Skip to content

Commit 3c6d739

Browse files
committed
rewrite cdylib-dylib-linkage to rmake
1 parent 2d5a628 commit 3c6d739

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,7 +1,6 @@
11
run-make/branch-protection-check-IBT/Makefile
22
run-make/c-unwind-abi-catch-lib-panic/Makefile
33
run-make/cat-and-grep-sanity-check/Makefile
4-
run-make/cdylib-dylib-linkage/Makefile
54
run-make/cross-lang-lto-clang/Makefile
65
run-make/cross-lang-lto-pgo-smoketest/Makefile
76
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_extension, dynamic_lib_name, has_extension, has_prefix, has_suffix,
12+
is_msvc, name_contains, 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, dynamic_lib_extension()) && 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)