Browse Source

Rename link() to cargo_metadata() and cover all the cargo:… flags.

add-rc-path
Niels Grewe 9 years ago
parent
commit
a383401530
  1. 2
      gcc-test/build.rs
  2. 31
      src/lib.rs

2
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");
}

31
src/lib.rs

@ -75,7 +75,7 @@ pub struct Config {
env: Vec<(OsString, OsString)>,
compiler: Option<PathBuf>,
archiver: Option<PathBuf>,
link: bool,
cargo_metadata: bool,
}
fn getenv(v: &str) -> Option<String> {
@ -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);
}
}
}

Loading…
Cancel
Save