rust/tests/run-make/extern-flag-pathless/rmake.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
1.7 KiB
Rust
Raw Normal View History

2024-06-26 13:56:11 -05:00
// It is possible, since #64882, to use the --extern flag without an explicit
// path. In the event of two --extern flags, the explicit one with a path will take
// priority, but otherwise, it is a more concise way of fetching specific libraries.
// This test checks that the default priority of explicit extern flags and rlibs is
// respected.
// See https://github.com/rust-lang/rust/pull/64882
//@ ignore-cross-compile
// Reason: the compiled binary is executed
2024-07-17 08:31:38 -05:00
use run_make_support::{dynamic_lib_name, rfs, run, run_fail, rust_lib_name, rustc};
2024-06-26 13:56:11 -05:00
fn main() {
rustc().input("bar.rs").crate_type("rlib").crate_type("dylib").arg("-Cprefer-dynamic").run();
// By default, the rlib has priority over the dylib.
rustc().input("foo.rs").arg("--extern").arg("bar").run();
rfs::rename(dynamic_lib_name("bar"), "bar.tmp");
2024-06-26 13:56:11 -05:00
run("foo");
rfs::rename("bar.tmp", dynamic_lib_name("bar"));
2024-06-26 13:56:11 -05:00
rustc().input("foo.rs").extern_("bar", rust_lib_name("bar")).arg("--extern").arg("bar").run();
rfs::rename(dynamic_lib_name("bar"), "bar.tmp");
2024-06-26 13:56:11 -05:00
run("foo");
rfs::rename("bar.tmp", dynamic_lib_name("bar"));
2024-06-26 13:56:11 -05:00
// The first explicit usage of extern overrides the second pathless --extern bar.
rustc()
.input("foo.rs")
.extern_("bar", dynamic_lib_name("bar"))
.arg("--extern")
.arg("bar")
.run();
rfs::rename(dynamic_lib_name("bar"), "bar.tmp");
2024-06-26 13:56:11 -05:00
run_fail("foo");
rfs::rename("bar.tmp", dynamic_lib_name("bar"));
2024-06-26 13:56:11 -05:00
// With prefer-dynamic, execution fails as it refuses to use the rlib.
rustc().input("foo.rs").arg("--extern").arg("bar").arg("-Cprefer-dynamic").run();
rfs::rename(dynamic_lib_name("bar"), "bar.tmp");
2024-06-26 13:56:11 -05:00
run_fail("foo");
rfs::rename("bar.tmp", dynamic_lib_name("bar"));
2024-06-26 13:56:11 -05:00
}