about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJubilee <46493976+workingjubilee@users.noreply.github.com>2024-06-12 20:03:18 -0700
committerGitHub <noreply@github.com>2024-06-12 20:03:18 -0700
commit1a6b1a14f9825879f7a9606ccbb5982cdcc46d1e (patch)
treecb5a8a9f2476dc6bfa0e4558809b59233b583b84
parent8cf5101d77cd9eeb12751c563d8098aba2c604d0 (diff)
parent2ac5faa509e9511665986a5ac25ed7c4e427aac2 (diff)
downloadrust-1a6b1a14f9825879f7a9606ccbb5982cdcc46d1e.tar.gz
rust-1a6b1a14f9825879f7a9606ccbb5982cdcc46d1e.zip
Rollup merge of #125674 - Oneirical:another-day-another-test, r=jieyouxu
Rewrite `symlinked-extern`, `symlinked-rlib` and `symlinked-libraries` `run-make` tests in `rmake.rs` format

Part of #121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html).

try-job: x86_64-msvc
-rw-r--r--src/tools/run-make-support/src/lib.rs28
-rw-r--r--src/tools/tidy/src/allowed_run_make_makefiles.txt3
-rw-r--r--tests/run-make/symlinked-extern/Makefile12
-rw-r--r--tests/run-make/symlinked-extern/rmake.rs21
-rw-r--r--tests/run-make/symlinked-libraries/Makefile11
-rw-r--r--tests/run-make/symlinked-libraries/rmake.rs16
-rw-r--r--tests/run-make/symlinked-rlib/Makefile10
-rw-r--r--tests/run-make/symlinked-rlib/rmake.rs16
8 files changed, 81 insertions, 36 deletions
diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs
index b920f9a07db..9ec20bf8fd4 100644
--- a/src/tools/run-make-support/src/lib.rs
+++ b/src/tools/run-make-support/src/lib.rs
@@ -93,6 +93,34 @@ pub fn source_root() -> PathBuf {
     env_var("SOURCE_ROOT").into()
 }
 
