Skip to content

Commit

Permalink
port symlinked-extern to rmake
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneirical committed Jun 12, 2024
1 parent bbe9a9c commit 80408e0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
23 changes: 21 additions & 2 deletions src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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.
Expand Down Expand Up @@ -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.
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 @@ -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
Expand Down
25 changes: 25 additions & 0 deletions tests/run-make/symlinked-extern/rmake.rs
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit 80408e0

Please sign in to comment.