Skip to content

Commit

Permalink
Use C++ environment variables when constructing link command line
Browse files Browse the repository at this point in the history
This PR makes sure that rustc action also takes declared environment
variables from the C++ toolchain when constructing the action. This way
the C++ toolchain can start using more environment variables without
breaking rust.
  • Loading branch information
hlopko committed Sep 26, 2019
1 parent adccbba commit e1710fe
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,17 @@ def _get_linker_and_args(ctx, rpaths):
action_name = CPP_LINK_EXECUTABLE_ACTION_NAME,
variables = link_variables,
)
link_env = cc_common.get_environment_variables(
feature_configuration = feature_configuration,
action_name = CPP_LINK_EXECUTABLE_ACTION_NAME,
variables = link_variables,
)
ld = cc_common.get_tool_for_action(
feature_configuration = feature_configuration,
action_name = CPP_LINK_EXECUTABLE_ACTION_NAME,
)

return ld, link_args
return ld, link_args, link_env

def rustc_compile_action(
ctx,
Expand Down Expand Up @@ -246,7 +251,7 @@ def rustc_compile_action(

# Link!
rpaths = _compute_rpaths(toolchain, output_dir, dep_info)
ld, link_args = _get_linker_and_args(ctx, rpaths)
ld, link_args, link_env = _get_linker_and_args(ctx, rpaths)
args.add("--codegen=linker=" + ld)
args.add_joined("--codegen", link_args, join_with = " ", format_joined = "link-args=%s")

Expand Down Expand Up @@ -289,11 +294,14 @@ def rustc_compile_action(
toolchain.rustc.path,
)

env = _get_rustc_env(ctx, toolchain)
env.update(link_env)

ctx.actions.run_shell(
command = command,
inputs = compile_inputs,
outputs = [crate_info.output],
env = _get_rustc_env(ctx, toolchain),
env = env,
arguments = [args],
mnemonic = "Rustc",
progress_message = "Compiling Rust {} {} ({} files)".format(crate_info.type, ctx.label.name, len(crate_info.srcs)),
Expand Down

0 comments on commit e1710fe

Please sign in to comment.