From 16df91b97ad1df021ccd2203c974f416aae7e76b Mon Sep 17 00:00:00 2001 From: Oneirical Date: Wed, 26 Jun 2024 14:56:11 -0400 Subject: [PATCH] rewrite extern-flag-pathless to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/extern-flag-pathless/Makefile | 34 ---------------- tests/run-make/extern-flag-pathless/rmake.rs | 40 +++++++++++++++++++ 3 files changed, 40 insertions(+), 35 deletions(-) delete mode 100644 tests/run-make/extern-flag-pathless/Makefile create mode 100644 tests/run-make/extern-flag-pathless/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index a29d57d1603..463edb461e8 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -33,7 +33,6 @@ run-make/env-dep-info/Makefile run-make/export-executable-symbols/Makefile run-make/extern-diff-internal-name/Makefile run-make/extern-flag-disambiguates/Makefile -run-make/extern-flag-pathless/Makefile run-make/extern-fn-explicit-align/Makefile run-make/extern-fn-generic/Makefile run-make/extern-fn-mangle/Makefile diff --git a/tests/run-make/extern-flag-pathless/Makefile b/tests/run-make/extern-flag-pathless/Makefile deleted file mode 100644 index 36b374e0d2e..00000000000 --- a/tests/run-make/extern-flag-pathless/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -# Test mixing pathless --extern with paths. - -# Test for static linking by checking that the binary runs if the dylib -# is removed and test for dynamic linking by checking that the binary -# fails to run if the dylib is removed. - -all: - $(RUSTC) bar.rs --crate-type=rlib --crate-type=dylib -Cprefer-dynamic - - # rlib preferred over dylib - $(RUSTC) foo.rs --extern bar - mv $(call DYLIB,bar) $(TMPDIR)/bar.tmp - $(call RUN,foo) - mv $(TMPDIR)/bar.tmp $(call DYLIB,bar) - - $(RUSTC) foo.rs --extern bar=$(TMPDIR)/libbar.rlib --extern bar - mv $(call DYLIB,bar) $(TMPDIR)/bar.tmp - $(call RUN,foo) - mv $(TMPDIR)/bar.tmp $(call DYLIB,bar) - - # explicit --extern overrides pathless - $(RUSTC) foo.rs --extern bar=$(call DYLIB,bar) --extern bar - mv $(call DYLIB,bar) $(TMPDIR)/bar.tmp - $(call FAIL,foo) - mv $(TMPDIR)/bar.tmp $(call DYLIB,bar) - - # prefer-dynamic does what it says - $(RUSTC) foo.rs --extern bar -C prefer-dynamic - mv $(call DYLIB,bar) $(TMPDIR)/bar.tmp - $(call FAIL,foo) - mv $(TMPDIR)/bar.tmp $(call DYLIB,bar) diff --git a/tests/run-make/extern-flag-pathless/rmake.rs b/tests/run-make/extern-flag-pathless/rmake.rs new file mode 100644 index 00000000000..2f151136c33 --- /dev/null +++ b/tests/run-make/extern-flag-pathless/rmake.rs @@ -0,0 +1,40 @@ +// 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 + +use run_make_support::{dynamic_lib_name, fs_wrapper, run, run_fail, rust_lib_name, rustc}; + +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(); + fs_wrapper::rename(dynamic_lib_name("bar"), "bar.tmp"); + run("foo"); + fs_wrapper::rename("bar.tmp", dynamic_lib_name("bar")); + + rustc().input("foo.rs").extern_("bar", rust_lib_name("bar")).arg("--extern").arg("bar").run(); + fs_wrapper::rename(dynamic_lib_name("bar"), "bar.tmp"); + run("foo"); + fs_wrapper::rename("bar.tmp", dynamic_lib_name("bar")); + + // 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(); + fs_wrapper::rename(dynamic_lib_name("bar"), "bar.tmp"); + run_fail("foo"); + fs_wrapper::rename("bar.tmp", dynamic_lib_name("bar")); + + // With prefer-dynamic, execution fails as it refuses to use the rlib. + rustc().input("foo.rs").arg("--extern").arg("bar").arg("-Cprefer-dynamic").run(); + fs_wrapper::rename(dynamic_lib_name("bar"), "bar.tmp"); + run_fail("foo"); + fs_wrapper::rename("bar.tmp", dynamic_lib_name("bar")); +}