Skip to content

Commit b2a482f

Browse files
authored
support --action_env vars in build scripts (#447)
The existing rustc_env attribute is useful when the provided env var will not differ between machines, but is not practical when each user of the build script may require a different value, such as passing in a custom path to a tool on their machine. Fixes the issue mentioned in #314 (comment) by starting from the default environment.
1 parent 1d2ad1f commit b2a482f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

cargo/cargo_build_script.bzl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,19 @@ def _build_script_impl(ctx):
4040

4141
cc_toolchain = find_cpp_toolchain(ctx)
4242

43-
env = {
43+
# Start with the default shell env, which contains any --action_env
44+
# settings passed in on the command line.
45+
env = dict(ctx.configuration.default_shell_env)
46+
47+
env.update({
4448
"CARGO_MANIFEST_DIR": manifest_dir,
4549
"CARGO_PKG_NAME": crate_name,
4650
"HOST": toolchain.exec_triple,
4751
"OPT_LEVEL": compilation_mode_opt_level,
4852
"RUSTC": toolchain.rustc.path,
4953
"TARGET": toolchain.target_triple,
5054
# OUT_DIR is set by the runner itself, rather than on the action.
51-
}
55+
})
5256

5357
if ctx.attr.version:
5458
version = ctx.attr.version.split("+")[0].split(".")

0 commit comments

Comments
 (0)