diff --git a/gcc-test/build.rs b/gcc-test/build.rs index 141e36f..132614f 100644 --- a/gcc-test/build.rs +++ b/gcc-test/build.rs @@ -69,4 +69,8 @@ fn main() { println!("cargo:rustc-link-lib=msvc"); println!("cargo:rustc-link-search={}", out.display()); } + + // 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"); } diff --git a/gcc-test/tests/all.rs b/gcc-test/tests/all.rs index ef58550..2537960 100644 --- a/gcc-test/tests/all.rs +++ b/gcc-test/tests/all.rs @@ -2,6 +2,14 @@ extern crate gcc_test; use gcc_test::*; + +// This will cause a link failure if the archive is already +// linked against the gcc_test crate. +#[link(name = "OptLinkage", kind = "static")] +extern { + fn answer() -> i32; +} + #[test] fn foo_here() { unsafe { @@ -46,3 +54,8 @@ fn msvc_here() { msvc(); } } + +#[test] +fn opt_linkage() { + unsafe { assert_eq!(answer(),42); } +}