+/// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix.
+#[cfg(target_family = "windows")]
+pub fn create_symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) {
+    if link.as_ref().exists() {
+        std::fs::remove_dir(link.as_ref()).unwrap();
+    }
+    use std::os::windows::fs;
+    fs::symlink_file(original.as_ref(), link.as_ref()).expect(&format!(
+        "failed to create symlink {:?} for {:?}",
+        link.as_ref().display(),
+        original.as_ref().display(),
+    ));
+}
+
+/// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix.
+#[cfg(target_family = "unix")]
+pub fn create_symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) {
+    if link.as_ref().exists() {
+        std::fs::remove_dir(link.as_ref()).unwrap();
+    }
+    use std::os::unix::fs;
+    fs::symlink(original.as_ref(), link.as_ref()).expect(&format!(
+        "failed to create symlink {:?} for {:?}",
+        link.as_ref().display(),
+        original.as_ref().display(),
+    ));
+}
+
 /// Construct the static library name based on the platform.
 pub fn static_lib_name(name: &str) -> String {
     // See tools.mk (irrelevant lines omitted):
diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt
index 87185eef952..a4d19eee980 100644
--- a/src/tools/tidy/src/allowed_run_make_makefiles.txt
+++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt
@@ -227,9 +227,6 @@ run-make/std-core-cycle/Makefile
 run-make/symbol-mangling-hashed/Makefile
 run-make/symbol-visibility/Makefile
 run-make/symbols-include-type-name/Makefile
-run-make/symlinked-extern/Makefile
-run-make/symlinked-libraries/Makefile
-run-make/symlinked-rlib/Makefile
 run-make/sysroot-crates-are-unstable/Makefile
 run-make/target-cpu-native/Makefile
 run-make/target-specs/Makefile
diff --git a/tests/run-make/symlinked-extern/Makefile b/tests/run-make/symlinked-extern/Makefile
deleted file mode 100644
index 28c764b84e8..00000000000
--- a/tests/run-make/symlinked-extern/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-# ignore-cross-compile
-include ../tools.mk
-
-# ignore-windows
-# `ln` is actually `cp` on msys.
-
-all:
-	$(RUSTC) foo.rs
-	mkdir -p $(TMPDIR)/other
-	ln -nsf $(TMPDIR)/libfoo.rlib $(TMPDIR)/other
-	$(RUSTC) bar.rs -L $(TMPDIR)
-	$(RUSTC) baz.rs --extern foo=$(TMPDIR)/other/libfoo.rlib  -L $(TMPDIR)
diff --git a/tests/run-make/symlinked-extern/rmake.rs b/tests/run-make/symlinked-extern/rmake.rs
new file mode 100644
index 00000000000..98f69aefbe6
--- /dev/null
+++ b/tests/run-make/symlinked-extern/rmake.rs
@@ -0,0 +1,21 @@
+// Crates that are resolved normally have their path canonicalized and all
+// symlinks resolved. This did not happen for paths specified
+// using the --extern option to rustc, which could lead to rustc thinking
+// that it encountered two different versions of a crate, when it's
+// actually the same version found through different paths.
+// See https://github.com/rust-lang/rust/pull/16505
+
+// This test checks that --extern and symlinks together
+// can result in successful compilation.
+
+//@ ignore-cross-compile
+
+use run_make_support::{create_symlink, cwd, fs_wrapper, rustc};
+
+fn main() {
+    rustc().input("foo.rs").run();
+    fs_wrapper::create_dir_all("other");
+    create_symlink("libfoo.rlib", "other");
+    rustc().input("bar.rs").library_search_path(cwd()).run();
+    rustc().input("baz.rs").extern_("foo", "other").library_search_path(cwd()).run();
+}
diff --git a/tests/run-make/symlinked-libraries/Makefile b/tests/run-make/symlinked-libraries/Makefile
deleted file mode 100644
index fb0b6127e6f..00000000000
--- a/tests/run-make/symlinked-libraries/Makefile
+++ /dev/null
@@ -1,11 +0,0 @@
-# ignore-cross-compile
-include ../tools.mk
-
-# ignore-windows
-# `ln` is actually `cp` on msys.
-
-all:
-	$(RUSTC) foo.rs -C prefer-dynamic
-	mkdir -p $(TMPDIR)/other
-	ln -nsf $(TMPDIR)/$(call DYLIB_GLOB,foo) $(TMPDIR)/other
-	$(RUSTC) bar.rs -L $(TMPDIR)/other
diff --git a/tests/run-make/symlinked-libraries/rmake.rs b/tests/run-make/symlinked-libraries/rmake.rs
new file mode 100644
index 00000000000..eaf0c44206a
--- /dev/null
+++ b/tests/run-make/symlinked-libraries/rmake.rs
@@ -0,0 +1,16 @@
+// When a directory and a symlink simultaneously exist with the same name,
+// setting that name as the library search path should not cause rustc
+// to avoid looking in the symlink and cause an error. This test creates
+// a directory and a symlink named "other", and places the library in the symlink.
+// If it succeeds, the library was successfully found.
+// See https://github.com/rust-lang/rust/issues/12459
+
+//@ ignore-cross-compile
+use run_make_support::{create_symlink, dynamic_lib_name, fs_wrapper, rustc};
+
+fn main() {
+    rustc().input("foo.rs").arg("-Cprefer-dynamic").run();
+    fs_wrapper::create_dir_all("other");
+    create_symlink(dynamic_lib_name("foo"), "other");
+    rustc().input("bar.rs").library_search_path("other").run();
+}
diff --git a/tests/run-make/symlinked-rlib/Makefile b/tests/run-make/symlinked-rlib/Makefile
deleted file mode 100644
index a8565f683c3..00000000000
--- a/tests/run-make/symlinked-rlib/Makefile
+++ /dev/null
@@ -1,10 +0,0 @@
-# ignore-cross-compile
-include ../tools.mk
-
-# ignore-windows
-# `ln` is actually `cp` on msys.
-
-all:
-	$(RUSTC) foo.rs --crate-type=rlib -o $(TMPDIR)/foo.xxx
-	ln -nsf $(TMPDIR)/foo.xxx $(TMPDIR)/libfoo.rlib
-	$(RUSTC) bar.rs -L $(TMPDIR)
diff --git a/tests/run-make/symlinked-rlib/rmake.rs b/tests/run-make/symlinked-rlib/rmake.rs
new file mode 100644
index 00000000000..3759ca25928
--- /dev/null
+++ b/tests/run-make/symlinked-rlib/rmake.rs
@@ -0,0 +1,16 @@
+// Rustc did not recognize libraries which were symlinked
+// to files having extension other than .rlib. This was fixed
+// in #32828. This test creates a symlink to "foo.xxx", which has
+// an unusual file extension, and checks that rustc can successfully
+// use it as an rlib library.
+// See https://github.com/rust-lang/rust/pull/32828
+
+//@ ignore-cross-compile
+
+use run_make_support::{create_symlink, cwd, rustc};
+
+fn main() {
+    rustc().input("foo.rs").crate_type("rlib").output("foo.xxx").run();
+    create_symlink("foo.xxx", "libfoo.rlib");
+    rustc().input("bar.rs").library_search_path(cwd()).run();
+}