Skip to content

Commit 25fa202

Browse files
authored
Delete //cargo/settings:incompatible_runfiles_cargo_manifest_dir (#3881)
Closes #2898
1 parent ad14c2b commit 25fa202

4 files changed

Lines changed: 19 additions & 49 deletions

File tree

cargo/private/cargo_build_script.bzl

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -372,28 +372,18 @@ def _cargo_build_script_impl(ctx):
372372
if not workspace_name:
373373
workspace_name = ctx.workspace_name
374374

375-
extra_args = []
376-
extra_inputs = []
377375
extra_output = []
378376

379377
# Relying on runfiles directories is unreliable when passing data to
380378
# dependent actions. Instead, an explicit directory should be created
381379
# until more reliable functionality is implemented in Bazel:
382380
# https://github.com/bazelbuild/bazel/issues/15486
383-
incompatible_runfiles_cargo_manifest_dir = ctx.attr._incompatible_runfiles_cargo_manifest_dir[BuildSettingInfo].value
384-
if not incompatible_runfiles_cargo_manifest_dir:
385-
script_data.append(ctx.attr.script[DefaultInfo].default_runfiles.files)
386-
manifest_dir = "{}.runfiles/{}/{}".format(script.path, workspace_name, ctx.label.package)
387-
else:
388-
runfiles_dir, runfiles_inputs, runfiles_args = _create_runfiles_dir(
389-
ctx = ctx,
390-
script = ctx.attr.script,
391-
retain_list = ctx.attr._cargo_manifest_dir_filename_suffixes_to_retain[BuildSettingInfo].value,
392-
)
393-
manifest_dir = "{}/{}/{}".format(runfiles_dir.path, workspace_name, ctx.label.package)
394-
extra_args.append(runfiles_args)
395-
extra_inputs.append(runfiles_inputs)
396-
extra_output = [runfiles_dir]
381+
runfiles_dir, runfiles_inputs, runfiles_args = _create_runfiles_dir(
382+
ctx = ctx,
383+
script = ctx.attr.script,
384+
retain_list = ctx.attr._cargo_manifest_dir_filename_suffixes_to_retain[BuildSettingInfo].value,
385+
)
386+
manifest_dir = "{}/{}/{}".format(runfiles_dir.path, workspace_name, ctx.label.package)
397387

398388
pkg_name = ctx.attr.pkg_name
399389
if pkg_name == "":
@@ -635,17 +625,18 @@ def _cargo_build_script_impl(ctx):
635625

