diff options
| author | Oneirical <manchot@videotron.ca> | 2024-05-28 13:21:28 -0400 |
|---|---|---|
| committer | Oneirical <manchot@videotron.ca> | 2024-06-12 09:44:21 -0400 |
| commit | 80408e0649b29915ad5258367b67c70a91e6b043 (patch) | |
| tree | 7db3817a33ef5ab2f08d77d87aa562e7ae93f078 | |
| parent | bbe9a9c20bac888efae2c7f033fb6cb3925a65b7 (diff) | |
| download | rust-80408e0649b29915ad5258367b67c70a91e6b043.tar.gz rust-80408e0649b29915ad5258367b67c70a91e6b043.zip | |
port symlinked-extern to rmake
| -rw-r--r-- | src/tools/run-make-support/src/lib.rs | 23 | ||||
| -rw-r--r-- | src/tools/tidy/src/allowed_run_make_makefiles.txt | 1 | ||||
| -rw-r--r-- | tests/run-make/symlinked-extern/rmake.rs | 25 |
3 files changed, 46 insertions, 3 deletions
diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index b920f9a07db..d93a950d3e1 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -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. diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index ac89a30f353..4adfd52b2b3 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -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 diff --git a/tests/run-make/symlinked-extern/rmake.rs b/tests/run-make/symlinked-extern/rmake.rs new file mode 100644 index 00000000000..124f1cef849 --- /dev/null +++ b/tests/run-make/symlinked-extern/rmake.rs @@ -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(); +} |
