Skip to content

Commit 1568991

Browse files
committed
cargo_build_script: Populate LD and LDFLAGS
These are sometimes invoked by -sys crates.
1 parent 5a79d72 commit 1568991

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

cargo/cargo_build_script.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ def _build_script_impl(ctx):
9292
# Pull in env vars which may be required for the cc_toolchain to work (e.g. on OSX, the SDK version).
9393
# We hope that the linker env is sufficient for the whole cc_toolchain.
9494
cc_toolchain, feature_configuration = find_cc_toolchain(ctx)
95-
_, _, linker_env = get_linker_and_args(ctx, ctx.attr, cc_toolchain, feature_configuration, None)
95+
linker, link_args, linker_env = get_linker_and_args(ctx, ctx.attr, cc_toolchain, feature_configuration, None)
9696
env.update(**linker_env)
97+
env["LD"] = linker
98+
env["LDFLAGS"] = " ".join(link_args)
9799

98100
# MSVC requires INCLUDE to be set
99101
cc_env = get_cc_compile_env(cc_toolchain, feature_configuration)

cargo/cargo_build_script_runner/bin.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ fn run_buildrs() -> Result<(), String> {
110110
}
111111
}
112112

113+
if let Some(ld_path) = env::var_os("LD") {
114+
command.env("LD", absolutify(&exec_root, ld_path));
115+
}
116+
113117
// replace env vars with a ${pwd} prefix with the exec_root
114118
for (key, value) in env::vars() {
115119
let exec_root_str = exec_root.to_str().expect("exec_root not in utf8");

0 commit comments

Comments
 (0)