Skip to content

Commit

Permalink
Auto merge of rust-lang#128245 - Oneirical:total-linkage-ownage, r=<try>
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Jul 30, 2024
2 parents f8060d2 + 648ce51 commit c34ae38
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ pub use artifact_names::{

/// Path-related helpers.
pub use path_helpers::{
cwd, filename_not_in_denylist, has_extension, has_prefix, has_suffix, not_contains, path,
shallow_find_files, source_root,
cwd, filename_not_in_denylist, has_extension, has_prefix, has_suffix, name_contains,
not_contains, path, shallow_find_files, source_root,
};

/// Helpers for scoped test execution where certain properties are attempted to be maintained.
Expand Down
8 changes: 7 additions & 1 deletion src/tools/run-make-support/src/path_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::path::{Path, PathBuf};

use crate::env::env_var;
use crate::rfs;

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

Expand Down Expand Up @@ -78,3 +79,8 @@ pub fn has_extension<P: AsRef<Path>>(path: P, extension: &str) -> bool {
pub fn has_suffix<P: AsRef<Path>>(path: P, suffix: &str) -> bool {
path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().ends_with(suffix))
}

/// Returns true if the filename at `path` contains `needle`.
pub fn name_contains<P: AsRef<Path>>(path: P, needle: &str) -> bool {
path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().contains(needle))
}
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
@@ -1,6 +1,5 @@
run-make/branch-protection-check-IBT/Makefile
run-make/cat-and-grep-sanity-check/Makefile
run-make/cdylib-dylib-linkage/Makefile
run-make/cross-lang-lto-clang/Makefile
run-make/cross-lang-lto-pgo-smoketest/Makefile
run-make/cross-lang-lto-upstream-rlibs/Makefile
Expand Down
31 changes: 0 additions & 31 deletions tests/run-make/cdylib-dylib-linkage/Makefile

This file was deleted.

40 changes: 40 additions & 0 deletions tests/run-make/cdylib-dylib-linkage/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Previously, rustc mandated that cdylibs could only link against rlibs as dependencies,
// making linkage between cdylibs and dylibs impossible. After this was changed in #68448,
// this test attempts to link both `foo` (a cdylib) and `bar` (a dylib) and checks that
// both compilation and execution are successful.
// See https:/rust-lang/rust/pull/68448

//@ ignore-cross-compile
// Reason: the compiled binary is executed

use run_make_support::{
bin_name, cc, dynamic_lib_name, has_extension, has_prefix, has_suffix, is_msvc, name_contains,
path, run, rustc, shallow_find_files, target,
};

fn main() {
rustc().arg("-Cprefer-dynamic").input("bar.rs").run();
rustc().input("foo.rs").run();
let sysroot = rustc().print("sysroot").run().stdout_utf8();
let sysroot = sysroot.trim();
let target_sysroot = path(sysroot).join("lib/rustlib").join(target()).join("lib");
if is_msvc() {
let mut libs = shallow_find_files(&target_sysroot, |path| {
has_prefix(path, "libstd-") && has_suffix(path, ".dll.lib")
});
libs.push(path("foo.dll.lib"));
libs.push(path("bar.dll.lib"));
cc().input("foo.c").args(&libs).out_exe("foo").run();
} else {
let stdlibs = shallow_find_files(&target_sysroot, |path| {
!has_extension(path, "rlib") && name_contains(path, "std")
});
cc().input("foo.c")
.args(&[dynamic_lib_name("foo"), dynamic_lib_name("bar")])
.arg(stdlibs.get(0).unwrap())
.library_search_path(&target_sysroot)
.output(bin_name("foo"))
.run();
}
run("foo");
}

0 comments on commit c34ae38

Please sign in to comment.