Skip to content

Commit c34ae38

Browse files
committed
Auto merge of rust-lang#128245 - Oneirical:total-linkage-ownage, r=<try>
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 f8060d2 + 648ce51 commit c34ae38

File tree

5 files changed

+49
-35
lines changed

5 files changed

+49
-35
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ pub use artifact_names::{
7676

7777
/// Path-related helpers.
7878
pub use path_helpers::{
79-
cwd, filename_not_in_denylist, has_extension, has_prefix, has_suffix, not_contains, path,
80-
shallow_find_files, source_root,
79+
cwd, filename_not_in_denylist, has_extension, has_prefix, has_suffix, name_contains,
80+
not_contains, path, shallow_find_files, source_root,
8181
};
8282

8383
/// 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 name_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-clang/Makefile
54
run-make/cross-lang-lto-pgo-smoketest/Makefile
65
run-make/cross-lang-lto-upstream-rlibs/Makefile

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

-31
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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_name, has_extension, has_prefix, has_suffix, is_msvc, name_contains,
12+
path, run, rustc, shallow_find_files, target,
13+
};
14+
15+
fn main() {
16+
rustc().arg("-Cprefer-dynamic").input("bar.rs").run();
17+
rustc().input("foo.rs").run();
18+
let sysroot = rustc().print("sysroot").run().stdout_utf8();
19+
let sysroot = sysroot.trim();
20+
let target_sysroot = path(sysroot).join("lib/rustlib").join(target()).join("lib");
21+
if is_msvc() {
22+
let mut libs = shallow_find_files(&target_sysroot, |path| {
23+
has_prefix(path, "libstd-") && has_suffix(path, ".dll.lib")
24+
});
25+
libs.push(path("foo.dll.lib"));
26+
libs.push(path("bar.dll.lib"));
27+
cc().input("foo.c").args(&libs).out_exe("foo").run();
28+
} else {
29+
let stdlibs = shallow_find_files(&target_sysroot, |path| {
30+
!has_extension(path, "rlib") && name_contains(path, "std")
31+
});
32+
cc().input("foo.c")
33+
.args(&[dynamic_lib_name("foo"), dynamic_lib_name("bar")])
34+
.arg(stdlibs.get(0).unwrap())
35+
.library_search_path(&target_sysroot)
36+
.output(bin_name("foo"))
37+
.run();
38+
}
39+
run("foo");
40+
}

0 commit comments

Comments
 (0)