Skip to content

Commit a5b8a83

Browse files
committed
[feat] Add a build setting to announce crate scope
This build setting is not used internally, but provides a way for dependencies to be aware that they are being compiled for a rust crate. Examples of complex scenarios allowed by this change: 1. Build with a mac-x86_64 toolchain on mac-aarch64 platforms (rosetta) - everything (including host tools) is compiled for aarch64 while proc_macros must be compiled for x86_64. 2. A `cc_library` linked to both a `cc_binary` and a `rust_binary`, but needs slightly different build flags when used for rust crates.
1 parent 3902162 commit a5b8a83

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

rust/private/rust.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -750,13 +750,13 @@ _common_attrs = {
750750
doc = "A version to inject in the cargo environment variable.",
751751
default = "0.0.0",
752752
),
753+
"_allowlist_function_transition": attr.label(
754+
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
755+
),
753756
"_stamp_flag": attr.label(
754757
doc = "A setting used to determine whether or not the `--stamp` flag is enabled",
755758
default = Label("//rust/private:stamp"),
756759
),
757-
"_allowlist_function_transition": attr.label(
758-
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
759-
),
760760
} | RUSTC_ATTRS
761761

762762
_coverage_attrs = {

test/crate_scope/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ rust_library(
4545
name = "proc_macro_helper",
4646
srcs = ["proc_macro_helper.rs"],
4747
data = select({
48+
"//rust/settings:regular_crate_scope": [],
4849
"//rust/settings:proc_macro_scope": [":helper_data"],
49-
# Analysis fails if rust_library doesn't propagate the condition above.
5050
}),
5151
edition = "2021",
5252
rustc_env = {"CARGO_MANIFEST_DIR": package_name()},

0 commit comments

Comments
 (0)