Skip to content

Commit

Permalink
cargo_build_script: Populate LD and LDFLAGS (#1067)
Browse files Browse the repository at this point in the history
These are sometimes invoked by -sys crates.
  • Loading branch information
illicitonion committed Dec 16, 2021
1 parent 5a79d72 commit 09c364f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cargo/cargo_build_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ def _build_script_impl(ctx):
# Pull in env vars which may be required for the cc_toolchain to work (e.g. on OSX, the SDK version).
# We hope that the linker env is sufficient for the whole cc_toolchain.
cc_toolchain, feature_configuration = find_cc_toolchain(ctx)
_, _, linker_env = get_linker_and_args(ctx, ctx.attr, cc_toolchain, feature_configuration, None)
linker, link_args, linker_env = get_linker_and_args(ctx, ctx.attr, cc_toolchain, feature_configuration, None)
env.update(**linker_env)
env["LD"] = linker
env["LDFLAGS"] = " ".join(link_args)

# MSVC requires INCLUDE to be set
cc_env = get_cc_compile_env(cc_toolchain, feature_configuration)
Expand Down
4 changes: 4 additions & 0 deletions cargo/cargo_build_script_runner/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ fn run_buildrs() -> Result<(), String> {
}
}

if let Some(ld_path) = env::var_os("LD") {
command.env("LD", exec_root.join(ld_path));
}

// replace env vars with a ${pwd} prefix with the exec_root
for (key, value) in env::vars() {
let exec_root_str = exec_root.to_str().expect("exec_root not in utf8");
Expand Down

0 comments on commit 09c364f

Please sign in to comment.