Skip to content

Commit fb03dad

Browse files
committed
Auto merge of #2710 - sbeckeriv:the-missing-lib, r=alexcrichton
The missing lib Dearest Reviewer, This pull request allows the value of project.links to be passed into the build script via an environment variable. This closes #1220 . I have added a test that makes sure that the environment variable is set. Also note I am using CARGO_LIB not LIB because it appears to be used for windows in appveyor. I think CARGO_LIB fits better. I have also updated the documentation to reflect the new variable. Thanks! Becker
2 parents 48fd9de + 388028e commit fb03dad

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

src/cargo/ops/cargo_rustc/custom_build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
109109
.env("PROFILE", if cx.build_config.release {"release"} else {"debug"})
110110
.env("HOST", &cx.config.rustc_info().host);
111111

112+
if let Some(links) = unit.pkg.manifest().links(){
113+
p.env("CARGO_MANIFEST_LINKS", links);
114+
}
115+
112116
// Be sure to pass along all enabled features for this package, this is the
113117
// last piece of statically known information that we have.
114118
if let Some(features) = cx.resolve.features(unit.pkg.package_id()) {

src/doc/environment-variables.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ let out_dir = env::var("OUT_DIR").unwrap();
6868
script). Also note that this is the value of the
6969
current working directory of the build script when it
7070
starts.
71+
* `CARGO_MANIFEST_LINKS` - the manifest `links` value.
7172
* `CARGO_FEATURE_<name>` - For each activated feature of the package being
7273
built, this environment variable will be present
7374
where `<name>` is the name of the feature uppercased

tests/test_cargo_compile_custom_build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,11 @@ test!(links_passes_env_vars {
353353
"#)
354354
.file("a/src/lib.rs", "")
355355
.file("a/build.rs", r#"
356+
use std::env;
356357
fn main() {
358+
let lib = env::var("CARGO_MANIFEST_LINKS").unwrap();
359+
assert_eq!(lib, "foo");
360+
357361
println!("cargo:foo=bar");
358362
println!("cargo:bar=baz");
359363
}

0 commit comments

Comments
 (0)