Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use C++ environment variables when constructing link command line #252

Merged
merged 2 commits into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions rust/private/legacy_cc_starlark_api_shim.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@ def get_libs_for_static_executable(dep):
A depset[File]
"""
libraries_to_link = dep[CcInfo].linking_context.libraries_to_link

# Remove `if` line once Bazel 0.27 is used
# (https://github.com/bazelbuild/bazel/issues/8118)
if type(libraries_to_link) == type(depset()):
libraries_to_link = libraries_to_link.to_list()

return depset([_get_preferred_artifact(lib) for lib in libraries_to_link])
return depset([_get_preferred_artifact(lib) for lib in libraries_to_link.to_list()])

def _get_preferred_artifact(library_to_link):
return (
Expand Down
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