port symlinked-extern to rmake

This commit is contained in:
Oneirical 2024-05-28 13:21:28 -04:00
parent bbe9a9c20b
commit 80408e0649
3 changed files with 46 additions and 3 deletions

View File

@ -93,6 +93,17 @@ pub fn source_root() -> PathBuf {
env_var("SOURCE_ROOT").into()
}
/// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix.
pub fn create_symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) {
if is_windows() {
use std::os::windows::fs;
fs::symlink_file(original, link).unwrap();
} else {
use std::os::unix::fs;
fs::symlink(original, link).unwrap();
}
}
/// Construct the static library name based on the platform.
pub fn static_lib_name(name: &str) -> String {
// See tools.mk (irrelevant lines omitted):
@ -114,7 +125,11 @@ pub fn static_lib_name(name: &str) -> String {
// ```
assert!(!name.contains(char::is_whitespace), "static library name cannot contain whitespace");
if is_msvc() { format!("{name}.lib") } else { format!("lib{name}.a") }
if is_msvc() {
format!("{name}.lib")
} else {
format!("lib{name}.a")
}
}
/// Construct the dynamic library name based on the platform.
@ -161,7 +176,11 @@ pub fn rust_lib_name(name: &str) -> String {
/// Construct the binary name based on platform.
pub fn bin_name(name: &str) -> String {
if is_windows() { format!("{name}.exe") } else { name.to_string() }
if is_windows() {
format!("{name}.exe")
} else {
name.to_string()
}
}
/// Return the current working directory.

View File

@ -228,7 +228,6 @@ run-make/std-core-cycle/Makefile
run-make/symbol-mangling-hashed/Makefile
run-make/symbol-visibility/Makefile
run-make/symbols-include-type-name/Makefile
run-make/symlinked-extern/Makefile
run-make/symlinked-libraries/Makefile
run-make/symlinked-rlib/Makefile
run-make/sysroot-crates-are-unstable/Makefile

View File

@ -0,0 +1,25 @@
// Crates that are resolved normally have their path canonicalized and all
// symlinks resolved. This did not happen for paths specified
// using the --extern option to rustc, which could lead to rustc thinking
// that it encountered two different versions of a crate, when it's
// actually the same version found through different paths.
// This test checks that --extern and symlinks together
// can result in successful compilation.
//@ ignore-cross-compile
use run_make_support::{create_symlink, rustc, tmp_dir};
use std::fs;
fn main() {
rustc().input("foo.rs").run();
fs::create_dir_all(tmp_dir().join("other")).unwrap();
create_symlink(tmp_dir().join("libfoo.rlib"), tmp_dir().join("other"));
rustc().input("bar.rs").library_search_path(tmp_dir()).run();
rustc()
.input("baz.rs")
.extern_("foo", tmp_dir().join("other/libfoo.rlib"))
.library_search_path(tmp_dir())
.run();
}