Skip to content
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
4 changes: 4 additions & 0 deletions src/cargo/ops/cargo_rustc/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
.env("PROFILE", if cx.build_config.release {"release"} else {"debug"})
.env("HOST", &cx.config.rustc_info().host);

if let Some(links) = unit.pkg.manifest().links(){
p.env("CARGO_MANIFEST_LINKS", links);
}

// Be sure to pass along all enabled features for this package, this is the
// last piece of statically known information that we have.
if let Some(features) = cx.resolve.features(unit.pkg.package_id()) {
Expand Down
1 change: 1 addition & 0 deletions src/doc/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ let out_dir = env::var("OUT_DIR").unwrap();
script). Also note that this is the value of the
current working directory of the build script when it
starts.
* `CARGO_MANIFEST_LINKS` - the manifest `links` value.
* `CARGO_FEATURE_<name>` - For each activated feature of the package being
built, this environment variable will be present
where `<name>` is the name of the feature uppercased
Expand Down
4 changes: 4 additions & 0 deletions tests/test_cargo_compile_custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,11 @@ test!(links_passes_env_vars {
"#)
.file("a/src/lib.rs", "")
.file("a/build.rs", r#"
use std::env;
fn main() {
let lib = env::var("CARGO_MANIFEST_LINKS").unwrap();
assert_eq!(lib, "foo");

println!("cargo:foo=bar");
println!("cargo:bar=baz");
}
Expand Down