Use --print target-libdir in run-make tests

This makes the tests more robust against sysroot layout changes and
slightly simplifies them.
This commit is contained in:
bjorn3 2025-12-31 15:14:36 +00:00
parent 2848c2ebe9
commit 1a4e7f9aa9
4 changed files with 11 additions and 15 deletions

View file

@ -169,9 +169,8 @@ fn main() {
// Test that all binaries in rlibs produced by `rustc` have the same version.
// Regression test for https://github.com/rust-lang/rust/issues/128419.
let sysroot = rustc().print("sysroot").run().stdout_utf8();
let target_sysroot = path(sysroot.trim()).join("lib/rustlib").join(target()).join("lib");
let rlibs = shallow_find_files(&target_sysroot, |path| has_extension(path, "rlib"));
let sysroot_libs_dir = rustc().print("target-libdir").target(target()).run().stdout_utf8();
let rlibs = shallow_find_files(sysroot_libs_dir.trim(), |path| has_extension(path, "rlib"));
let output = cmd("otool").arg("-l").args(rlibs).run().stdout_utf8();
let re = regex::Regex::new(r"(minos|version) ([0-9.]*)").unwrap();

View file

@ -16,24 +16,23 @@ use run_make_support::{
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");
let sysroot_libs_dir = rustc().print("target-libdir").target(target()).run().stdout_utf8();
let sysroot_libs_dir = sysroot_libs_dir.trim();
if is_windows_msvc() {
let mut libs = shallow_find_files(&target_sysroot, |path| {
let mut libs = shallow_find_files(sysroot_libs_dir, |path| {
has_prefix(path, "libstd-") && has_suffix(path, ".dll.lib")
});
libs.push(path(msvc_import_dynamic_lib_name("foo")));
libs.push(path(msvc_import_dynamic_lib_name("bar")));
cc().input("foo.c").args(&libs).out_exe("foo").run();
} else {
let stdlibs = shallow_find_files(&target_sysroot, |path| {
let stdlibs = shallow_find_files(sysroot_libs_dir, |path| {
has_extension(path, dynamic_lib_extension()) && filename_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)
.library_search_path(sysroot_libs_dir)
.output(bin_name("foo"))
.run();
}

View file

@ -15,10 +15,8 @@ type SymbolTable<'data> = run_make_support::object::read::elf::SymbolTable<'data
fn main() {
// Find libstd-...rlib
let sysroot = rustc().print("sysroot").run().stdout_utf8();
let sysroot = sysroot.trim();
let target_sysroot = path(sysroot).join("lib/rustlib").join(target()).join("lib");
let mut libs = shallow_find_files(&target_sysroot, |path| {
let sysroot_libs_dir = rustc().print("target-libdir").target(target()).run().stdout_utf8();
let mut libs = shallow_find_files(sysroot_libs_dir.trim(), |path| {
has_prefix(path, "libstd-") && has_suffix(path, ".rlib")
});
assert_eq!(libs.len(), 1);

View file

@ -44,8 +44,8 @@ fn check_crate_is_unstable(cr: &Crate) {
}
fn get_unstable_sysroot_crates() -> Vec<Crate> {
let sysroot = PathBuf::from(rustc().print("sysroot").run().stdout_utf8().trim());
let sysroot_libs_dir = sysroot.join("lib").join("rustlib").join(target()).join("lib");
let sysroot_libs_dir =
PathBuf::from(rustc().print("target-libdir").target(target()).run().stdout_utf8().trim());
println!("Sysroot libs dir: {sysroot_libs_dir:?}");
// Generate a list of all library crates in the sysroot.