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

Set CARGO_MANIFEST_LINKS if links is set #2190

Merged
merged 1 commit into from
Oct 10, 2023
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
6 changes: 4 additions & 2 deletions cargo/private/cargo_build_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ def _cargo_build_script_impl(ctx):
for f in ctx.attr.crate_features:
env["CARGO_FEATURE_" + f.upper().replace("-", "_")] = "1"

links = ctx.attr.links or ""
if links:
env["CARGO_MANIFEST_LINKS"] = links

# Add environment variables from the Rust toolchain.
env.update(toolchain.env)

Expand Down Expand Up @@ -208,8 +212,6 @@ def _cargo_build_script_impl(ctx):
transitive = toolchain_tools,
)

links = ctx.attr.links or ""

# dep_env_file contains additional environment variables coming from
# direct dependency sys-crates' build scripts. These need to be made
# available to the current crate build script.
Expand Down
1 change: 1 addition & 0 deletions test/cargo_build_script/tools_exec/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ cargo_build_script(
"TOOL": "$(execpath :tool)",
},
edition = "2018",
links = "beep",
# Add a flag to test that they're exposed to the build script
rustc_flags = ["--verbose"],
toolchains = ["//rust/toolchain:current_rust_toolchain"],
Expand Down
2 changes: 2 additions & 0 deletions test/cargo_build_script/tools_exec/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ fn main() {
for env_var in &["CFLAGS", "CXXFLAGS", "LDFLAGS"] {
assert!(std::env::var(env_var).is_ok());
}

assert_eq!(std::env::var("CARGO_MANIFEST_LINKS").unwrap(), "beep");
}