about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-05-15 02:10:09 +0000
committerbors <bors@rust-lang.org>2024-05-15 02:10:09 +0000
commit9e7aff794539aa040362f4424eb29207449ffce0 (patch)
tree33c5c92bb90d67a5c70dbdd8d12f1f8e126093b2 /src
parent0160bff4b1bffa241299aba8c8c63e7a3cd871fe (diff)
parent81f7e54962efc456a630746e7b73d1a97188d5d8 (diff)
Auto merge of #125031 - Oneirical:dynamic-libs, r=jieyouxu
Migrate `run-make/issue-11908` to new `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).

Set as draft, because I have a few concerns:

- [x] I am not sure if `target().contains("darwin")` is a good way of checking that the target is on OSX.
- [x] I find it strange that the `dylib` part of the test adapts to different target platforms, but not the `rlib` part. Is `rlib` named the same on all platforms?
Diffstat (limited to 'src')
-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
3 files changed, 49 insertions, 13 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