diff --git a/rust/release_crates/protobuf_codegen/src/lib.rs b/rust/release_crates/protobuf_codegen/src/lib.rs index a8f09dcf1c..1a19c1b84c 100644 --- a/rust/release_crates/protobuf_codegen/src/lib.rs +++ b/rust/release_crates/protobuf_codegen/src/lib.rs @@ -54,7 +54,7 @@ fn protoc_version(protoc_output: &str) -> String { // "X.Y.Z" with an optional suffix starting with a dash. We want to drop the // major version ("X.") and only keep the suffix if it starts with "-rc". fn expected_protoc_version(cargo_version: &str) -> String { - let mut s = cargo_version.to_string(); + let mut s = cargo_version.replace("-rc.", "-rc"); let is_release_candidate = s.find("-rc") != None; if !is_release_candidate { if let Some(i) = s.find('-') { @@ -258,6 +258,6 @@ mod tests { assert_that!(expected_protoc_version("4.30.0-alpha"), eq("30.0")); assert_that!(expected_protoc_version("4.30.0-beta"), eq("30.0")); assert_that!(expected_protoc_version("4.30.0-pre"), eq("30.0")); - assert_that!(expected_protoc_version("4.30.0-rc1"), eq("30.0-rc1")); + assert_that!(expected_protoc_version("4.30.0-rc.1"), eq("30.0-rc1")); } } diff --git a/src/google/protobuf/compiler/rust/generator.cc b/src/google/protobuf/compiler/rust/generator.cc index 7e1e037cb7..0900bbf390 100644 --- a/src/google/protobuf/compiler/rust/generator.cc +++ b/src/google/protobuf/compiler/rust/generator.cc @@ -20,6 +20,7 @@ #include "absl/status/statusor.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" +#include "absl/strings/str_replace.h" #include "absl/strings/string_view.h" #include "absl/strings/strip.h" #include "absl/types/span.h" @@ -177,8 +178,8 @@ bool RustGenerator::Generate(const FileDescriptor* file, {"Option", "::std::option::Option"}, }); - auto expected_runtime_version = - std::string(absl::StripSuffix(PROTOBUF_RUST_VERSION_STRING, "-dev")); + std::string expected_runtime_version = absl::StrReplaceAll( + PROTOBUF_RUST_VERSION_STRING, {{"-dev", ""}, {"-rc", "-rc."}}); if (!absl::StrContains(expected_runtime_version, "-rc")) { expected_runtime_version.append("-release"); }