about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOneirical <manchot@videotron.ca>2024-05-11 19:34:19 -0400
committerOneirical <manchot@videotron.ca>2024-05-14 18:15:37 -0400
commit81f7e54962efc456a630746e7b73d1a97188d5d8 (patch)
treeabd5199e45ac7737b5c0aa7444c0fd92ee7d288d
parent8387315ab3c26a57a1f53a90f188f0bc88514bca (diff)
downloadrust-81f7e54962efc456a630746e7b73d1a97188d5d8.tar.gz
rust-81f7e54962efc456a630746e7b73d1a97188d5d8.zip
Port issue-11908 to rmake
-rw-r--r--src/tools/run-make-support/src/lib.rs51
-rw-r--r--src/tools/run-make-support/src/rustc.rs10
-rw-r--r--src/tools/tidy/src/allowed_run_make_makefiles.txt1
-rw-r--r--tests/run-make/issue-11908/Makefile22
-rw-r--r--tests/run-make/reachable-extern-fn-available-lto/rmake.rs4
-rw-r--r--tests/run-make/same-lib-two-locations-no-panic/bar.rs (renamed from tests/run-make/issue-11908/bar.rs)0
-rw-r--r--tests/run-make/same-lib-two-locations-no-panic/foo.rs (renamed from tests/run-make/issue-11908/foo.rs)0
-rw-r--r--tests/run-make/same-lib-two-locations-no-panic/rmake.rs28
8 files changed, 79 insertions, 37 deletions
diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs
index cc81d23a8ff..446afa1f82e 100644
--- a/src/tools/run-make-support/src/lib.rs
+++ b/src/tools/run-make-support/src/lib.rs
@@ -40,12 +40,17 @@ pub fn target() -> String {
 
 /// Check if target is windows-like.
 pub fn is_windows() -> bool {
-    env::var_os("IS_WINDOWS").is_some()
+    target().contains("windows")
 }
 
 /// Check if target uses msvc.
 pub fn is_msvc() -> bool {
-    env::var_os("IS_MSVC").is_some()
+    target().contains("msvc")
+}
+
+/// Check if target uses macOS.
+pub fn is_darwin() -> bool {
+    target().contains("darwin")
 }
 
 /// Construct a path to a static library under `$TMPDIR` given the library name. This will return a
@@ -82,9 +87,47 @@ pub fn static_lib_name(name: &str) -> String {
     //     endif
     // endif
     // ```
-    assert!(!name.contains(char::is_whitespace), "name cannot contain whitespace");
+    assert!(!name.contains(char::is_whitespace), "static library name cannot contain whitespace");
+
+    if is_msvc() { format!("{name}.lib") } else { format!("lib{name}.a") }
+}
+
+/// Construct a path to a dynamic library under `$TMPDIR` given the library name. This will return a
+/// path with `$TMPDIR` joined with platform-and-compiler-specific library name.
+pub fn dynamic_lib(name: &str) -> PathBuf {
+    tmp_dir().join(dynamic_lib_name(name))
+}
+
+/// Construct the dynamic library name based on the platform.
+pub fn dynamic_lib_name(name: &str) -> String {
+    // See tools.mk (irrelevant lines omitted):
+    //
+    // ```makefile
+    // ifeq ($(UNAME),Darwin)
+    //     DYLIB = $(TMPDIR)/lib$(1).dylib
+    // else
+    //     ifdef IS_WINDOWS
+    //         DYLIB = $(TMPDIR)/$(1).dll
+    //     else
+    //         DYLIB = $(TMPDIR)/lib$(1).so
+    //     endif
+    // endif
+    // ```
+    assert!(!name.contains(char::is_whitespace), "dynamic library name cannot contain whitespace");
+
+    if is_darwin() {
+        format!("lib{name}.dylib")
+    } else if is_windows() {
+        format!("{name}.dll")
+    } else {
+        format!("lib{name}.so")
+    }
+}
 
-    if target().contains("msvc") { format!("{name}.lib") } else { format!("lib{name}.a") }
+/// Construct a path to a rust library (rlib) under `$TMPDIR` given the library name. This will return a
+/// path with `$TMPDIR` joined with the library name.
+pub fn rust_lib(name: &str) -> PathBuf {
+    tmp_dir().join(format!("lib{name}.rlib"))
 }
 
 /// Construct the binary name based on platform.
diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs
index 7d239ff2e0a..d034826a830 100644
--- a/src/tools/run-make-support/src/rustc.rs
+++ b/src/tools/run-make-support/src/rustc.rs
@@ -91,7 +91,7 @@ impl Rustc {
         self
     }
 
-    /// Specify path to the output file.
+    /// Specify path to the output file. Equivalent to `-o`` in rustc.
     pub fn output<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
         self.cmd.arg("-o");
         self.cmd.arg(path.as_ref());
@@ -150,13 +150,7 @@ impl Rustc {
         self
     }
 
-    /// Enables link time optimizations in rustc. Equivalent to `-Clto``.
-    pub fn lto(&mut self) -> &mut Self {
-        self.cmd.arg("-Clto");
-        self
-    }
-
-    /// Add a directory to the library search path.
+    /// Add a directory to the library search path. Equivalent to `-L`` in rustc.
     pub fn library_search_path<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
         self.cmd.arg("-L");
         self.cmd.arg(path.as_ref());
diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt
index 5f68f779c4e..c2358eff617 100644
--- a/src/tools/tidy/src/allowed_run_make_makefiles.txt
+++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt
@@ -94,7 +94,6 @@ run-make/invalid-staticlib/Makefile
 run-make/issue-107094/Makefile
 run-make/issue-10971-temps-dir/Makefile
 run-make/issue-109934-lto-debuginfo/Makefile
-run-make/issue-11908/Makefile
 run-make/issue-14698/Makefile
 run-make/issue-15460/Makefile
 run-make/issue-18943/Makefile
diff --git a/tests/run-make/issue-11908/Makefile b/tests/run-make/issue-11908/Makefile
deleted file mode 100644
index 38586662fc7..00000000000
--- a/tests/run-make/issue-11908/Makefile
+++ /dev/null
@@ -1,22 +0,0 @@
-# ignore-cross-compile
-# This test ensures that if you have the same rlib or dylib at two locations
-# in the same path that you don't hit an assertion in the compiler.
-#
-# Note that this relies on `liburl` to be in the path somewhere else,
-# and then our aux-built libraries will collide with liburl (they have
-# the same version listed)
-
-include ../tools.mk
-
-all:
-	mkdir $(TMPDIR)/other
-	$(RUSTC) foo.rs --crate-type=dylib -C prefer-dynamic
-	mv $(call DYLIB,foo) $(TMPDIR)/other
-	$(RUSTC) foo.rs --crate-type=dylib -C prefer-dynamic
-	$(RUSTC) bar.rs -L $(TMPDIR)/other
-	rm -rf $(TMPDIR)
-	mkdir -p $(TMPDIR)/other
-	$(RUSTC) foo.rs --crate-type=rlib
-	mv $(TMPDIR)/libfoo.rlib $(TMPDIR)/other
-	$(RUSTC) foo.rs --crate-type=rlib
-	$(RUSTC) bar.rs -L $(TMPDIR)/other
diff --git a/tests/run-make/reachable-extern-fn-available-lto/rmake.rs b/tests/run-make/reachable-extern-fn-available-lto/rmake.rs
index 3e38b92b2b8..c7262b9461b 100644
--- a/tests/run-make/reachable-extern-fn-available-lto/rmake.rs
+++ b/tests/run-make/reachable-extern-fn-available-lto/rmake.rs
@@ -9,7 +9,7 @@
 
 //@ ignore-cross-compile
 
-use run_make_support::{cc, extra_c_flags, run, rustc, static_lib, tmp_dir};
+use run_make_support::{cc, extra_c_flags, run, rustc, static_lib};
 
 fn main() {
     let libbar_path = static_lib("bar");
@@ -17,7 +17,7 @@ fn main() {
     rustc()
         .input("bar.rs")
         .crate_type("staticlib")
-        .lto()
+        .arg("-Clto")
         .library_search_path(".")
         .output(&libbar_path)
         .run();
diff --git a/tests/run-make/issue-11908/bar.rs b/tests/run-make/same-lib-two-locations-no-panic/bar.rs
index bb7b36c496e..bb7b36c496e 100644
--- a/tests/run-make/issue-11908/bar.rs
+++ b/tests/run-make/same-lib-two-locations-no-panic/bar.rs
diff --git a/tests/run-make/issue-11908/foo.rs b/tests/run-make/same-lib-two-locations-no-panic/foo.rs
index 82b2dfe9fdb..82b2dfe9fdb 100644
--- a/tests/run-make/issue-11908/foo.rs
+++ b/tests/run-make/same-lib-two-locations-no-panic/foo.rs
diff --git a/tests/run-make/same-lib-two-locations-no-panic/rmake.rs b/tests/run-make/same-lib-two-locations-no-panic/rmake.rs
new file mode 100644
index 00000000000..2900c3c8b74
--- /dev/null
+++ b/tests/run-make/same-lib-two-locations-no-panic/rmake.rs
@@ -0,0 +1,28 @@
+// A path which contains the same rlib or dylib in two locations
+// should not cause an assertion panic in the compiler.
+// This test tries to replicate the linked issue and checks
+// if the bugged error makes a resurgence.
+
+// See https://github.com/rust-lang/rust/issues/11908
+
+//@ ignore-cross-compile
+
+use run_make_support::{dynamic_lib, rust_lib, rustc, tmp_dir};
+use std::fs;
+
+fn main() {
+    let tmp_dir_other = tmp_dir().join("other");
+
+    fs::create_dir(&tmp_dir_other);
+    rustc().input("foo.rs").crate_type("dylib").arg("-Cprefer-dynamic").run();
+    fs::rename(dynamic_lib("foo"), &tmp_dir_other);
+    rustc().input("foo.rs").crate_type("dylib").arg("-Cprefer-dynamic").run();
+    rustc().input("bar.rs").library_search_path(&tmp_dir_other).run();
+    fs::remove_dir_all(tmp_dir());
+
+    fs::create_dir_all(&tmp_dir_other);
+    rustc().input("foo.rs").crate_type("rlib").run();
+    fs::rename(rust_lib("foo"), &tmp_dir_other);
+    rustc().input("foo.rs").crate_type("rlib").run();
+    rustc().input("bar.rs").library_search_path(tmp_dir_other).run();
+}