Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 274423a

Browse files
committedJun 12, 2024
Auto merge of #125674 - Oneirical:another-day-another-test, r=<try>
Rewrite `symlinked-extern`, `symlinked-rlib` and `symlinked-libraries` `run-make` tests in `rmake.rs` format Part of #121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html). try-job: x86_64-msvc
2 parents c25ac9d + 2ac5faa commit 274423a

File tree

8 files changed

+81
-36
lines changed

8 files changed

+81
-36
lines changed
 

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

+28
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,34 @@ 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+
#[cfg(target_family = "windows")]
98+
pub fn create_symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) {
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();
115+
}
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+
));
122+
}
123+
96124
/// Construct the static library name based on the platform.
97125
pub fn static_lib_name(name: &str) -> String {
98126
// See tools.mk (irrelevant lines omitted):

‎src/tools/tidy/src/allowed_run_make_makefiles.txt

-3
Original file line numberDiff line numberDiff line change
@@ -228,9 +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
232-
run-make/symlinked-libraries/Makefile
233-
run-make/symlinked-rlib/Makefile
234231
run-make/sysroot-crates-are-unstable/Makefile
235232
run-make/target-cpu-native/Makefile
236233
run-make/target-specs/Makefile

‎tests/run-make/symlinked-extern/Makefile

-12
This file was deleted.
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
// See https://github.com/rust-lang/rust/pull/16505
7+
8+
// This test checks that --extern and symlinks together
9+
// can result in successful compilation.
10+
11+
//@ ignore-cross-compile
12+
13+
use run_make_support::{create_symlink, cwd, fs_wrapper, rustc};
14+
15+
fn main() {
16+
rustc().input("foo.rs").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();
21+
}

‎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/Makefile

-10
This file was deleted.
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Rustc did not recognize libraries which were symlinked
2+
// to files having extension other than .rlib. This was fixed
3+
// in #32828. This test creates a symlink to "foo.xxx", which has
4+
// an unusual file extension, and checks that rustc can successfully
5+
// use it as an rlib library.
6+
// See https://github.com/rust-lang/rust/pull/32828
7+
8+
//@ ignore-cross-compile
9+
10+
use run_make_support::{create_symlink, cwd, rustc};
11+
12+
fn main() {
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();
16+
}

0 commit comments

Comments
 (0)
Please sign in to comment.