rewrite redundant-libs to rmake · rust-lang/rust@011727f (original) (raw)

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
1 +// rustc will remove one of the two redundant references to foo below. Depending
2 +// on which one gets removed, we'll get a linker error on SOME platforms (like
3 +// Linux). On these platforms, when a library is referenced, the linker will
4 +// only pull in the symbols needed _at that point in time_. If a later library
5 +// depends on additional symbols from the library, they will not have been pulled
6 +// in, and you'll get undefined symbols errors.
7 +//
8 +// So in this example, we need to ensure that rustc keeps the _later_ reference
9 +// to foo, and not the former one.
10 +
11 +//@ ignore-cross-compile
12 +// Reason: the compiled binary is executed
13 +//@ ignore-windows-msvc
14 +// Reason: this test links libraries via link.exe, which only accepts the import library
15 +// for the dynamic library, i.e. `foo.dll.lib`. However, build_native_dynamic_lib only
16 +// produces `foo.dll` - the dynamic library itself. To make this test work on MSVC, one
17 +// would need to derive the import library from the dynamic library.
18 +// See https://stackoverflow.com/questions/9360280/
19 +
20 +use run_make_support::{
21 + build_native_dynamic_lib, build_native_static_lib, cwd, is_msvc, rfs, run, rustc,
22 +};
23 +
24 +fn main() {
25 +build_native_dynamic_lib("foo");
26 +build_native_static_lib("bar");
27 +build_native_static_lib("baz");
28 +rustc()
29 +.args(&["-lstatic=bar", "-lfoo", "-lstatic=baz", "-lfoo"])
30 +.input("main.rs")
31 +.print("link-args")
32 +.run();
33 +run("main");
34 +}