Skip to content

Commit

Permalink
port symlinked-libraries to rmake
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneirical committed May 29, 2024
1 parent 5b4b92a commit 1b8d584
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 30 deletions.
31 changes: 14 additions & 17 deletions src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,19 @@ pub fn source_path() -> PathBuf {
}

/// 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) {
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();
}
use std::os::windows::fs;
fs::symlink_file(original, link)
.expect(&format!("failed to create symlink {} for {}", link, original));
}

/// 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) {
use std::os::unix::fs;
fs::symlink(original, link)
.expect(&format!("failed to create symlink {} for {}", link, original));
}

/// Construct the static library name based on the platform.
Expand All @@ -108,11 +113,7 @@ 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 a path to a dynamic library under `$TMPDIR` given the library name. This will return a
Expand Down Expand Up @@ -155,11 +156,7 @@ pub fn rust_lib(name: &str) -> PathBuf {

/// 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() }
}

/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
Expand Down
1 change: 0 additions & 1 deletion src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ run-make/suspicious-library/Makefile
run-make/symbol-mangling-hashed/Makefile
run-make/symbol-visibility/Makefile
run-make/symbols-include-type-name/Makefile
run-make/symlinked-libraries/Makefile
run-make/sysroot-crates-are-unstable/Makefile
run-make/target-cpu-native/Makefile
run-make/target-specs/Makefile
Expand Down
11 changes: 0 additions & 11 deletions tests/run-make/symlinked-libraries/Makefile

This file was deleted.

17 changes: 17 additions & 0 deletions tests/run-make/symlinked-libraries/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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, rustc, tmp_dir};
use std::fs;

fn main() {
rustc().input("foo.rs").arg("-Cprefer-dynamic").run();
fs::create_dir_all(tmp_dir().join("other")).unwrap();
create_symlink(dynamic_lib("foo"), tmp_dir().join("other"));
rustc().input("bar.rs").library_search_path(tmp_dir().join("other")).run();
}
2 changes: 1 addition & 1 deletion tests/run-make/symlinked-rlib/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ use run_make_support::{create_symlink, rustc, tmp_dir};
fn main() {
rustc().input("foo.rs").crate_type("rlib").output(tmp_dir().join("foo.xxx")).run();
create_symlink(tmp_dir().join("foo.xxx"), tmp_dir().join("libfoo.rlib"));
rustc().input("bar.rs").library_search_path(tmp_dir());
rustc().input("bar.rs").library_search_path(tmp_dir()).run();
}

0 comments on commit 1b8d584

Please sign in to comment.