Skip to content

Commit 1236ff3

Browse files
committed
Port issue-11908 to rmake
1 parent 8387315 commit 1236ff3

File tree

7 files changed

+77
-35
lines changed

7 files changed

+77
-35
lines changed

src/tools/run-make-support/src/lib.rs

+47-4
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,17 @@ pub fn target() -> String {
4040

4141
/// Check if target is windows-like.
4242
pub fn is_windows() -> bool {
43-
env::var_os("IS_WINDOWS").is_some()
43+
target().contains("windows")
4444
}
4545

4646
/// Check if target uses msvc.
4747
pub fn is_msvc() -> bool {
48-
env::var_os("IS_MSVC").is_some()
48+
target().contains("msvc")
49+
}
50+
51+
/// Check if target uses macOS.
52+
pub fn is_darwin() -> bool {
53+
target().contains("darwin")
4954
}
5055

5156
/// 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 {
8287
// endif
8388
// endif
8489
// ```
85-
assert!(!name.contains(char::is_whitespace), "name cannot contain whitespace");
90+
assert!(!name.contains(char::is_whitespace), "static library name cannot contain whitespace");
91+
92+
if is_msvc() { format!("{name}.lib") } else { format!("lib{name}.a") }
93+
}
94+
95+
/// Construct a path to a dynamic library under `$TMPDIR` given the library name. This will return a
96+
/// path with `$TMPDIR` joined with platform-and-compiler-specific library name.
97+
pub fn dynamic_lib(name: &str) -> PathBuf {
98+
tmp_dir().join(dynamic_lib_name(name))
99+
}
100+
101+
/// Construct the dynamic library name based on the platform.
102+
pub fn dynamic_lib_name(name: &str) -> String {
103+
// See tools.mk (irrelevant lines omitted):
104+
//
105+
// ```makefile
106+
// ifeq ($(UNAME),Darwin)
107+
// DYLIB = $(TMPDIR)/lib$(1).dylib
108+
// else
109+
// ifdef IS_WINDOWS
110+
// DYLIB = $(TMPDIR)/$(1).dll
111+
// else
112+
// DYLIB = $(TMPDIR)/lib$(1).so
113+
// endif
114+
// endif
115+
// ```
116+
assert!(!name.contains(char::is_whitespace), "dynamic library name cannot contain whitespace");
117+
118+
if is_darwin() {
119+
format!("lib{name}.dylib")
120+
} else if is_windows() {
121+
format!("{name}.dll")
122+
} else {
123+
format!("lib{name}.so")
124+
}
125+
}
86126

87-
if target().contains("msvc") { format!("{name}.lib") } else { format!("lib{name}.a") }
127+
/// Construct a path to a rust library (rlib) under `$TMPDIR` given the library name. This will return a
128+
/// path with `$TMPDIR` joined with the library name.
129+
pub fn rust_lib(name: &str) -> PathBuf {
130+
tmp_dir().join(format!("lib{name}.rlib"))
88131
}
89132

90133
/// Construct the binary name based on platform.

src/tools/run-make-support/src/rustc.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl Rustc {
9191
self
9292
}
9393

94-
/// Specify path to the output file.
94+
/// Specify path to the output file. Equivalent to `-o`` in rustc.
9595
pub fn output<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
9696
self.cmd.arg("-o");
9797
self.cmd.arg(path.as_ref());
@@ -150,13 +150,7 @@ impl Rustc {
150150
self
151151
}
152152

153-
/// Enables link time optimizations in rustc. Equivalent to `-Clto``.
154-
pub fn lto(&mut self) -> &mut Self {
155-
self.cmd.arg("-Clto");
156-
self
157-
}
158-
159-
/// Add a directory to the library search path.
153+
/// Add a directory to the library search path. Equivalent to `-L`` in rustc.
160154
pub fn library_search_path<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
161155
self.cmd.arg("-L");
162156
self.cmd.arg(path.as_ref());

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ run-make/invalid-staticlib/Makefile
9494
run-make/issue-107094/Makefile
9595
run-make/issue-10971-temps-dir/Makefile
9696
run-make/issue-109934-lto-debuginfo/Makefile
97-
run-make/issue-11908/Makefile
9897
run-make/issue-14698/Makefile
9998
run-make/issue-15460/Makefile
10099
run-make/issue-18943/Makefile

tests/run-make/issue-11908/Makefile

-22
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// A path which contains the same rlib or dylib in two locations
2+
// should not cause an assertion panic in the compiler.
3+
// This test tries to replicate the linked issue and checks
4+
// if the bugged error makes a resurgence.
5+
6+
// See https://github.com/rust-lang/rust/issues/11908
7+
8+
//@ ignore-cross-compile
9+
10+
use run_make_support::{dynamic_lib, rust_lib, rustc, tmp_dir};
11+
use std::fs;
12+
13+
fn main() {
14+
let tmp_dir_other = tmp_dir().join("other");
15+
16+
fs::create_dir(&tmp_dir_other);
17+
rustc().input("foo.rs").crate_type("dylib").arg("-Cprefer-dynamic").run();
18+
fs::rename(dynamic_lib("foo"), &tmp_dir_other);
19+
rustc().input("foo.rs").crate_type("dylib").arg("-Cprefer-dynamic").run();
20+
rustc().input("bar.rs").library_search_path(&tmp_dir_other).run();
21+
fs::remove_dir_all(tmp_dir());
22+
23+
fs::create_dir_all(&tmp_dir_other);
24+
rustc().input("foo.rs").crate_type("rlib").run();
25+
fs::rename(rust_lib("foo"), &tmp_dir_other);
26+
rustc().input("foo.rs").crate_type("rlib").run();
27+
rustc().input("bar.rs").library_search_path(tmp_dir_other).run();
28+
}

0 commit comments

Comments
 (0)