From 560ba29992c7352bd26161668472bac6bce370eb Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Tue, 10 Nov 2020 06:14:33 +0000 Subject: [PATCH] Use cargo-raze's gen_buildrs for trusted crates. Signed-off-by: Piotr Sikora --- .github/workflows/rust.yml | 2 +- Cargo.toml | 19 ++---- .../cargo/remote/BUILD.getrandom-0.2.0.bazel | 67 ++++++++++++++++++- bazel/cargo/remote/BUILD.libc-0.2.80.bazel | 39 ++++++++--- bazel/cargo/remote/BUILD.log-0.4.11.bazel | 31 ++++++++- 5 files changed, 130 insertions(+), 28 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 3df51920..dcaf7963 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -75,7 +75,7 @@ jobs: - name: Format (cargo raze) run: | - cargo install cargo-raze --git https://github.com/google/cargo-raze --rev cb9f85d22b1c81cceb9acaf1fa4336c5fc4e6bff + cargo install cargo-raze --version 0.7.0 cp -p bazel/cargo/Cargo.lock . rm -rf bazel/cargo/ cargo raze --output=bazel/cargo diff --git a/Cargo.toml b/Cargo.toml index 0e06abc7..2e5b8d7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,19 +32,14 @@ panic = "abort" workspace_path = "//bazel/cargo" genmode = "Remote" -[package.metadata.raze.crates.libc.'0.2.80'] -additional_flags = [ - "--cfg=libc_priv_mod_use", - "--cfg=libc_union", - "--cfg=libc_const_size_of", - "--cfg=libc_align", - "--cfg=libc_core_cvoid", - "--cfg=libc_packedN", - "--cfg=libc_cfg_target_vendor", -] +[package.metadata.raze.crates.getrandom.'=0.2.0'] +gen_buildrs = true -[package.metadata.raze.crates.log.'0.4.11'] -additional_flags = ["--cfg=atomic_cas"] +[package.metadata.raze.crates.libc.'=0.2.80'] +gen_buildrs = true + +[package.metadata.raze.crates.log.'=0.4.11'] +gen_buildrs = true [[example]] name = "hello_world" diff --git a/bazel/cargo/remote/BUILD.getrandom-0.2.0.bazel b/bazel/cargo/remote/BUILD.getrandom-0.2.0.bazel index d91deb02..5e431e5c 100644 --- a/bazel/cargo/remote/BUILD.getrandom-0.2.0.bazel +++ b/bazel/cargo/remote/BUILD.getrandom-0.2.0.bazel @@ -28,11 +28,71 @@ licenses([ "notice", # MIT from expression "MIT OR Apache-2.0" ]) -# Generated Targets +# Generated Targets# buildifier: disable=load-on-top +load( + "@io_bazel_rules_rust//cargo:cargo_build_script.bzl", + "cargo_build_script", +) -# Unsupported target "mod" with type "bench" omitted +cargo_build_script( + name = "getrandom_build_script", + srcs = glob(["**/*.rs"]), + build_script_env = { + }, + crate_features = [ + ], + crate_root = "build.rs", + data = glob(["**"]), + edition = "2018", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-raze", + "manual", + ], + version = "0.2.0", + visibility = ["//visibility:private"], + deps = [ + ] + selects.with_or({ + # cfg(all(target_arch = "wasm32", target_os = "unknown", not(cargo_web))) + ( + "@io_bazel_rules_rust//rust/platform:wasm32-unknown-unknown", + ): [ + ], + "//conditions:default": [], + }) + selects.with_or({ + # cfg(target_os = "wasi") + ( + "@io_bazel_rules_rust//rust/platform:wasm32-wasi", + ): [ + ], + "//conditions:default": [], + }) + selects.with_or({ + # cfg(unix) + ( + "@io_bazel_rules_rust//rust/platform:aarch64-apple-ios", + "@io_bazel_rules_rust//rust/platform:aarch64-linux-android", + "@io_bazel_rules_rust//rust/platform:aarch64-unknown-linux-gnu", + "@io_bazel_rules_rust//rust/platform:arm-unknown-linux-gnueabi", + "@io_bazel_rules_rust//rust/platform:i686-apple-darwin", + "@io_bazel_rules_rust//rust/platform:i686-linux-android", + "@io_bazel_rules_rust//rust/platform:i686-unknown-freebsd", + "@io_bazel_rules_rust//rust/platform:i686-unknown-linux-gnu", + "@io_bazel_rules_rust//rust/platform:powerpc-unknown-linux-gnu", + "@io_bazel_rules_rust//rust/platform:s390x-unknown-linux-gnu", + "@io_bazel_rules_rust//rust/platform:x86_64-apple-darwin", + "@io_bazel_rules_rust//rust/platform:x86_64-apple-ios", + "@io_bazel_rules_rust//rust/platform:x86_64-linux-android", + "@io_bazel_rules_rust//rust/platform:x86_64-unknown-freebsd", + "@io_bazel_rules_rust//rust/platform:x86_64-unknown-linux-gnu", + ): [ + ], + "//conditions:default": [], + }), +) -# Unsupported target "build-script-build" with type "custom-build" omitted +# Unsupported target "mod" with type "bench" omitted rust_library( name = "getrandom", @@ -54,6 +114,7 @@ rust_library( version = "0.2.0", # buildifier: leave-alone deps = [ + ":getrandom_build_script", "@raze__cfg_if__0_1_10//:cfg_if", ] + selects.with_or({ # cfg(all(target_arch = "wasm32", target_os = "unknown", not(cargo_web))) diff --git a/bazel/cargo/remote/BUILD.libc-0.2.80.bazel b/bazel/cargo/remote/BUILD.libc-0.2.80.bazel index 34e15553..81bb143b 100644 --- a/bazel/cargo/remote/BUILD.libc-0.2.80.bazel +++ b/bazel/cargo/remote/BUILD.libc-0.2.80.bazel @@ -28,9 +28,36 @@ licenses([ "notice", # MIT from expression "MIT OR Apache-2.0" ]) -# Generated Targets +# Generated Targets# buildifier: disable=load-on-top +load( + "@io_bazel_rules_rust//cargo:cargo_build_script.bzl", + "cargo_build_script", +) -# Unsupported target "build-script-build" with type "custom-build" omitted +cargo_build_script( + name = "libc_build_script", + srcs = glob(["**/*.rs"]), + build_script_env = { + }, + crate_features = [ + "default", + "std", + ], + crate_root = "build.rs", + data = glob(["**"]), + edition = "2015", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-raze", + "manual", + ], + version = "0.2.80", + visibility = ["//visibility:private"], + deps = [ + ], +) rust_library( name = "libc", @@ -44,13 +71,6 @@ rust_library( edition = "2015", rustc_flags = [ "--cap-lints=allow", - "--cfg=libc_priv_mod_use", - "--cfg=libc_union", - "--cfg=libc_const_size_of", - "--cfg=libc_align", - "--cfg=libc_core_cvoid", - "--cfg=libc_packedN", - "--cfg=libc_cfg_target_vendor", ], tags = [ "cargo-raze", @@ -59,6 +79,7 @@ rust_library( version = "0.2.80", # buildifier: leave-alone deps = [ + ":libc_build_script", ], ) diff --git a/bazel/cargo/remote/BUILD.log-0.4.11.bazel b/bazel/cargo/remote/BUILD.log-0.4.11.bazel index 022c0e5c..3910f0b2 100644 --- a/bazel/cargo/remote/BUILD.log-0.4.11.bazel +++ b/bazel/cargo/remote/BUILD.log-0.4.11.bazel @@ -28,9 +28,34 @@ licenses([ "notice", # MIT from expression "MIT OR Apache-2.0" ]) -# Generated Targets +# Generated Targets# buildifier: disable=load-on-top +load( + "@io_bazel_rules_rust//cargo:cargo_build_script.bzl", + "cargo_build_script", +) -# Unsupported target "build-script-build" with type "custom-build" omitted +cargo_build_script( + name = "log_build_script", + srcs = glob(["**/*.rs"]), + build_script_env = { + }, + crate_features = [ + ], + crate_root = "build.rs", + data = glob(["**"]), + edition = "2015", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-raze", + "manual", + ], + version = "0.4.11", + visibility = ["//visibility:private"], + deps = [ + ], +) rust_library( name = "log", @@ -42,7 +67,6 @@ rust_library( edition = "2015", rustc_flags = [ "--cap-lints=allow", - "--cfg=atomic_cas", ], tags = [ "cargo-raze", @@ -51,6 +75,7 @@ rust_library( version = "0.4.11", # buildifier: leave-alone deps = [ + ":log_build_script", "@raze__cfg_if__0_1_10//:cfg_if", ], )