Browse Source

Add an option to disabled automatic linking of the produced binary.

This is mostly useful when your tests require building some piece of C code,
but you do not want the entire crate to be linked against it. You can then
just do `#[cfg_attr(test,link(name = "mylibrary", kind = "static"))]` and the
code will only be linked for tests.
add-rc-path
Niels Grewe 10 years ago
parent
commit
6713b25a1b
  1. 18
      src/lib.rs

18
src/lib.rs

@ -75,6 +75,7 @@ pub struct Config {
env: Vec<(OsString, OsString)>,
compiler: Option<PathBuf>,
archiver: Option<PathBuf>,
link: bool,
}
fn getenv(v: &str) -> Option<String> {
@ -133,6 +134,7 @@ impl Config {
env: Vec::new(),
compiler: None,
archiver: None,
link: true
}
}
@ -286,6 +288,16 @@ 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;
self
}
#[doc(hidden)]
pub fn __set_env<A, B>(&mut self, a: A, b: B) -> &mut Config
@ -313,8 +325,10 @@ impl Config {
self.assemble(lib_name, &dst.join(output), &objects);
println!("cargo:rustc-link-search=native={}", dst.display());
println!("cargo:rustc-link-lib=static={}",
&output[3..output.len() - 2]);
if self.link {
println!("cargo:rustc-link-lib=static={}",
&output[3..output.len() - 2]);
}
// Add specific C++ libraries, if enabled.
if self.cpp {

Loading…
Cancel
Save