From e1710fe9d2f46ea8beb576db16b3fa756a14f2a0 Mon Sep 17 00:00:00 2001 From: Marcel Hlopko Date: Thu, 26 Sep 2019 10:12:39 +0200 Subject: [PATCH] Use C++ environment variables when constructing link command line 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. --- rust/private/rustc.bzl | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index 6b44e2f02d..ed87d71663 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -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, @@ -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") @@ -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)),