Skip to content

Commit 2ac5faa

Browse files
committed
port symlinked-libraries to rmake
1 parent 59acd23 commit 2ac5faa

File tree

6 files changed

+50
-42
lines changed

6 files changed

+50
-42
lines changed

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

+25-16
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,31 @@ pub fn source_root() -> PathBuf {
9494
}
9595

9696
/// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix.
97+
#[cfg(target_family = "windows")]
9798
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();
99+
if link.as_ref().exists() {
100+
std::fs::remove_dir(link.as_ref()).unwrap();
101+
}
102+
use std::os::windows::fs;
103+
fs::symlink_file(original.as_ref(), link.as_ref()).expect(&format!(
104+
"failed to create symlink {:?} for {:?}",
105+
link.as_ref().display(),
106+
original.as_ref().display(),
107+
));
108+
}
109+
110+
/// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix.
111+
#[cfg(target_family = "unix")]
112+
pub fn create_symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) {
113+
if link.as_ref().exists() {
114+
std::fs::remove_dir(link.as_ref()).unwrap();
104115
}
116+
use std::os::unix::fs;
117+
fs::symlink(original.as_ref(), link.as_ref()).expect(&format!(
118+
"failed to create symlink {:?} for {:?}",
119+
link.as_ref().display(),
120+
original.as_ref().display(),
121+
));
105122
}
106123

107124
/// Construct the static library name based on the platform.
@@ -125,11 +142,7 @@ pub fn static_lib_name(name: &str) -> String {
125142
// ```
126143
assert!(!name.contains(char::is_whitespace), "static library name cannot contain whitespace");
127144

128-
if is_msvc() {
129-
format!("{name}.lib")
130-
} else {
131-
format!("lib{name}.a")
132-
}
145+
if is_msvc() { format!("{name}.lib") } else { format!("lib{name}.a") }
133146
}
134147

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

177190
/// Construct the binary name based on platform.
178191
pub fn bin_name(name: &str) -> String {
179-
if is_windows() {
180-
format!("{name}.exe")
181-
} else {
182-
name.to_string()
183-
}
192+
if is_windows() { format!("{name}.exe") } else { name.to_string() }
184193
}
185194

186195
/// Return the current working directory.

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
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-libraries/Makefile
232231
run-make/sysroot-crates-are-unstable/Makefile
233232
run-make/target-cpu-native/Makefile
234233
run-make/target-specs/Makefile

tests/run-make/symlinked-extern/rmake.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,12 @@
1010

1111
//@ ignore-cross-compile
1212

13-
use run_make_support::{create_symlink, rustc, tmp_dir};
14-
use std::fs;
13+
use run_make_support::{create_symlink, cwd, fs_wrapper, rustc};
1514

1615
fn main() {
1716
rustc().input("foo.rs").run();
18-
fs::create_dir_all(tmp_dir().join("other")).unwrap();
19-
create_symlink(tmp_dir().join("libfoo.rlib"), tmp_dir().join("other"));
20-
rustc().input("bar.rs").library_search_path(tmp_dir()).run();
21-
rustc()
22-
.input("baz.rs")
23-
.extern_("foo", tmp_dir().join("other/libfoo.rlib"))
24-
.library_search_path(tmp_dir())
25-
.run();
17+
fs_wrapper::create_dir_all("other");
18+
create_symlink("libfoo.rlib", "other");
19+
rustc().input("bar.rs").library_search_path(cwd()).run();
20+
rustc().input("baz.rs").extern_("foo", "other").library_search_path(cwd()).run();
2621
}

tests/run-make/symlinked-libraries/Makefile

-11
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// When a directory and a symlink simultaneously exist with the same name,
2+
// setting that name as the library search path should not cause rustc
3+
// to avoid looking in the symlink and cause an error. This test creates
4+
// a directory and a symlink named "other", and places the library in the symlink.
5+
// If it succeeds, the library was successfully found.
6+
// See https://github.com/rust-lang/rust/issues/12459
7+
8+
//@ ignore-cross-compile
9+
use run_make_support::{create_symlink, dynamic_lib_name, fs_wrapper, rustc};
10+
11+
fn main() {
12+
rustc().input("foo.rs").arg("-Cprefer-dynamic").run();
13+
fs_wrapper::create_dir_all("other");
14+
create_symlink(dynamic_lib_name("foo"), "other");
15+
rustc().input("bar.rs").library_search_path("other").run();
16+
}

tests/run-make/symlinked-rlib/rmake.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
//@ ignore-cross-compile
99

10-
use run_make_support::{create_symlink, rustc, tmp_dir};
10+
use run_make_support::{create_symlink, cwd, rustc};
1111

1212
fn main() {
13-
rustc().input("foo.rs").crate_type("rlib").output(tmp_dir().join("foo.xxx")).run();
14-
create_symlink(tmp_dir().join("foo.xxx"), tmp_dir().join("libfoo.rlib"));
15-
rustc().input("bar.rs").library_search_path(tmp_dir());
13+
rustc().input("foo.rs").crate_type("rlib").output("foo.xxx").run();
14+
create_symlink("foo.xxx", "libfoo.rlib");
15+
rustc().input("bar.rs").library_search_path(cwd()).run();
1616
}

0 commit comments

Comments
 (0)