diff --git a/rust/release_crates/protobuf/BUILD b/rust/release_crates/protobuf/BUILD index 9ebf01bfc2..5e5dd4bda0 100644 --- a/rust/release_crates/protobuf/BUILD +++ b/rust/release_crates/protobuf/BUILD @@ -1,6 +1,6 @@ load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix") load("@rules_pkg//pkg:tar.bzl", "pkg_tar") -load("//:protobuf_version.bzl", "PROTOBUF_RUST_VERSION") +load("//rust/release_crates:substitute_rust_release_version.bzl", "substitute_rust_release_version") pkg_tar( name = "protobuf_crate", @@ -19,19 +19,22 @@ pkg_files( strip_prefix = strip_prefix.from_root("rust/release_crates/protobuf"), ) -genrule( - name = "gen_cargo_toml", - srcs = ["Cargo-template.toml"], - outs = ["Cargo.toml"], - cmd = "cat $(SRCS) | sed -e 's/{{VERSION}}/{0}-beta1/g' > $(OUTS)".format(PROTOBUF_RUST_VERSION), +substitute_rust_release_version( + src = "Cargo-template.toml", + out = "Cargo.toml", +) + +substitute_rust_release_version( + src = "README-template.md", + out = "README.md", ) filegroup( name = "srcs", srcs = [ + "Cargo.toml", "README.md", "build.rs", - ":gen_cargo_toml", ], visibility = ["//rust:__subpackages__"], ) diff --git a/rust/release_crates/protobuf/README.md b/rust/release_crates/protobuf/README-template.md similarity index 98% rename from rust/release_crates/protobuf/README.md rename to rust/release_crates/protobuf/README-template.md index f4a7987bb0..d09c6791fd 100644 --- a/rust/release_crates/protobuf/README.md +++ b/rust/release_crates/protobuf/README-template.md @@ -42,7 +42,7 @@ You can build a compatible protoc from source as follows: ``` git clone https://github.com/protocolbuffers/protobuf.git cd protobuf -git checkout $TAG +git checkout rust-prerelease-{VERSION} cmake . -Dprotobuf_FORCE_FETCH_DEPENDENCIES=ON cmake --build . --parallel 12" ``` diff --git a/rust/release_crates/protobuf_codegen/BUILD b/rust/release_crates/protobuf_codegen/BUILD index 00bcd6b603..42c875b432 100644 --- a/rust/release_crates/protobuf_codegen/BUILD +++ b/rust/release_crates/protobuf_codegen/BUILD @@ -1,6 +1,6 @@ load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix") load("@rules_pkg//pkg:tar.bzl", "pkg_tar") -load("//:protobuf_version.bzl", "PROTOBUF_RUST_VERSION") +load("//rust/release_crates:substitute_rust_release_version.bzl", "substitute_rust_release_version") pkg_tar( name = "protobuf_codegen_crate", @@ -18,18 +18,21 @@ pkg_files( strip_prefix = strip_prefix.from_root("rust/release_crates/protobuf_codegen"), ) -genrule( - name = "gen_cargo_toml", - srcs = ["Cargo-template.toml"], - outs = ["Cargo.toml"], - cmd = "cat $(SRCS) | sed -e 's/{{VERSION}}/{0}-beta1/g' > $(OUTS)".format(PROTOBUF_RUST_VERSION), +substitute_rust_release_version( + src = "Cargo-template.toml", + out = "Cargo.toml", +) + +substitute_rust_release_version( + src = "README-template.md", + out = "README.md", ) filegroup( name = "srcs", srcs = [ + "Cargo.toml", "README.md", - ":gen_cargo_toml", ] + glob(["src/**/*"]), visibility = ["//rust:__subpackages__"], ) diff --git a/rust/release_crates/protobuf_codegen/README.md b/rust/release_crates/protobuf_codegen/README-template.md similarity index 95% rename from rust/release_crates/protobuf_codegen/README.md rename to rust/release_crates/protobuf_codegen/README-template.md index 7fe01c5950..5caea061b0 100644 --- a/rust/release_crates/protobuf_codegen/README.md +++ b/rust/release_crates/protobuf_codegen/README-template.md @@ -21,7 +21,7 @@ You can build a compatible protoc from source as follows: ``` git clone https://github.com/protocolbuffers/protobuf.git cd protobuf -git checkout $TAG +git checkout rust-prerelease-{VERSION} cmake . -Dprotobuf_FORCE_FETCH_DEPENDENCIES=ON cmake --build . --parallel 12" ``` diff --git a/rust/release_crates/protobuf_example/.gitignore b/rust/release_crates/protobuf_example/.gitignore deleted file mode 100644 index 7f0a975eb7..0000000000 --- a/rust/release_crates/protobuf_example/.gitignore +++ /dev/null @@ -1 +0,0 @@ -src/protobuf_generated/ diff --git a/rust/release_crates/protobuf_example/BUILD b/rust/release_crates/protobuf_example/BUILD index b820fc866f..a9a1b39543 100644 --- a/rust/release_crates/protobuf_example/BUILD +++ b/rust/release_crates/protobuf_example/BUILD @@ -1,6 +1,6 @@ load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix") load("@rules_pkg//pkg:tar.bzl", "pkg_tar") -load("//:protobuf_version.bzl", "PROTOBUF_RUST_VERSION") +load("//rust/release_crates:substitute_rust_release_version.bzl", "substitute_rust_release_version") pkg_tar( name = "protobuf_example_crate", @@ -17,15 +17,27 @@ pkg_files( strip_prefix = strip_prefix.from_root("rust/release_crates/protobuf_example"), ) -genrule( - name = "gen_cargo_toml", - srcs = ["Cargo-template.toml"], - outs = ["Cargo.toml"], - cmd = "cat $(SRCS) | sed -e 's/{{VERSION}}/{0}-beta1/g' > $(OUTS)".format(PROTOBUF_RUST_VERSION), +substitute_rust_release_version( + src = "Cargo-template.toml", + out = "Cargo.toml", +) + +substitute_rust_release_version( + src = "README-template.md", + out = "README.md", ) filegroup( name = "srcs", - srcs = [":gen_cargo_toml"] + glob(["**/*"]), + srcs = [ + "Cargo.toml", + "README.md", + "build.rs", + ] + glob( + [ + "proto/**/*", + "src/**/*", + ], + ), visibility = ["//rust:__subpackages__"], ) diff --git a/rust/release_crates/protobuf_example/README.md b/rust/release_crates/protobuf_example/README-template.md similarity index 93% rename from rust/release_crates/protobuf_example/README.md rename to rust/release_crates/protobuf_example/README-template.md index 401804da14..7783f68256 100644 --- a/rust/release_crates/protobuf_example/README.md +++ b/rust/release_crates/protobuf_example/README-template.md @@ -15,7 +15,7 @@ You can build a compatible protoc from source as follows: ``` git clone https://github.com/protocolbuffers/protobuf.git cd protobuf -git checkout $TAG +git checkout rust-prerelease-{VERSION} cmake . -Dprotobuf_FORCE_FETCH_DEPENDENCIES=ON cmake --build . --parallel 12" ``` diff --git a/rust/release_crates/substitute_rust_release_version.bzl b/rust/release_crates/substitute_rust_release_version.bzl new file mode 100644 index 0000000000..eed862269f --- /dev/null +++ b/rust/release_crates/substitute_rust_release_version.bzl @@ -0,0 +1,15 @@ +"""A rule to textually replace {{VERSION}} with the Rust release version in files.""" + +load("//:protobuf_version.bzl", "PROTOBUF_RUST_VERSION") + +# Temporarily append a prerelease suffix to our versions until we consider the release stable. +PROTOBUF_RUST_VERSION_WITH_BETA_SUFFIX = PROTOBUF_RUST_VERSION + "-beta2" + +def substitute_rust_release_version(src, out, name = None): + version = PROTOBUF_RUST_VERSION_WITH_BETA_SUFFIX + native.genrule( + name = name or ("gen_%s" % out), + srcs = [src], + outs = [out], + cmd = "cat $(SRCS) | sed -e 's/{{VERSION}}/{0}/g' > $(OUTS)".format(version), + ) diff --git a/src/google/protobuf/compiler/rust/generator.cc b/src/google/protobuf/compiler/rust/generator.cc index a2050b0696..7f8a137fda 100644 --- a/src/google/protobuf/compiler/rust/generator.cc +++ b/src/google/protobuf/compiler/rust/generator.cc @@ -177,7 +177,7 @@ bool RustGenerator::Generate(const FileDescriptor* file, }); std::string expected_runtime_version = absl::StrCat( - absl::StripSuffix(PROTOBUF_RUST_VERSION_STRING, "-dev"), "-beta1"); + absl::StripSuffix(PROTOBUF_RUST_VERSION_STRING, "-dev"), "-beta2"); ctx.Emit({{"expected_runtime_version", expected_runtime_version}}, R"rs(