Skip to content

Commit 1a6e777

Browse files
committed
Auto merge of rust-lang#126208 - Oneirical:one-flew-over-the-cuckoo's-test, r=jieyouxu
Migrate `compiler-lookup-paths`, `dump-mono-stats` and `prune-link-args` `run-make` tests to `rmake` or `ui` format 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). try-job: x86_64-msvc try-job: aarch64-apple try-job: dist-x86_64-linux try-job: armhf-gnu
2 parents 7d356eb + ea2b699 commit 1a6e777

File tree

14 files changed

+206
-91
lines changed

14 files changed

+206
-91
lines changed

Cargo.lock

-7
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,6 @@ dependencies = [
228228
"backtrace",
229229
]
230230

231-
[[package]]
232-
name = "ar"
233-
version = "0.9.0"
234-
source = "registry+https://github.com./rust-lang/crates.io-index"
235-
checksum = "d67af77d68a931ecd5cbd8a3b5987d63a1d1d1278f7f6a60ae33db485cdebb69"
236-
237231
[[package]]
238232
name = "ar_archive_writer"
239233
version = "0.3.0"
@@ -3451,7 +3445,6 @@ dependencies = [
34513445
name = "run_make_support"
34523446
version = "0.2.0"
34533447
dependencies = [
3454-
"ar",
34553448
"bstr",
34563449
"build_helper",
34573450
"gimli 0.31.0",

src/tools/run-make-support/Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,4 @@ similar = "2.5.0"
1010
wasmparser = "0.118.2"
1111
regex = "1.8" # 1.8 to avoid memchr 2.6.0, as 2.5.0 is pinned in the workspace
1212
gimli = "0.31.0"
13-
ar = "0.9.0"
14-
1513
build_helper = { path = "../build_helper" }

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::Path;
22

33
use crate::command::Command;
4-
use crate::{bin_name, cygpath_windows, env_var, is_msvc, is_windows, uname};
4+
use crate::{cygpath_windows, env_var, is_msvc, is_windows, uname};
55

66
/// Construct a new platform-specific C compiler invocation.
77
///
@@ -68,9 +68,14 @@ impl Cc {
6868
// endif
6969
// ```
7070

71+
let mut path = std::path::PathBuf::from(name);
72+
7173
if is_msvc() {
72-
let fe_path = cygpath_windows(bin_name(name));
73-
let fo_path = cygpath_windows(format!("{name}.obj"));
74+
path.set_extension("exe");
75+
let fe_path = cygpath_windows(&path);
76+
path.set_extension("");
77+
path.set_extension("obj");
78+
let fo_path = cygpath_windows(path);
7479
self.cmd.arg(format!("-Fe:{fe_path}"));
7580
self.cmd.arg(format!("-Fo:{fo_path}"));
7681
} else {

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

+22-15
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc};
3030
pub use clang::{clang, Clang};
3131
pub use diff::{diff, Diff};
3232
pub use llvm::{
33-
llvm_filecheck, llvm_objdump, llvm_profdata, llvm_readobj, LlvmFilecheck, LlvmObjdump,
34-
LlvmProfdata, LlvmReadobj,
33+
llvm_ar, llvm_filecheck, llvm_objdump, llvm_profdata, llvm_readobj, LlvmAr, LlvmFilecheck,
34+
LlvmObjdump, LlvmProfdata, LlvmReadobj,
3535
};
3636
pub use run::{cmd, run, run_fail, run_with_args};
3737
pub use rustc::{aux_build, bare_rustc, rustc, Rustc};
@@ -61,19 +61,6 @@ pub fn target() -> String {
6161
env_var("TARGET")
6262
}
6363

64-
/// `AR`
65-
#[track_caller]
66-
pub fn ar(inputs: &[impl AsRef<Path>], output_path: impl AsRef<Path>) {
67-
let output = fs::File::create(&output_path).expect(&format!(
68-
"the file in path \"{}\" could not be created",
69-
output_path.as_ref().display()
70-
));
71-
let mut builder = ar::Builder::new(output);
72-
for input in inputs {
73-
builder.append_path(input).unwrap();
74-
}
75-
}
76-
7764
/// Check if target is windows-like.
7865
#[must_use]
7966
pub fn is_windows() -> bool {
@@ -294,6 +281,26 @@ pub fn not_contains<P: AsRef<Path>>(path: P, expected: &str) -> bool {
294281
!path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().contains(expected))
295282
}
296283

284+
/// Builds a static lib (`.lib` on Windows MSVC and `.a` for the rest) with the given name.
285+
#[track_caller]
286+
pub fn build_native_static_lib(lib_name: &str) -> PathBuf {
287+
let obj_file = if is_msvc() { format!("{lib_name}") } else { format!("{lib_name}.o") };
288+
let src = format!("{lib_name}.c");
289+
let lib_path = static_lib_name(lib_name);
290+
if is_msvc() {
291+
cc().arg("-c").out_exe(&obj_file).input(src).run();
292+
} else {
293+
cc().arg("-v").arg("-c").out_exe(&obj_file).input(src).run();
294+
};
295+
let obj_file = if is_msvc() {
296+
PathBuf::from(format!("{lib_name}.obj"))
297+
} else {
298+
PathBuf::from(format!("{lib_name}.o"))
299+
};
300+
llvm_ar().obj_to_ar().output_input(&lib_path, &obj_file).run();
301+
path(lib_path)
302+
}
303+
297304
/// Returns true if the filename at `path` is not in `expected`.
298305
pub fn filename_not_in_denylist<P: AsRef<Path>, V: AsRef<[String]>>(path: P, expected: V) -> bool {
299306
let expected = expected.as_ref();

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

+37
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ pub fn llvm_objdump() -> LlvmObjdump {
2929
LlvmObjdump::new()
3030
}
3131

32+
/// Construct a new `llvm-ar` invocation. This assumes that `llvm-ar` is available
33+
/// at `$LLVM_BIN_DIR/llvm-ar`.
34+
pub fn llvm_ar() -> LlvmAr {
35+
LlvmAr::new()
36+
}
37+
3238
/// A `llvm-readobj` invocation builder.
3339
#[derive(Debug)]
3440
#[must_use]
@@ -57,10 +63,18 @@ pub struct LlvmObjdump {
5763
cmd: Command,
5864
}
5965

66+
/// A `llvm-ar` invocation builder.
67+
#[derive(Debug)]
68+
#[must_use]
69+
pub struct LlvmAr {
70+
cmd: Command,
71+
}
72+
6073
crate::impl_common_helpers!(LlvmReadobj);
6174
crate::impl_common_helpers!(LlvmProfdata);
6275
crate::impl_common_helpers!(LlvmFilecheck);
6376
crate::impl_common_helpers!(LlvmObjdump);
77+
crate::impl_common_helpers!(LlvmAr);
6478

6579
/// Generate the path to the bin directory of LLVM.
6680
#[must_use]
@@ -204,3 +218,26 @@ impl LlvmObjdump {
204218
self
205219
}
206220
}
221+
222+
impl LlvmAr {
223+
/// Construct a new `llvm-ar` invocation. This assumes that `llvm-ar` is available
224+
/// at `$LLVM_BIN_DIR/llvm-ar`.
225+
pub fn new() -> Self {
226+
let llvm_ar = llvm_bin_dir().join("llvm-ar");
227+
let cmd = Command::new(llvm_ar);
228+
Self { cmd }
229+
}
230+
231+
pub fn obj_to_ar(&mut self) -> &mut Self {
232+
self.cmd.arg("rcus");
233+
self
234+
}
235+
236+
/// Provide an output, then an input file. Bundled in one function, as llvm-ar has
237+
/// no "--output"-style flag.
238+
pub fn output_input(&mut self, out: impl AsRef<Path>, input: impl AsRef<Path>) -> &mut Self {
239+
self.cmd.arg(out.as_ref());
240+
self.cmd.arg(input.as_ref());
241+
self
242+
}
243+
}

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

+13
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,19 @@ impl Rustc {
242242
self
243243
}
244244

245+
/// Add a directory to the library search path with a restriction, where `kind` is a dependency
246+
/// type. Equivalent to `-L KIND=PATH` in rustc.
247+
pub fn specific_library_search_path<P: AsRef<Path>>(
248+
&mut self,
249+
kind: &str,
250+
path: P,
251+
) -> &mut Self {
252+
assert!(["dependency", "native", "all", "framework", "crate"].contains(&kind));
253+
let path = path.as_ref().to_string_lossy();
254+
self.cmd.arg(format!("-L{kind}={path}"));
255+
self
256+
}
257+
245258
/// Override the system root. Equivalent to `--sysroot` in rustc.
246259
pub fn sysroot<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
247260
self.cmd.arg("--sysroot");

src/tools/tidy/src/allowed_run_make_makefiles.txt

-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ run-make/c-unwind-abi-catch-panic/Makefile
1010
run-make/cat-and-grep-sanity-check/Makefile
1111
run-make/cdylib-dylib-linkage/Makefile
1212
run-make/compiler-lookup-paths-2/Makefile
13-
run-make/compiler-lookup-paths/Makefile
1413
run-make/compiler-rt-works-on-mingw/Makefile
1514
run-make/crate-hash-rustc-version/Makefile
1615
run-make/cross-lang-lto-clang/Makefile
@@ -21,7 +20,6 @@ run-make/dep-info-doesnt-run-much/Makefile
2120
run-make/dep-info-spaces/Makefile
2221
run-make/dep-info/Makefile
2322
run-make/dump-ice-to-disk/Makefile
24-
run-make/dump-mono-stats/Makefile
2523
run-make/emit-to-stdout/Makefile
2624
run-make/export-executable-symbols/Makefile
2725
run-make/extern-diff-internal-name/Makefile
@@ -93,7 +91,6 @@ run-make/pgo-indirect-call-promotion/Makefile
9391
run-make/pointer-auth-link-with-c/Makefile
9492
run-make/print-calling-conventions/Makefile
9593
run-make/print-target-list/Makefile
96-
run-make/prune-link-args/Makefile
9794
run-make/raw-dylib-alt-calling-convention/Makefile
9895
run-make/raw-dylib-c/Makefile
9996
run-make/raw-dylib-import-name-type/Makefile

tests/run-make/compiler-lookup-paths/Makefile

-44
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Since #19941, rustc can accept specifications on its library search paths.
2+
// This test runs Rust programs with varied library dependencies, expecting them
3+
// to succeed or fail depending on the situation.
4+
// The second part of the tests also checks that libraries with an incorrect hash
5+
// fail to be used by the compiler.
6+
// See https://github.com./rust-lang/rust/pull/19941
7+
8+
//@ ignore-wasm32
9+
//@ ignore-wasm64
10+
// Reason: a C compiler is required for build_native_static_lib
11+
12+
use run_make_support::{build_native_static_lib, fs_wrapper, rustc, static_lib_name};
13+
14+
fn main() {
15+
build_native_static_lib("native");
16+
let lib_native = static_lib_name("native");
17+
fs_wrapper::create_dir_all("crate");
18+
fs_wrapper::create_dir_all("native");
19+
fs_wrapper::rename(&lib_native, format!("native/{}", &lib_native));
20+
rustc().input("a.rs").run();
21+
fs_wrapper::rename("liba.rlib", "crate/liba.rlib");
22+
rustc().input("b.rs").specific_library_search_path("native", "crate").run_fail();
23+
rustc().input("b.rs").specific_library_search_path("dependency", "crate").run_fail();
24+
rustc().input("b.rs").specific_library_search_path("crate", "crate").run();
25+
rustc().input("b.rs").specific_library_search_path("all", "crate").run();
26+
27+
rustc().input("c.rs").specific_library_search_path("native", "crate").run_fail();
28+
rustc().input("c.rs").specific_library_search_path("crate", "crate").run_fail();
29+
rustc().input("c.rs").specific_library_search_path("dependency", "crate").run();
30+
rustc().input("c.rs").specific_library_search_path("all", "crate").run();
31+
32+
rustc().input("d.rs").specific_library_search_path("dependency", "native").run_fail();
33+
rustc().input("d.rs").specific_library_search_path("crate", "native").run_fail();
34+
rustc().input("d.rs").specific_library_search_path("native", "native").run();
35+
rustc().input("d.rs").specific_library_search_path("all", "native").run();
36+
37+
// Deduplication tests.
38+
fs_wrapper::create_dir_all("e1");
39+
fs_wrapper::create_dir_all("e2");
40+
41+
rustc().input("e.rs").output("e1/libe.rlib").run();
42+
rustc().input("e.rs").output("e2/libe.rlib").run();
43+
// If the library hash is correct, compilation should succeed.
44+
rustc().input("f.rs").library_search_path("e1").library_search_path("e2").run();
45+
rustc()
46+
.input("f.rs")
47+
.specific_library_search_path("crate", "e1")
48+
.library_search_path("e2")
49+
.run();
50+
rustc()
51+
.input("f.rs")
52+
.specific_library_search_path("crate", "e1")
53+
.specific_library_search_path("crate", "e2")
54+
.run();
55+
// If the library has a different hash, errors should occur.
56+
rustc().input("e2.rs").output("e2/libe.rlib").run();
57+
rustc().input("f.rs").library_search_path("e1").library_search_path("e2").run_fail();
58+
rustc()
59+
.input("f.rs")
60+
.specific_library_search_path("crate", "e1")
61+
.library_search_path("e2")
62+
.run_fail();
63+
rustc()
64+
.input("f.rs")
65+
.specific_library_search_path("crate", "e1")
66+
.specific_library_search_path("crate", "e2")
67+
.run_fail();
68+
// Native and dependency paths do not cause errors.
69+
rustc()
70+
.input("f.rs")
71+
.specific_library_search_path("native", "e1")
72+
.library_search_path("e2")
73+
.run();
74+
rustc()
75+
.input("f.rs")
76+
.specific_library_search_path("dependency", "e1")
77+
.library_search_path("e2")
78+
.run();
79+
rustc()
80+
.input("f.rs")
81+
.specific_library_search_path("dependency", "e1")
82+
.specific_library_search_path("crate", "e2")
83+
.run();
84+
}

tests/run-make/dump-mono-stats/Makefile

-5
This file was deleted.
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// A flag named dump-mono-stats was added to the compiler in 2022, which
2+
// collects stats on instantiation of items and their associated costs.
3+
// This test checks that the output stat file exists, and that it contains
4+
// a specific expected string.
5+
// See https://github.com./rust-lang/rust/pull/105481
6+
7+
use run_make_support::{cwd, fs_wrapper, rustc};
8+
9+
fn main() {
10+
rustc()
11+
.crate_type("lib")
12+
.input("foo.rs")
13+
.arg(format!("-Zdump-mono-stats={}", cwd().display()))
14+
.arg("-Zdump-mono-stats-format=json")
15+
.run();
16+
assert!(fs_wrapper::read_to_string("foo.mono_items.json").contains(r#""name":"bar""#));
17+
}
+8-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
// When the metadata format changes, old libraries used to cause librustc to abort
2+
// when reading their metadata. The error message for this scenario was unhelpful at best.
3+
// A better error message was implemented in #12645, and this test checks that it is the
4+
// one appearing in stderr in this scenario.
5+
// See https://github.com./rust-lang/rust/pull/12645
6+
17
use run_make_support::fs_wrapper::create_file;
2-
use run_make_support::{ar, rustc};
8+
use run_make_support::{llvm_ar, rustc};
39

410
fn main() {
511
create_file("lib.rmeta");
6-
ar(&["lib.rmeta"], "libfoo-ffffffff-1.0.rlib");
12+
llvm_ar().obj_to_ar().output_input("libfoo-ffffffff-1.0.rlib", "lib.rmeta").run();
713
rustc().input("foo.rs").run_fail().assert_stderr_contains("found invalid metadata");
814
}

tests/run-make/prune-link-args/Makefile

-10
This file was deleted.

0 commit comments

Comments
 (0)