Skip to content

Commit 60d1465

Browse files
committed
Auto merge of rust-lang#128245 - Oneirical:total-linkage-ownage, r=jieyouxu
Migrate `cdylib-dylib-linkage` `run-make` test to rmake Part of rust-lang#121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html). ~~Those sysroot tests are always fun. I'm getting local errors that don't make a lot of sense about my own sysroot not existing, so I am trying this in CI to see what happens.~~ ~~EDIT: I am getting the same error here. The strange thing is, when I try to navigate to `/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib` on my personal computer, the directory does exist, but the error message is that the directory does not.~~ EDIT 2: The sysroot path just needed to be trimmed! Please try: // try-job: x86_64-msvc // passed previously try-job: x86_64-mingw try-job: x86_64-gnu-llvm-18 try-job: i686-msvc try-job: aarch64-apple
2 parents 93ea767 + 20332da commit 60d1465

File tree

6 files changed

+63
-36
lines changed

6 files changed

+63
-36
lines changed

src/tools/run-make-support/src/artifact_names.rs

+11
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ pub fn dynamic_lib_name(name: &str) -> String {
3838
format!("{}{name}.{}", std::env::consts::DLL_PREFIX, std::env::consts::DLL_EXTENSION)
3939
}
4040

41+
/// Construct the name of the import library for the dynamic library, exclusive to MSVC and
42+
/// accepted by link.exe.
43+
#[track_caller]
44+
#[must_use]
45+
pub fn msvc_import_dynamic_lib_name(name: &str) -> String {
46+
assert!(is_msvc(), "this function is exclusive to MSVC");
47+
assert!(!name.contains(char::is_whitespace), "import library name cannot contain whitespace");
48+
49+
format!("{name}.dll.lib")
50+
}
51+
4152
/// Construct the dynamic library extension based on the target.
4253
#[must_use]
4354
pub fn dynamic_lib_extension() -> &'static str {

src/tools/run-make-support/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,14 @@ pub use targets::{is_darwin, is_msvc, is_windows, llvm_components_contain, targe
7272

7373
/// Helpers for building names of output artifacts that are potentially target-specific.
7474
pub use artifact_names::{
75-
bin_name, dynamic_lib_extension, dynamic_lib_name, rust_lib_name, static_lib_name,
75+
bin_name, dynamic_lib_extension, dynamic_lib_name, msvc_import_dynamic_lib_name, rust_lib_name,
76+
static_lib_name,
7677
};
7778

7879
/// Path-related helpers.
7980
pub use path_helpers::{
80-
cwd, filename_not_in_denylist, has_extension, has_prefix, has_suffix, not_contains, path,
81-
shallow_find_files, source_root,
81+
cwd, filename_contains, filename_not_in_denylist, has_extension, has_prefix, has_suffix,
82+
not_contains, path, shallow_find_files, source_root,
8283
};
8384

8485
/// Helpers for scoped test execution where certain properties are attempted to be maintained.

src/tools/run-make-support/src/path_helpers.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use std::path::{Path, PathBuf};
44

55
use crate::env::env_var;
6+
use crate::rfs;
67

78
/// Return the current working directory.
89
///
@@ -40,7 +41,7 @@ pub fn shallow_find_files<P: AsRef<Path>, F: Fn(&PathBuf) -> bool>(
4041
filter: F,
4142
) -> Vec<PathBuf> {
4243
let mut matching_files = Vec::new();
43-
for entry in std::fs::read_dir(path).unwrap() {
44+
for entry in rfs::read_dir(path) {
4445
let entry = entry.expect("failed to read directory entry.");
4546
let path = entry.path();
4647

@@ -78,3 +79,8 @@ pub fn has_extension<P: AsRef<Path>>(path: P, extension: &str) -> bool {
7879
pub fn has_suffix<P: AsRef<Path>>(path: P, suffix: &str) -> bool {
7980
path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().ends_with(suffix))
8081
}
82+
83+
/// Returns true if the filename at `path` contains `needle`.
84+
pub fn filename_contains<P: AsRef<Path>>(path: P, needle: &str) -> bool {
85+
path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().contains(needle))
86+
}

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
run-make/branch-protection-check-IBT/Makefile
22
run-make/cat-and-grep-sanity-check/Makefile
3-
run-make/cdylib-dylib-linkage/Makefile
43
run-make/cross-lang-lto-upstream-rlibs/Makefile
54
run-make/dep-info-doesnt-run-much/Makefile
65
run-make/dep-info-spaces/Makefile

tests/run-make/cdylib-dylib-linkage/Makefile

-31
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Previously, rustc mandated that cdylibs could only link against rlibs as dependencies,
2+
// making linkage between cdylibs and dylibs impossible. After this was changed in #68448,
3+
// this test attempts to link both `foo` (a cdylib) and `bar` (a dylib) and checks that
4+
// both compilation and execution are successful.
5+
// See https://github.com/rust-lang/rust/pull/68448
6+
7+
//@ ignore-cross-compile
8+
// Reason: the compiled binary is executed
9+
10+
use run_make_support::{
11+
bin_name, cc, dynamic_lib_extension, dynamic_lib_name, filename_contains, has_extension,
12+
has_prefix, has_suffix, is_msvc, msvc_import_dynamic_lib_name, path, run, rustc,
13+
shallow_find_files, target,
14+
};
15+
16+
fn main() {
17+
rustc().arg("-Cprefer-dynamic").input("bar.rs").run();
18+
rustc().input("foo.rs").run();
19+
let sysroot = rustc().print("sysroot").run().stdout_utf8();
20+
let sysroot = sysroot.trim();
21+
let target_sysroot = path(sysroot).join("lib/rustlib").join(target()).join("lib");
22+
if is_msvc() {
23+
let mut libs = shallow_find_files(&target_sysroot, |path| {
24+
has_prefix(path, "libstd-") && has_suffix(path, ".dll.lib")
25+
});
26+
libs.push(path(msvc_import_dynamic_lib_name("foo")));
27+
libs.push(path(msvc_import_dynamic_lib_name("bar")));
28+
cc().input("foo.c").args(&libs).out_exe("foo").run();
29+
} else {
30+
let stdlibs = shallow_find_files(&target_sysroot, |path| {
31+
has_extension(path, dynamic_lib_extension()) && filename_contains(path, "std")
32+
});
33+
cc().input("foo.c")
34+
.args(&[dynamic_lib_name("foo"), dynamic_lib_name("bar")])
35+
.arg(stdlibs.get(0).unwrap())
36+
.library_search_path(&target_sysroot)
37+
.output(bin_name("foo"))
38+
.run();
39+
}
40+
run("foo");
41+
}

0 commit comments

Comments
 (0)