diff --git a/gcc-test/build.rs b/gcc-test/build.rs index 132614f..276da26 100644 --- a/gcc-test/build.rs +++ b/gcc-test/build.rs @@ -72,5 +72,5 @@ fn main() { // This tests whether we can build a library but not link it to the main crate. // The test module will do its own linking. - gcc::Config::new().link(false).file("src/opt_linkage.c").compile("libOptLinkage.a"); + gcc::Config::new().cargo_metadata(false).file("src/opt_linkage.c").compile("libOptLinkage.a"); } diff --git a/src/lib.rs b/src/lib.rs index c5b5d36..e093a15 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -75,7 +75,7 @@ pub struct Config { env: Vec<(OsString, OsString)>, compiler: Option, archiver: Option, - link: bool, + cargo_metadata: bool, } fn getenv(v: &str) -> Option { @@ -134,7 +134,7 @@ impl Config { env: Vec::new(), compiler: None, archiver: None, - link: true + cargo_metadata: true } } @@ -288,13 +288,10 @@ impl Config { self.archiver = Some(archiver.as_ref().to_owned()); self } - /// Define whether the compiled archive will automatically be linked. - /// - /// If you don't want the compiled archive to be linked into the rust - /// binary automatically, you can set this option to `false`. It can - /// still be linked explicitly using the `#[cfg(link())]` directive. - pub fn link(&mut self, link: bool) -> &mut Config { - self.link = link; + /// Define whether metadata should be emitted for cargo allowing it to + /// automatically link the binary. Defaults to `true`. + pub fn cargo_metadata(&mut self, cargo_metadata: bool) -> &mut Config { + self.cargo_metadata = cargo_metadata; self } @@ -324,16 +321,18 @@ impl Config { } self.assemble(lib_name, &dst.join(output), &objects); - println!("cargo:rustc-link-search=native={}", dst.display()); - if self.link { + + if self.cargo_metadata { println!("cargo:rustc-link-lib=static={}", &output[3..output.len() - 2]); - } + println!("cargo:rustc-link-search=native={}", dst.display()); + + // Add specific C++ libraries, if enabled. + if self.cpp { + if let Some(stdlib) = self.get_cpp_link_stdlib() { + println!("cargo:rustc-link-lib={}", stdlib); + } - // Add specific C++ libraries, if enabled. - if self.cpp { - if let Some(stdlib) = self.get_cpp_link_stdlib() { - println!("cargo:rustc-link-lib={}", stdlib); } } }