Skip to content

Commit 80408e0

Browse files
committed
port symlinked-extern to rmake
1 parent bbe9a9c commit 80408e0

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ pub fn source_root() -> PathBuf {
9393
env_var("SOURCE_ROOT").into()
9494
}
9595

96+
/// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix.
97+
pub fn create_symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) {
98+
if is_windows() {
99+
use std::os::windows::fs;
100+
fs::symlink_file(original, link).unwrap();
101+
} else {
102+
use std::os::unix::fs;
103+
fs::symlink(original, link).unwrap();
104+
}
105+
}
106+
96107
/// Construct the static library name based on the platform.
97108
pub fn static_lib_name(name: &str) -> String {
98109
// See tools.mk (irrelevant lines omitted):
@@ -114,7 +125,11 @@ pub fn static_lib_name(name: &str) -> String {
114125
// ```
115126
assert!(!name.contains(char::is_whitespace), "static library name cannot contain whitespace");
116127

117-
if is_msvc() { format!("{name}.lib") } else { format!("lib{name}.a") }
128+
if is_msvc() {
129+
format!("{name}.lib")
130+
} else {
131+
format!("lib{name}.a")
132+
}
118133
}
119134

120135
/// Construct the dynamic library name based on the platform.
@@ -161,7 +176,11 @@ pub fn rust_lib_name(name: &str) -> String {
161176

162177
/// Construct the binary name based on platform.
163178
pub fn bin_name(name: &str) -> String {
164-
if is_windows() { format!("{name}.exe") } else { name.to_string() }
179+
if is_windows() {
180+
format!("{name}.exe")
181+
} else {
182+
name.to_string()
183+
}
165184
}
166185

167186
/// Return the current working directory.

src/tools/tidy/src/allowed_run_make_makefiles.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ run-make/std-core-cycle/Makefile
228228
run-make/symbol-mangling-hashed/Makefile
229229
run-make/symbol-visibility/Makefile
230230
run-make/symbols-include-type-name/Makefile
231-
run-make/symlinked-extern/Makefile
232231
run-make/symlinked-libraries/Makefile
233232
run-make/symlinked-rlib/Makefile
234233
run-make/sysroot-crates-are-unstable/Makefile
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Crates that are resolved normally have their path canonicalized and all
2+
// symlinks resolved. This did not happen for paths specified
3+
// using the --extern option to rustc, which could lead to rustc thinking
4+
// that it encountered two different versions of a crate, when it's
5+
// actually the same version found through different paths.
6+
7+
// This test checks that --extern and symlinks together
8+
// can result in successful compilation.
9+
10+
//@ ignore-cross-compile
11+
12+
use run_make_support::{create_symlink, rustc, tmp_dir};
13+
use std::fs;
14+
15+
fn main() {
16+
rustc().input("foo.rs").run();
17+
fs::create_dir_all(tmp_dir().join("other")).unwrap();
18+
create_symlink(tmp_dir().join("libfoo.rlib"), tmp_dir().join("other"));
19+
rustc().input("bar.rs").library_search_path(tmp_dir()).run();
20+
rustc()
21+
.input("baz.rs")
22+
.extern_("foo", tmp_dir().join("other/libfoo.rlib"))
23+
.library_search_path(tmp_dir())
24+
.run();
25+
}

0 commit comments

Comments
 (0)