diff --git a/docs/crate_universe.md b/docs/crate_universe.md index 62be0919ad..5d6f8bb76d 100644 --- a/docs/crate_universe.md +++ b/docs/crate_universe.md @@ -462,7 +462,7 @@ bazel run //3rdparty:crates_vendor -- --repin ``` Under the hood, `--repin` will trigger a [cargo update](https://doc.rust-lang.org/cargo/commands/cargo-update.html) -call against the generated workspace. The following table describes how to controll particular values passed to the +call against the generated workspace. The following table describes how to control particular values passed to the `cargo update` command. | Value | Cargo command | diff --git a/docs/symbols.bzl b/docs/symbols.bzl index 9a7e76176f..d1a8d65662 100644 --- a/docs/symbols.bzl +++ b/docs/symbols.bzl @@ -28,9 +28,11 @@ load( _crates_vendor = "crates_vendor", ) load( - "@rules_rust//proto:proto.bzl", + "@rules_rust//proto:defs.bzl", _rust_grpc_library = "rust_grpc_library", + _rust_prost_library = "rust_prost_library", _rust_proto_library = "rust_proto_library", + _rust_tonic_library = "rust_tonic_library", ) load( "@rules_rust//proto:repositories.bzl", @@ -124,6 +126,8 @@ rust_doc_test = _rust_doc_test rust_proto_library = _rust_proto_library rust_grpc_library = _rust_grpc_library +rust_prost_library = _rust_prost_library +rust_tonic_library = _rust_tonic_library rust_bindgen = _rust_bindgen rust_bindgen_dependencies = _rust_bindgen_dependencies diff --git a/proto/BUILD.bazel b/proto/BUILD.bazel index 298c61511b..293e4d88df 100644 --- a/proto/BUILD.bazel +++ b/proto/BUILD.bazel @@ -48,5 +48,6 @@ bzl_library( srcs = glob(["**/*.bzl"]), deps = [ "//proto/3rdparty:bzl_lib", + "//proto/prost:bzl_lib", ], ) diff --git a/proto/prost/private/prost.bzl b/proto/prost/private/prost.bzl index 2642e3cdf0..4a128a27e7 100644 --- a/proto/prost/private/prost.bzl +++ b/proto/prost/private/prost.bzl @@ -1,6 +1,6 @@ """Rules for building protos in Rust with Prost and Tonic.""" -load("@rules_proto//proto:defs.bzl", "ProtoInfo") +load("@rules_proto//proto:defs.bzl", "ProtoInfo", "proto_common") load("//rust:defs.bzl", "rust_common") # buildifier: disable=bzl-visibility @@ -10,13 +10,6 @@ load("//rust/private:providers.bzl", "DepVariantInfo") load("//rust/private:rustc.bzl", "rustc_compile_action") load(":providers.bzl", "ProstProtoInfo", "TonicProtoInfo") -# This follows the exact same convention as the new upstream protobuf rules. -# https://github.com/protocolbuffers/protobuf/blob/v23.3/rust/aspects.bzl#L15 -# The interface here hasn't changed in quite a while and since there's now -# additional reliance on it there it seems unlikely that it will break and if -# it does there should be a clear migration example for Starlark code there. -proto_common = proto_common_do_not_use - PROST_EXTENSION = ".rs" TONIC_EXTENSION = ".tonic.rs" diff --git a/proto/prost/private/protoc_wrapper.rs b/proto/prost/private/protoc_wrapper.rs index 280e91078c..b75de79838 100644 --- a/proto/prost/private/protoc_wrapper.rs +++ b/proto/prost/private/protoc_wrapper.rs @@ -25,17 +25,15 @@ fn find_generated_rust_files(out_dir: &Path) -> ProtocResult> for f in find_generated_rust_files(&path)? { all_rs_files.insert(f); } - } else { - if let Some(ext) = path.extension() { - if ext == "rs" { - all_rs_files.insert(path); - } - } else if let Some(name) = path.file_name() { - if name == "_" { - let rs_name = path.parent().expect("Failed to get parent").join("_.rs"); - fs::rename(&path, &rs_name).map_err(from_error)?; - all_rs_files.insert(rs_name); - } + } else if let Some(ext) = path.extension() { + if ext == "rs" { + all_rs_files.insert(path); + } + } else if let Some(name) = path.file_name() { + if name == "_" { + let rs_name = path.parent().expect("Failed to get parent").join("_.rs"); + fs::rename(&path, &rs_name).map_err(from_error)?; + all_rs_files.insert(rs_name); } } } @@ -224,11 +222,11 @@ fn compute_proto_package_info( crate_name: &str, protoc: &Path, includes: &BTreeSet, - proto_paths: &Vec, + proto_paths: &[String], ) -> ProtocResult> { let mut extern_paths = BTreeSet::new(); for proto_file in proto_files.iter() { - let output = process::Command::new(&protoc) + let output = process::Command::new(protoc) .args(includes.iter().map(|include| format!("-I{}", include))) .arg("--print_free_field_numbers") .args( @@ -259,16 +257,16 @@ fn compute_proto_package_info( } let (absolute, _) = text - .split_once(" ") + .split_once(' ') .ok_or_else(|| format!("Failed to split line: {}", text))?; let mut package = ""; let mut symbol_name = absolute; - if let Some((package_, symbol_name_)) = absolute.rsplit_once(".") { + if let Some((package_, symbol_name_)) = absolute.rsplit_once('.') { package = package_; symbol_name = symbol_name_; } - let symbol = format!("{}::{}", package.replace(".", "::"), symbol_name); + let symbol = format!("{}::{}", package.replace('.', "::"), symbol_name); let extern_path = format!(".{}={}::{}", absolute, crate_name, symbol.trim_matches(':')); if !extern_paths.insert(extern_path.clone()) { panic!("Duplicate extern: {}", extern_path); @@ -335,23 +333,27 @@ impl Args { // for the process runner and arguments for protoc and potentially spawn // additional arguments needed by prost. for arg in env::args().skip(1) { - if !arg.starts_with("-") { + if !arg.starts_with('-') { proto_files.insert(PathBuf::from(arg)); continue; } if arg.starts_with("-I") { - includes.insert(arg[2..].to_string()); + includes.insert( + arg.strip_prefix("-I") + .expect("Failed to strip -I") + .to_string(), + ); continue; } - if !arg.contains("=") { + if !arg.contains('=') { extra_args.push(arg); continue; } let part = arg - .split_once("=") + .split_once('=') .ok_or_else(|| format!("Failed to parse argument `{arg}`",))?; match part { ("--protoc", value) => { @@ -369,7 +371,7 @@ impl Args { } ("--package_info_output", value) => { let (key, value) = value - .split_once("=") + .split_once('=') .map(|(a, b)| (a.to_string(), PathBuf::from(b))) .expect("Failed to parse package info output"); crate_name = Some(key); @@ -539,7 +541,7 @@ fn main() -> ProtocResult<()> { // Write outputs fs::write(&out_librs, generate_lib_rs(&rust_files, is_tonic)?).map_err(from_error)?; fs::write( - &package_info_file, + package_info_file, package_info.into_iter().collect::>().join("\n"), ) .map_err(from_error)?; diff --git a/proto/repositories.bzl b/proto/repositories.bzl index 42137ea166..92e38a3ed6 100644 --- a/proto/repositories.bzl +++ b/proto/repositories.bzl @@ -23,11 +23,11 @@ def rust_proto_dependencies(): maybe( http_archive, name = "rules_proto", - sha256 = "66bfdf8782796239d3875d37e7de19b1d94301e8972b3cbd2446b332429b4df1", - strip_prefix = "rules_proto-4.0.0", + sha256 = "dc3fb206a2cb3441b485eb1e423165b231235a1ea9b031b4433cf7bc1fa460dd", + strip_prefix = "rules_proto-5.3.0-21.7", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/refs/tags/4.0.0.tar.gz", - "https://github.com/bazelbuild/rules_proto/archive/refs/tags/4.0.0.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/refs/tags/5.3.0-21.7.tar.gz", + "https://github.com/bazelbuild/rules_proto/archive/refs/tags/5.3.0-21.7.tar.gz", ], )