|
| 1 | +// It is possible, since #64882, to use the --extern flag without an explicit |
| 2 | +// path. In the event of two --extern flags, the explicit one with a path will take |
| 3 | +// priority, but otherwise, it is a more concise way of fetching specific libraries. |
| 4 | +// This test checks that the default priority of explicit extern flags and rlibs is |
| 5 | +// respected. |
| 6 | +// See https://github.com/rust-lang/rust/pull/64882 |
| 7 | + |
| 8 | +use run_make_support::{dynamic_lib_name, fs_wrapper, run, run_fail, rust_lib_name, rustc}; |
| 9 | + |
| 10 | +fn main() { |
| 11 | + rustc().input("bar.rs").crate_type("rlib").crate_type("dylib").arg("-Cprefer-dynamic").run(); |
| 12 | + |
| 13 | + // By default, the rlib has priority over the dylib. |
| 14 | + rustc().input("foo.rs").arg("--extern").arg("bar").run(); |
| 15 | + fs_wrapper::rename(dynamic_lib_name("bar"), "bar.tmp"); |
| 16 | + run("foo"); |
| 17 | + fs_wrapper::rename("bar.tmp", dynamic_lib_name("bar")); |
| 18 | + |
| 19 | + rustc().input("foo.rs").extern_("bar", rust_lib_name("bar")).arg("--extern").arg("bar").run(); |
| 20 | + fs_wrapper::rename(dynamic_lib_name("bar"), "bar.tmp"); |
| 21 | + run("foo"); |
| 22 | + fs_wrapper::rename("bar.tmp", dynamic_lib_name("bar")); |
| 23 | + |
| 24 | + // The first explicit usage of extern overrides the second pathless --extern bar. |
| 25 | + rustc() |
| 26 | + .input("foo.rs") |
| 27 | + .extern_("bar", dynamic_lib_name("bar")) |
| 28 | + .arg("--extern") |
| 29 | + .arg("bar") |
| 30 | + .run(); |
| 31 | + fs_wrapper::rename(dynamic_lib_name("bar"), "bar.tmp"); |
| 32 | + run_fail("foo"); |
| 33 | + fs_wrapper::rename("bar.tmp", dynamic_lib_name("bar")); |
| 34 | + |
| 35 | + // With prefer-dynamic, execution fails as it refuses to use the rlib. |
| 36 | + rustc().input("foo.rs").arg("--extern").arg("bar").arg("-Cprefer-dynamic").run(); |
| 37 | + fs_wrapper::rename(dynamic_lib_name("bar"), "bar.tmp"); |
| 38 | + run_fail("foo"); |
| 39 | + fs_wrapper::rename("bar.tmp", dynamic_lib_name("bar")); |
| 40 | +} |
0 commit comments