From 8ce4952624abfde9bcd64e53aad9e4397e515ac3 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 3 Dec 2024 12:56:20 -0800 Subject: [PATCH] Create /release_crates/ directory that contains one directory for each of our 3 crates that we package up. PiperOrigin-RevId: 702439996 --- .github/workflows/test_rust.yml | 2 +- rust/BUILD | 115 +----------------- rust/cargo/BUILD | 17 --- rust/dist.bzl | 4 +- rust/protobuf_codegen/BUILD | 16 --- rust/protobuf_codegen/example/BUILD | 5 - rust/release_crates/BUILD | 14 +++ rust/{ => release_crates}/cargo_test.sh | 18 ++- rust/release_crates/protobuf/BUILD | 36 ++++++ .../protobuf}/Cargo-template.toml | 0 .../protobuf}/build.rs | 0 rust/release_crates/protobuf_codegen/BUILD | 35 ++++++ .../protobuf_codegen/Cargo-template.toml | 0 .../protobuf_codegen/src/lib.rs | 0 rust/release_crates/protobuf_example/BUILD | 23 ++++ .../protobuf_example}/Cargo.toml | 0 .../protobuf_example}/build.rs | 0 .../protobuf_example}/proto/bar/bar.proto | 0 .../protobuf_example}/proto/foo.proto | 0 .../protobuf_example}/src/main.rs | 4 +- 20 files changed, 125 insertions(+), 164 deletions(-) delete mode 100644 rust/cargo/BUILD delete mode 100644 rust/protobuf_codegen/BUILD delete mode 100644 rust/protobuf_codegen/example/BUILD create mode 100644 rust/release_crates/BUILD rename rust/{ => release_crates}/cargo_test.sh (79%) create mode 100644 rust/release_crates/protobuf/BUILD rename rust/{cargo => release_crates/protobuf}/Cargo-template.toml (100%) rename rust/{cargo => release_crates/protobuf}/build.rs (100%) create mode 100644 rust/release_crates/protobuf_codegen/BUILD rename rust/{ => release_crates}/protobuf_codegen/Cargo-template.toml (100%) rename rust/{ => release_crates}/protobuf_codegen/src/lib.rs (100%) create mode 100644 rust/release_crates/protobuf_example/BUILD rename rust/{protobuf_codegen/example => release_crates/protobuf_example}/Cargo.toml (100%) rename rust/{protobuf_codegen/example => release_crates/protobuf_example}/build.rs (100%) rename rust/{protobuf_codegen/example => release_crates/protobuf_example}/proto/bar/bar.proto (100%) rename rust/{protobuf_codegen/example => release_crates/protobuf_example}/proto/foo.proto (100%) rename rust/{protobuf_codegen/example => release_crates/protobuf_example}/src/main.rs (91%) diff --git a/.github/workflows/test_rust.yml b/.github/workflows/test_rust.yml index f83438440a..2f0bb26321 100644 --- a/.github/workflows/test_rust.yml +++ b/.github/workflows/test_rust.yml @@ -33,7 +33,7 @@ jobs: - config: { name: Cargo } image: "us-docker.pkg.dev/protobuf-build/containers/release/linux/rust:6.3.0-1.74.0-8858126dd9480abf91e6ce8d6e41a5cd3c03882c" bazel_cmd: "run" - targets: "//rust:cargo_test" + targets: "//rust/release_crates:cargo_test" name: Linux ${{ matrix.config.name }} runs-on: ubuntu-22-4core steps: diff --git a/rust/BUILD b/rust/BUILD index c475bac6d4..9ec6bc197f 100644 --- a/rust/BUILD +++ b/rust/BUILD @@ -2,7 +2,6 @@ load("@bazel_skylib//rules:common_settings.bzl", "string_flag") load("@rules_pkg//pkg:mappings.bzl", "pkg_filegroup", "pkg_files", "strip_prefix") -load("@rules_pkg//pkg:tar.bzl", "pkg_tar") load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") load("//bazel/toolchains:proto_lang_toolchain.bzl", "proto_lang_toolchain") load("//rust:dist.bzl", "pkg_cross_compiled_binaries") @@ -261,20 +260,10 @@ config_setting( }, ) -# Note: strip_prefix.from_pkg() should work for this below, but has surprising behavior in bazel -# with filegroups and so we only use strip_prefix.from_root() and this constant instead. -SRC_ROOT = "rust" - pkg_files( name = "rust_protobuf_src", srcs = ALL_RUST_SRCS, - strip_prefix = strip_prefix.from_root(SRC_ROOT), -) - -pkg_files( - name = "crate_root_files", - srcs = ["//rust/cargo:srcs"], - strip_prefix = strip_prefix.from_root(SRC_ROOT + "/cargo"), + strip_prefix = strip_prefix.from_root("rust"), ) pkg_filegroup( @@ -284,6 +273,7 @@ pkg_filegroup( "//rust/upb:rust_protobuf_upb_src", ], prefix = "src", + visibility = ["//rust/release_crates:__subpackages__"], ) pkg_files( @@ -299,79 +289,7 @@ pkg_filegroup( "//upb/cmake:upb_cmake_dist", ], prefix = "libupb", -) - -pkg_tar( - name = "protobuf_crate_dist", - srcs = [ - ":crate_root_files", - ":rust_protobuf_libupb_src", - ":rust_protobuf_src_dir", - "//:LICENSE", - ], -) - -pkg_files( - name = "protobuf_codegen_files", - srcs = ["//rust/protobuf_codegen:srcs"], - strip_prefix = strip_prefix.from_root(SRC_ROOT + "/protobuf_codegen"), -) - -pkg_tar( - name = "codegen_crate_dist", - srcs = [ - ":protobuf_codegen_files", - ":vendored_protocs_dist", - "//:LICENSE", - ], - tags = ["manual"], -) - -pkg_tar( - name = "codegen_crate_test", - srcs = [ - ":protobuf_codegen_files", - ":vendored_protocs_test", - "//:LICENSE", - ], - tags = ["manual"], -) - -pkg_files( - name = "codegen_example_files", - srcs = ["//rust/protobuf_codegen/example:srcs"], - strip_prefix = strip_prefix.from_root(SRC_ROOT + "/protobuf_codegen/example"), -) - -pkg_tar( - name = "codegen_example_test", - srcs = [ - ":codegen_example_files", - "//:LICENSE", - ], -) - -# Bundle all protoc binaries for all platforms. Requires the toolchains to be installed. -pkg_cross_compiled_binaries( - name = "vendored_protocs_dist", - cpus = [ - # TODO: Re-enable these platforms once the toolchains are available. - # "osx-x86_64", - # "osx-aarch_64", - "linux-aarch_64", - "linux-ppcle_64", - # "linux-s390_64", - "linux-x86_32", - "linux-x86_64", - "win32", - "win64", - ], - prefix = "bin", - tags = ["manual"], - targets = [ - "//upb_generator/minitable:protoc-gen-upb_minitable", - "//:protoc", - ], + visibility = ["//rust/release_crates:__subpackages__"], ) # Bundle only the linux-x86_64 protoc for testing. @@ -386,30 +304,5 @@ pkg_cross_compiled_binaries( "//upb_generator/minitable:protoc-gen-upb_minitable", "//:protoc", ], -) - -# Run the cargo test with only a bundled linux-x86_64 protoc. -sh_binary( - name = "cargo_test", - srcs = ["cargo_test.sh"], - data = [ - ":codegen_crate_test", - ":codegen_example_test", - ":protobuf_crate_dist", - ], - tags = ["manual"], - deps = ["@bazel_tools//tools/bash/runfiles"], -) - -# Run the cargo test with all bundled protocs. -sh_binary( - name = "cargo_release_test", - srcs = ["cargo_test.sh"], - data = [ - ":codegen_crate_dist", - ":codegen_example_test", - ":protobuf_crate_dist", - ], - tags = ["manual"], - deps = ["@bazel_tools//tools/bash/runfiles"], + visibility = ["//rust/release_crates:__subpackages__"], ) diff --git a/rust/cargo/BUILD b/rust/cargo/BUILD deleted file mode 100644 index fc68d2fe11..0000000000 --- a/rust/cargo/BUILD +++ /dev/null @@ -1,17 +0,0 @@ -load("//:protobuf_version.bzl", "PROTOBUF_RUST_VERSION") - -genrule( - name = "gen_cargo_toml", - srcs = ["Cargo-template.toml"], - outs = ["Cargo.toml"], - cmd = "cat $(SRCS) | sed -e 's/{{VERSION}}/{0}-beta/g' > $(OUTS)".format(PROTOBUF_RUST_VERSION), -) - -filegroup( - name = "srcs", - srcs = [ - "build.rs", - ":gen_cargo_toml", - ], - visibility = ["//rust:__subpackages__"], -) diff --git a/rust/dist.bzl b/rust/dist.bzl index 5ffb2898bc..327e1af29b 100644 --- a/rust/dist.bzl +++ b/rust/dist.bzl @@ -47,7 +47,7 @@ _cross_compiled_binary = rule( }, ) -def pkg_cross_compiled_binaries(name, cpus, targets, prefix, tags): +def pkg_cross_compiled_binaries(name, cpus, targets, prefix, tags, visibility = None): """Creates a pkg_filegroup that contains the cross compiled binaries for each cpu. This rule is used to create a pkg_filegroup that contains the cross compiled binaries for each @@ -60,6 +60,7 @@ def pkg_cross_compiled_binaries(name, cpus, targets, prefix, tags): targets: The targets to cross compile. prefix: The prefix to add to the pkg_filegroup. tags: The tags to add to the pkg_filegroup. + visibility: The visibility of the pkg_filegroup. """ filegroups = [] @@ -94,5 +95,6 @@ def pkg_cross_compiled_binaries(name, cpus, targets, prefix, tags): srcs = filegroups, prefix = prefix, tags = tags, + visibility = visibility, ) return diff --git a/rust/protobuf_codegen/BUILD b/rust/protobuf_codegen/BUILD deleted file mode 100644 index a4b51870b9..0000000000 --- a/rust/protobuf_codegen/BUILD +++ /dev/null @@ -1,16 +0,0 @@ -load("//:protobuf_version.bzl", "PROTOBUF_RUST_VERSION") - -genrule( - name = "gen_cargo_toml", - srcs = ["Cargo-template.toml"], - outs = ["Cargo.toml"], - cmd = "cat $(SRCS) | sed -e 's/{{VERSION}}/{0}-beta/g' > $(OUTS)".format(PROTOBUF_RUST_VERSION), -) - -filegroup( - name = "srcs", - srcs = [ - ":gen_cargo_toml", - ] + glob(["src/**/*"]), - visibility = ["//rust:__subpackages__"], -) diff --git a/rust/protobuf_codegen/example/BUILD b/rust/protobuf_codegen/example/BUILD deleted file mode 100644 index f478eae366..0000000000 --- a/rust/protobuf_codegen/example/BUILD +++ /dev/null @@ -1,5 +0,0 @@ -filegroup( - name = "srcs", - srcs = glob(["**/*"]), - visibility = ["//rust:__subpackages__"], -) diff --git a/rust/release_crates/BUILD b/rust/release_crates/BUILD new file mode 100644 index 0000000000..ba06d1f8d0 --- /dev/null +++ b/rust/release_crates/BUILD @@ -0,0 +1,14 @@ +# Protobuf Rust crate packaging for release. + +# Run the cargo test with only a bundled linux-x86_64 protoc. +sh_binary( + name = "cargo_test", + srcs = ["cargo_test.sh"], + data = [ + "//rust/release_crates/protobuf:protobuf_crate", + "//rust/release_crates/protobuf_codegen:protobuf_codegen_crate", + "//rust/release_crates/protobuf_example:protobuf_example_crate", + ], + tags = ["manual"], + deps = ["@bazel_tools//tools/bash/runfiles"], +) diff --git a/rust/cargo_test.sh b/rust/release_crates/cargo_test.sh similarity index 79% rename from rust/cargo_test.sh rename to rust/release_crates/cargo_test.sh index afc9adbe16..19bb4dd7b4 100755 --- a/rust/cargo_test.sh +++ b/rust/release_crates/cargo_test.sh @@ -35,29 +35,25 @@ mkdir $CARGO_HOME CRATE_ROOT=$TMP_DIR/protobuf mkdir $CRATE_ROOT -PROTOBUF_TAR=$(rlocation com_google_protobuf/rust/protobuf_crate_dist.tar) +PROTOBUF_TAR=$(rlocation com_google_protobuf/rust/release_crates/protobuf/protobuf_crate.tar) -echo "Expanding protobuf_crate tar" +echo "Expanding protobuf crate tar" tar -xvf $PROTOBUF_TAR -C $CRATE_ROOT CODEGEN_ROOT=$TMP_DIR/protobuf_codegen mkdir $CODEGEN_ROOT -CODEGEN_TAR=$(rlocation com_google_protobuf/rust/codegen_crate_dist.tar) +CODEGEN_TAR=$(rlocation com_google_protobuf/rust/release_crates/protobuf_codegen/protobuf_codegen_crate.tar) -if [[ ! -f $CODEGEN_TAR ]]; then - CODEGEN_TAR=$(rlocation com_google_protobuf/rust/codegen_crate_test.tar) -fi - -echo "Expanding codegen_crate tar" +echo "Expanding protbuf_codegen crate tar" tar -xvf $CODEGEN_TAR -C $CODEGEN_ROOT -EXAMPLE_ROOT=$TMP_DIR/codegen_example +EXAMPLE_ROOT=$TMP_DIR/protobuf_example mkdir $EXAMPLE_ROOT -EXAMPLE_TAR=$(rlocation com_google_protobuf/rust/codegen_example_test.tar) +EXAMPLE_TAR=$(rlocation com_google_protobuf/rust/release_crates/protobuf_example/protobuf_example_crate.tar) -echo "Expanding codegen_example tar" +echo "Expanding protobuf_example crate tar" tar -xvf $EXAMPLE_TAR -C $EXAMPLE_ROOT cd $CRATE_ROOT diff --git a/rust/release_crates/protobuf/BUILD b/rust/release_crates/protobuf/BUILD new file mode 100644 index 0000000000..27032c7779 --- /dev/null +++ b/rust/release_crates/protobuf/BUILD @@ -0,0 +1,36 @@ +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") + +pkg_tar( + name = "protobuf_crate", + srcs = [ + ":crate_root_files", + "//:LICENSE", + "//rust:rust_protobuf_libupb_src", + "//rust:rust_protobuf_src_dir", + ], + visibility = ["//rust:__subpackages__"], +) + +pkg_files( + name = "crate_root_files", + srcs = [":srcs"], + 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}-beta/g' > $(OUTS)".format(PROTOBUF_RUST_VERSION), +) + +filegroup( + name = "srcs", + srcs = [ + "build.rs", + ":gen_cargo_toml", + ], + visibility = ["//rust:__subpackages__"], +) diff --git a/rust/cargo/Cargo-template.toml b/rust/release_crates/protobuf/Cargo-template.toml similarity index 100% rename from rust/cargo/Cargo-template.toml rename to rust/release_crates/protobuf/Cargo-template.toml diff --git a/rust/cargo/build.rs b/rust/release_crates/protobuf/build.rs similarity index 100% rename from rust/cargo/build.rs rename to rust/release_crates/protobuf/build.rs diff --git a/rust/release_crates/protobuf_codegen/BUILD b/rust/release_crates/protobuf_codegen/BUILD new file mode 100644 index 0000000000..581ebf2b5d --- /dev/null +++ b/rust/release_crates/protobuf_codegen/BUILD @@ -0,0 +1,35 @@ +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") + +pkg_tar( + name = "protobuf_codegen_crate", + srcs = [ + ":protobuf_codegen_files", + "//:LICENSE", + "//rust:vendored_protocs_test", + ], + tags = ["manual"], + visibility = ["//rust:__subpackages__"], +) + +pkg_files( + name = "protobuf_codegen_files", + srcs = [":srcs"], + 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}-beta/g' > $(OUTS)".format(PROTOBUF_RUST_VERSION), +) + +filegroup( + name = "srcs", + srcs = [ + ":gen_cargo_toml", + ] + glob(["src/**/*"]), + visibility = ["//rust:__subpackages__"], +) diff --git a/rust/protobuf_codegen/Cargo-template.toml b/rust/release_crates/protobuf_codegen/Cargo-template.toml similarity index 100% rename from rust/protobuf_codegen/Cargo-template.toml rename to rust/release_crates/protobuf_codegen/Cargo-template.toml diff --git a/rust/protobuf_codegen/src/lib.rs b/rust/release_crates/protobuf_codegen/src/lib.rs similarity index 100% rename from rust/protobuf_codegen/src/lib.rs rename to rust/release_crates/protobuf_codegen/src/lib.rs diff --git a/rust/release_crates/protobuf_example/BUILD b/rust/release_crates/protobuf_example/BUILD new file mode 100644 index 0000000000..6e4cd58951 --- /dev/null +++ b/rust/release_crates/protobuf_example/BUILD @@ -0,0 +1,23 @@ +load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix") +load("@rules_pkg//pkg:tar.bzl", "pkg_tar") + +pkg_tar( + name = "protobuf_example_crate", + srcs = [ + ":protobuf_example_files", + "//:LICENSE", + ], + visibility = ["//rust:__subpackages__"], +) + +pkg_files( + name = "protobuf_example_files", + srcs = [":srcs"], + strip_prefix = strip_prefix.from_root("rust/release_crates/protobuf_example"), +) + +filegroup( + name = "srcs", + srcs = glob(["**/*"]), + visibility = ["//rust:__subpackages__"], +) diff --git a/rust/protobuf_codegen/example/Cargo.toml b/rust/release_crates/protobuf_example/Cargo.toml similarity index 100% rename from rust/protobuf_codegen/example/Cargo.toml rename to rust/release_crates/protobuf_example/Cargo.toml diff --git a/rust/protobuf_codegen/example/build.rs b/rust/release_crates/protobuf_example/build.rs similarity index 100% rename from rust/protobuf_codegen/example/build.rs rename to rust/release_crates/protobuf_example/build.rs diff --git a/rust/protobuf_codegen/example/proto/bar/bar.proto b/rust/release_crates/protobuf_example/proto/bar/bar.proto similarity index 100% rename from rust/protobuf_codegen/example/proto/bar/bar.proto rename to rust/release_crates/protobuf_example/proto/bar/bar.proto diff --git a/rust/protobuf_codegen/example/proto/foo.proto b/rust/release_crates/protobuf_example/proto/foo.proto similarity index 100% rename from rust/protobuf_codegen/example/proto/foo.proto rename to rust/release_crates/protobuf_example/proto/foo.proto diff --git a/rust/protobuf_codegen/example/src/main.rs b/rust/release_crates/protobuf_example/src/main.rs similarity index 91% rename from rust/protobuf_codegen/example/src/main.rs rename to rust/release_crates/protobuf_example/src/main.rs index 4b82be6abc..f48584b47f 100644 --- a/rust/protobuf_codegen/example/src/main.rs +++ b/rust/release_crates/protobuf_example/src/main.rs @@ -14,7 +14,7 @@ fn main() { mod tests { use super::*; - #[test] + #[test] // allow_core_test fn set_strings() { let foo = proto!(Foo { name: "foo", bar: __ { name: "bar" } }); @@ -22,7 +22,7 @@ mod tests { assert_eq!(foo.bar().name(), "bar"); } - #[test] + #[test] // allow_core_test fn set_ints() { let foo = proto!(Foo { int: 42, bar: __ { numbers: [1, 2, 3] } });