port symlinked-libraries to rmake
This commit is contained in:
parent
59acd23457
commit
2ac5faa509
@ -94,14 +94,31 @@ pub fn source_root() -> PathBuf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix.
|
/// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix.
|
||||||
|
#[cfg(target_family = "windows")]
|
||||||
pub fn create_symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) {
|
pub fn create_symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) {
|
||||||
if is_windows() {
|
if link.as_ref().exists() {
|
||||||
use std::os::windows::fs;
|
std::fs::remove_dir(link.as_ref()).unwrap();
|
||||||
fs::symlink_file(original, link).unwrap();
|
|
||||||
} else {
|
|
||||||
use std::os::unix::fs;
|
|
||||||
fs::symlink(original, link).unwrap();
|
|
||||||
}
|
}
|
||||||
|
use std::os::windows::fs;
|
||||||
|
fs::symlink_file(original.as_ref(), link.as_ref()).expect(&format!(
|
||||||
|
"failed to create symlink {:?} for {:?}",
|
||||||
|
link.as_ref().display(),
|
||||||
|
original.as_ref().display(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix.
|
||||||
|
#[cfg(target_family = "unix")]
|
||||||
|
pub fn create_symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) {
|
||||||
|
if link.as_ref().exists() {
|
||||||
|
std::fs::remove_dir(link.as_ref()).unwrap();
|
||||||
|
}
|
||||||
|
use std::os::unix::fs;
|
||||||
|
fs::symlink(original.as_ref(), link.as_ref()).expect(&format!(
|
||||||
|
"failed to create symlink {:?} for {:?}",
|
||||||
|
link.as_ref().display(),
|
||||||
|
original.as_ref().display(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct the static library name based on the platform.
|
/// Construct the static library name based on the platform.
|
||||||
@ -125,11 +142,7 @@ pub fn static_lib_name(name: &str) -> String {
|
|||||||
// ```
|
// ```
|
||||||
assert!(!name.contains(char::is_whitespace), "static library name cannot contain whitespace");
|
assert!(!name.contains(char::is_whitespace), "static library name cannot contain whitespace");
|
||||||
|
|
||||||
if is_msvc() {
|
if is_msvc() { format!("{name}.lib") } else { format!("lib{name}.a") }
|
||||||
format!("{name}.lib")
|
|
||||||
} else {
|
|
||||||
format!("lib{name}.a")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct the dynamic library name based on the platform.
|
/// Construct the dynamic library name based on the platform.
|
||||||
@ -176,11 +189,7 @@ pub fn rust_lib_name(name: &str) -> String {
|
|||||||
|
|
||||||
/// Construct the binary name based on platform.
|
/// Construct the binary name based on platform.
|
||||||
pub fn bin_name(name: &str) -> String {
|
pub fn bin_name(name: &str) -> String {
|
||||||
if is_windows() {
|
if is_windows() { format!("{name}.exe") } else { name.to_string() }
|
||||||
format!("{name}.exe")
|
|
||||||
} else {
|
|
||||||
name.to_string()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the current working directory.
|
/// Return the current working directory.
|
||||||
|
@ -228,7 +228,6 @@ run-make/std-core-cycle/Makefile
|
|||||||
run-make/symbol-mangling-hashed/Makefile
|
run-make/symbol-mangling-hashed/Makefile
|
||||||
run-make/symbol-visibility/Makefile
|
run-make/symbol-visibility/Makefile
|
||||||
run-make/symbols-include-type-name/Makefile
|
run-make/symbols-include-type-name/Makefile
|
||||||
run-make/symlinked-libraries/Makefile
|
|
||||||
run-make/sysroot-crates-are-unstable/Makefile
|
run-make/sysroot-crates-are-unstable/Makefile
|
||||||
run-make/target-cpu-native/Makefile
|
run-make/target-cpu-native/Makefile
|
||||||
run-make/target-specs/Makefile
|
run-make/target-specs/Makefile
|
||||||
|
@ -10,17 +10,12 @@
|
|||||||
|
|
||||||
//@ ignore-cross-compile
|
//@ ignore-cross-compile
|
||||||
|
|
||||||
use run_make_support::{create_symlink, rustc, tmp_dir};
|
use run_make_support::{create_symlink, cwd, fs_wrapper, rustc};
|
||||||
use std::fs;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
rustc().input("foo.rs").run();
|
rustc().input("foo.rs").run();
|
||||||
fs::create_dir_all(tmp_dir().join("other")).unwrap();
|
fs_wrapper::create_dir_all("other");
|
||||||
create_symlink(tmp_dir().join("libfoo.rlib"), tmp_dir().join("other"));
|
create_symlink("libfoo.rlib", "other");
|
||||||
rustc().input("bar.rs").library_search_path(tmp_dir()).run();
|
rustc().input("bar.rs").library_search_path(cwd()).run();
|
||||||
rustc()
|
rustc().input("baz.rs").extern_("foo", "other").library_search_path(cwd()).run();
|
||||||
.input("baz.rs")
|
|
||||||
.extern_("foo", tmp_dir().join("other/libfoo.rlib"))
|
|
||||||
.library_search_path(tmp_dir())
|
|
||||||
.run();
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
# ignore-cross-compile
|
|
||||||
include ../tools.mk
|
|
||||||
|
|
||||||
# ignore-windows
|
|
||||||
# `ln` is actually `cp` on msys.
|
|
||||||
|
|
||||||
all:
|
|
||||||
$(RUSTC) foo.rs -C prefer-dynamic
|
|
||||||
mkdir -p $(TMPDIR)/other
|
|
||||||
ln -nsf $(TMPDIR)/$(call DYLIB_GLOB,foo) $(TMPDIR)/other
|
|
||||||
$(RUSTC) bar.rs -L $(TMPDIR)/other
|
|
16
tests/run-make/symlinked-libraries/rmake.rs
Normal file
16
tests/run-make/symlinked-libraries/rmake.rs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// When a directory and a symlink simultaneously exist with the same name,
|
||||||
|
// setting that name as the library search path should not cause rustc
|
||||||
|
// to avoid looking in the symlink and cause an error. This test creates
|
||||||
|
// a directory and a symlink named "other", and places the library in the symlink.
|
||||||
|
// If it succeeds, the library was successfully found.
|
||||||
|
// See https://github.com/rust-lang/rust/issues/12459
|
||||||
|
|
||||||
|
//@ ignore-cross-compile
|
||||||
|
use run_make_support::{create_symlink, dynamic_lib_name, fs_wrapper, rustc};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
rustc().input("foo.rs").arg("-Cprefer-dynamic").run();
|
||||||
|
fs_wrapper::create_dir_all("other");
|
||||||
|
create_symlink(dynamic_lib_name("foo"), "other");
|
||||||
|
rustc().input("bar.rs").library_search_path("other").run();
|
||||||
|
}
|
@ -7,10 +7,10 @@
|
|||||||
|
|
||||||
//@ ignore-cross-compile
|
//@ ignore-cross-compile
|
||||||
|
|
||||||
use run_make_support::{create_symlink, rustc, tmp_dir};
|
use run_make_support::{create_symlink, cwd, rustc};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
rustc().input("foo.rs").crate_type("rlib").output(tmp_dir().join("foo.xxx")).run();
|
rustc().input("foo.rs").crate_type("rlib").output("foo.xxx").run();
|
||||||
create_symlink(tmp_dir().join("foo.xxx"), tmp_dir().join("libfoo.rlib"));
|
create_symlink("foo.xxx", "libfoo.rlib");
|
||||||
rustc().input("bar.rs").library_search_path(tmp_dir());
|
rustc().input("bar.rs").library_search_path(cwd()).run();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user