diff --git a/src/cargo/ops/cargo_rustc/custom_build.rs b/src/cargo/ops/cargo_rustc/custom_build.rs index 9c6b7a2463f..13d3ed0fc1b 100644 --- a/src/cargo/ops/cargo_rustc/custom_build.rs +++ b/src/cargo/ops/cargo_rustc/custom_build.rs @@ -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()) { diff --git a/src/doc/environment-variables.md b/src/doc/environment-variables.md index 4db72d9d2ed..201c680ea27 100644 --- a/src/doc/environment-variables.md +++ b/src/doc/environment-variables.md @@ -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_` - For each activated feature of the package being built, this environment variable will be present where `` is the name of the feature uppercased diff --git a/tests/test_cargo_compile_custom_build.rs b/tests/test_cargo_compile_custom_build.rs index 6a4d3679ee7..2275fc452bc 100644 --- a/tests/test_cargo_compile_custom_build.rs +++ b/tests/test_cargo_compile_custom_build.rs @@ -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"); }