Skip to content

Commit 671ec50

Browse files
committed
fix: Use "exec" for cargo build scripts
The nuance between when to use exec vs target is a bit tricky to get right sometimes. You want to use "exec" for executables that are used at build time and "target" for runtime dependencies Since cargo build script are run at build time, they need to be set to exec. This fixes circumstances where a user is using RBE on a platform different than their host machine For example, I found this bug when I enabled my linux based RBE cluster when trying to do a bazel run of a rust binary on my mac. When the build script executed it threw up because the RBE cluster was using the mac version of the script.
1 parent d256c7b commit 671ec50

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

cargo/private/cargo_build_script.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ cargo_build_script = rule(
625625
doc = "The binary script to run, generally a `rust_binary` target.",
626626
executable = True,
627627
mandatory = True,
628-
cfg = "target",
628+
cfg = "exec",
629629
providers = [CargoBuildScriptRunfilesInfo],
630630
),
631631
"tools": attr.label_list(

test/cargo_build_script/location_expansion/test.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,19 @@ pub fn test_execpath() {
6363
)
6464
.1;
6565

66-
let (data_cfg, data_short_path) = data_path.split_at(
66+
let (_data_cfg, data_short_path) = data_path.split_at(
6767
data_path
6868
.find("/bin/")
6969
.unwrap_or_else(|| panic!("Failed to find bin in {}", data_path))
7070
+ "/bin/".len(),
7171
);
72-
let (tool_cfg, tool_short_path) = tool_path.split_at(
72+
let (_tool_cfg, tool_short_path) = tool_path.split_at(
7373
tool_path
7474
.find("/bin/")
7575
.unwrap_or_else(|| panic!("Failed to find bin in {}", tool_path))
7676
+ "/bin/".len(),
7777
);
7878

79-
assert_ne!(
80-
data_cfg, tool_cfg,
81-
"Data and tools should not be from the same configuration."
82-
);
83-
8479
assert_eq!(
8580
data_short_path,
8681
"test/cargo_build_script/location_expansion/target_data.txt"

0 commit comments

Comments
 (0)