636626
ctx.actions.run(
637627
executable = ctx.executable._cargo_build_script_runner,
638-
arguments = [args] + extra_args,
628+
arguments = [args, runfiles_args],
639629
outputs = [
640630
out_dir,
641631
env_out,
642632
flags_out,
643633
link_flags,
644634
link_search_paths,
645635
dep_env_out,
636+
runfiles_dir,
646637
] + extra_output,
647638
tools = tools,
648-
inputs = depset(build_script_inputs, transitive = extra_inputs),
639+
inputs = depset(build_script_inputs, transitive = [runfiles_inputs]),
649640
mnemonic = "CargoBuildScriptRun",
650641
progress_message = "Running Cargo build script {}".format(pkg_name),
651642
env = env,
@@ -665,7 +656,7 @@ def _cargo_build_script_impl(ctx):
665656
flags = flags_out,
666657
linker_flags = link_flags,
667658
link_search_paths = link_search_paths,
668-
compile_data = depset(extra_output, transitive = script_data),
659+
compile_data = depset([runfiles_dir] + extra_output, transitive = script_data),
669660
),
670661
OutputGroupInfo(
671662
**output_groups
@@ -805,9 +796,6 @@ cargo_build_script = rule(
805796
allow_files = True,
806797
default = Label("//cargo/private:no_cxx"),
807798
),
808-
"_incompatible_runfiles_cargo_manifest_dir": attr.label(
809-
default = Label("//cargo/settings:incompatible_runfiles_cargo_manifest_dir"),
810-
),
811799
},
812800
fragments = ["cpp"],
813801
toolchains = [

cargo/private/cargo_build_script_runner/bin.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ fn run_buildrs() -> Result<(), String> {
5151
cargo_manifest_maker,
5252
} = Args::parse();
5353

54-
if let Some(cargo_manifest_maker) = &cargo_manifest_maker {
55-
cargo_manifest_maker.create_runfiles_dir().unwrap()
56-
}
54+
cargo_manifest_maker.create_runfiles_dir().unwrap();
5755

5856
let out_dir_abs = exec_root.join(out_dir);
5957
// For some reason Google's RBE does not create the output directory, force create it.
@@ -232,11 +230,9 @@ fn run_buildrs() -> Result<(), String> {
232230
}
233231

234232
// Delete any runfiles that do not need to be propagated to down stream dependents.
235-
if let Some(cargo_manifest_maker) = cargo_manifest_maker {
236-
cargo_manifest_maker
237-
.drain_runfiles_dir(&out_dir_abs)
238-
.unwrap();
239-
}
233+
cargo_manifest_maker
234+
.drain_runfiles_dir(&out_dir_abs)
235+
.unwrap();
240236

241237
// If out_dir is empty add an empty file to the directory to avoid an upstream Bazel bug
242238
// https://github.com/bazelbuild/bazel/issues/28286
@@ -312,7 +308,7 @@ struct Args {
312308
stderr_path: Option<String>,
313309
rundir: String,
314310
input_dep_env_paths: Vec<String>,
315-
cargo_manifest_maker: Option<RunfilesMaker>,
311+
cargo_manifest_maker: RunfilesMaker,
316312
}
317313

318314
impl Args {
@@ -336,7 +332,8 @@ impl Args {
336332
let mut stderr_path = None;
337333
let mut rundir: Result<String, String> = Err("Argument `rundir` not provided".to_owned());
338334
let mut input_dep_env_paths = Vec::new();
339-
let mut cargo_manifest_maker = None;
335+
let mut cargo_manifest_maker: Result<RunfilesMaker, String> =
336+
Err("Argument `cargo_manifest_args` not provided".to_owned());
340337

341338
for mut arg in env::args().skip(1) {
342339
if arg.starts_with("--script=") {
@@ -364,7 +361,7 @@ impl Args {
364361
} else if arg.starts_with("--input_dep_env_path=") {
365362
input_dep_env_paths.push(arg.split_off("--input_dep_env_path=".len()));
366363
} else if arg.starts_with("--cargo_manifest_args=") {
367-
cargo_manifest_maker = Some(RunfilesMaker::from_param_file(
364+
cargo_manifest_maker = Ok(RunfilesMaker::from_param_file(
368365
&arg.split_off("--cargo_manifest_args=".len()),
369366
));
370367
}
@@ -383,7 +380,7 @@ impl Args {
383380
stderr_path,
384381
rundir: rundir.unwrap(),
385382
input_dep_env_paths,
386-
cargo_manifest_maker,
383+
cargo_manifest_maker: cargo_manifest_maker.unwrap(),
387384
}
388385
}
389386
}

cargo/settings/BUILD.bazel

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ load(
44
"cargo_manifest_dir_filename_suffixes_to_retain",
55
"debug_std_streams_output_group",
66
"experimental_symlink_execroot",
7-
"incompatible_runfiles_cargo_manifest_dir",
87
"use_default_shell_env",
98
)
109

@@ -27,6 +26,4 @@ debug_std_streams_output_group()
2726

2827
experimental_symlink_execroot()
2928

30-
incompatible_runfiles_cargo_manifest_dir()
31-
3229
use_default_shell_env()

cargo/settings/settings.bzl

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,6 @@ def experimental_symlink_execroot():
1414
build_setting_default = False,
1515
)
1616

17-
def incompatible_runfiles_cargo_manifest_dir():
18-
"""A flag which causes `cargo_build_script` to write an explicit `CARGO_MANIFEST_DIR` \
19-
directory from an action instead of using runfiles directories which cannot be \
20-
passed to downstream actions.
21-
22-
https://github.com/bazelbuild/bazel/issues/15486
23-
"""
24-
bool_flag(
25-
name = "incompatible_runfiles_cargo_manifest_dir",
26-
build_setting_default = True,
27-
)
28-
2917
def cargo_manifest_dir_filename_suffixes_to_retain():
3018
"""A flag which determines what files are retained in `CARGO_MANIFEST_DIR` directories \
3119
that are created in `CargoBuildScriptRun` actions.

0 commit comments

Comments
 (0)