Automatically insert the version number in the README.md tag.

Make a starlark macro for textually substituting the rust release version number.

PiperOrigin-RevId: 708361023
pull/19742/head
Protobuf Team Bot 2 months ago committed by Copybara-Service
parent 05af18d24b
commit 03e09ad032
  1. 17
      rust/release_crates/protobuf/BUILD
  2. 2
      rust/release_crates/protobuf/README-template.md
  3. 17
      rust/release_crates/protobuf_codegen/BUILD
  4. 2
      rust/release_crates/protobuf_codegen/README-template.md
  5. 1
      rust/release_crates/protobuf_example/.gitignore
  6. 26
      rust/release_crates/protobuf_example/BUILD
  7. 2
      rust/release_crates/protobuf_example/README-template.md
  8. 15
      rust/release_crates/substitute_rust_release_version.bzl
  9. 2
      src/google/protobuf/compiler/rust/generator.cc

@ -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__"],
)

@ -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"
```

@ -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__"],
)

@ -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"
```

@ -1 +0,0 @@
src/protobuf_generated/

@ -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__"],
)

@ -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"
```

@ -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),
)

@ -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(

Loading…
Cancel
Save