Skip to content

Commit 436a333

Browse files
committed
Port issue-11908 to rmake
1 parent 8387315 commit 436a333

File tree

5 files changed

+82
-30
lines changed

5 files changed

+82
-30
lines changed

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,43 @@ pub fn static_lib_name(name: &str) -> String {
8282
// endif
8383
// endif
8484
// ```
85-
assert!(!name.contains(char::is_whitespace), "name cannot contain whitespace");
85+
assert!(!name.contains(char::is_whitespace), "static library name cannot contain whitespace");
8686

8787
if target().contains("msvc") { format!("{name}.lib") } else { format!("lib{name}.a") }
8888
}
8989

90+
/// Construct a path to a dynamic library under `$TMPDIR` given the library name. This will return a
91+
/// path with `$TMPDIR` joined with platform-and-compiler-specific library name.
92+
pub fn dynamic_lib(name: &str) -> PathBuf {
93+
tmp_dir().join(dynamic_lib_name(name))
94+
}
95+
96+
/// Construct the dynamic library name based on the platform.
97+
pub fn dynamic_lib_name(name: &str) -> String {
98+
// See tools.mk (irrelevant lines omitted):
99+
//
100+
// ```makefile
101+
// ifeq ($(UNAME),Darwin)
102+
// DYLIB = $(TMPDIR)/lib$(1).dylib
103+
// else
104+
// ifdef IS_WINDOWS
105+
// DYLIB = $(TMPDIR)/$(1).dll
106+
// else
107+
// DYLIB = $(TMPDIR)/lib$(1).so
108+
// endif
109+
// endif
110+
// ```
111+
assert!(!name.contains(char::is_whitespace), "dynamic library name cannot contain whitespace");
112+
113+
if target().contains("darwin") {
114+
format!("lib{name}.dylib")
115+
} else if target().contains("windows") {
116+
format!("{name}.dll")
117+
} else {
118+
format!("lib{name}.so")
119+
}
120+
}
121+
90122
/// Construct the binary name based on platform.
91123
pub fn bin_name(name: &str) -> String {
92124
if is_windows() { format!("{name}.exe") } else { name.to_string() }

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,6 @@ 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-
159153
/// Add a directory to the library search path.
160154
pub fn library_search_path<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
161155
self.cmd.arg("-L");

src/tools/tidy/src/allowed_run_make_makefiles.txt

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/run-make/issue-11908/rmake.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
// Note that this relies on `liburl` to be in the path somewhere else.
7+
// Our aux-built libraries will collide with liburl (they have
8+
// the same version listed)
9+
10+
// See https://github.com/rust-lang/rust/issues/11908
11+
12+
//@ ignore-cross-compile
13+
14+
use run_make_support::{rustc, dynamic_lib, tmp_dir};
15+
use std::fs;
16+
17+
fn main() {
18+
let mut tmp_dir_other = tmp_dir();
19+
tmp_dir_other.push("other");
20+
21+
fs::create_dir(tmp_dir_other);
22+
rustc().input("foo.rs")
23+
.crate_type("dylib")
24+
.codegen_option("prefer-dynamic")
25+
.run();
26+
fs::rename(dynamic_lib("foo"), tmp_dir_other);
27+
rustc().input("foo.rs")
28+
.crate_type("dylib")
29+
.codegen_option("prefer-dynamic")
30+
.run();
31+
rustc().input("bar.rs")
32+
.library_search_path(tmp_dir_other)
33+
.run();
34+
fs::remove_dir_all(tmp_dir());
35+
36+
fs::create_dir_all(tmp_dir_other);
37+
rustc().input("foo.rs")
38+
.crate_type("rlib")
39+
.run();
40+
let mut tmp_dir_libfoo = tmp_dir();
41+
tmp_dir_libfoo.push("libfoo.rlib");
42+
fs::rename(tmp_dir_libfoo, tmp_dir_other);
43+
rustc().input("foo.rs")
44+
.crate_type("rlib")
45+
.run();
46+
rustc().input("bar.rs")
47+
.library_search_path(tmp_dir_other)
48+
.run();
49+
}

0 commit comments

Comments
 (0)