Skip to content

Commit 27aea78

Browse files
committed
port symlinked-extern to rmake
1 parent f989d2f commit 27aea78

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
@@ -76,6 +76,17 @@ pub fn source_path() -> PathBuf {
7676
std::env::var("S").expect("S variable does not exist").into()
7777
}
7878

79+
/// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix.
80+
pub fn create_symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) {
81+
if is_windows() {
82+
use std::os::windows::fs;
83+
fs::symlink_file(original, link).unwrap();
84+
} else {
85+
use std::os::unix::fs;
86+
fs::symlink(original, link).unwrap();
87+
}
88+
}
89+
7990
/// Construct the static library name based on the platform.
8091
pub fn static_lib_name(name: &str) -> String {
8192
// See tools.mk (irrelevant lines omitted):
@@ -97,7 +108,11 @@ pub fn static_lib_name(name: &str) -> String {
97108
// ```
98109
assert!(!name.contains(char::is_whitespace), "static library name cannot contain whitespace");
99110

100-
if is_msvc() { format!("{name}.lib") } else { format!("lib{name}.a") }
111+
if is_msvc() {
112+
format!("{name}.lib")
113+
} else {
114+
format!("lib{name}.a")
115+
}
101116
}
102117

103118
/// Construct a path to a dynamic library under `$TMPDIR` given the library name. This will return a
@@ -140,7 +155,11 @@ pub fn rust_lib(name: &str) -> PathBuf {
140155

141156
/// Construct the binary name based on platform.
142157
pub fn bin_name(name: &str) -> String {
143-
if is_windows() { format!("{name}.exe") } else { name.to_string() }
158+
if is_windows() {
159+
format!("{name}.exe")
160+
} else {
161+
name.to_string()
162+
}
144163
}
145164

146165
/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is

src/tools/tidy/src/allowed_run_make_makefiles.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ run-make/suspicious-library/Makefile
252252
run-make/symbol-mangling-hashed/Makefile
253253
run-make/symbol-visibility/Makefile
254254
run-make/symbols-include-type-name/Makefile
255-
run-make/symlinked-extern/Makefile
256255
run-make/symlinked-libraries/Makefile
257256
run-make/symlinked-rlib/Makefile
258257
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)