Skip to content

Commit 9a73d23

Browse files
committed
port rust-lld-custom-target test to rmake
also make sure that rust-lld can be disabled via linker features, even when enabled by default by the target spec
1 parent 9779592 commit 9a73d23

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ run-make/rlib-format-packed-bundled-libs-2/Makefile
249249
run-make/rlib-format-packed-bundled-libs-3/Makefile
250250
run-make/rlib-format-packed-bundled-libs/Makefile
251251
run-make/rmeta-preferred/Makefile
252-
run-make/rust-lld-custom-target/Makefile
253252
run-make/rustc-macro-dep-files/Makefile
254253
run-make/rustdoc-determinism/Makefile
255254
run-make/rustdoc-error-lines/Makefile

tests/run-make/rust-lld-custom-target/Makefile

-7
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Test linking using `cc` with `rust-lld`, using a custom target with features described in MCP 510
2+
// see https://github.com/rust-lang/compiler-team/issues/510 for more info:
3+
//
4+
// Starting from the `x86_64-unknown-linux-gnu` target spec, we add the following options:
5+
// - a linker-flavor using lld via a C compiler
6+
// - the self-contained linker component is enabled
7+
8+
//@ needs-rust-lld
9+
//@ only-x86_64-unknown-linux-gnu
10+
11+
extern crate run_make_support;
12+
13+
use run_make_support::regex::Regex;
14+
use run_make_support::rustc;
15+
use std::process::Output;
16+
17+
fn main() {
18+
// Compile to a custom target spec with rust-lld enabled by default. We'll check that by asking
19+
// the linker to display its version number with a link-arg.
20+
let output = rustc()
21+
.env("RUSTC_LOG", "rustc_codegen_ssa::back::link=info")
22+
.arg("--crate-type=cdylib")
23+
.arg("--target=custom-target.json")
24+
.arg("-Clink-args=-Wl,-v")
25+
.input("lib.rs")
26+
.run();
27+
assert!(
28+
find_lld_version_in_logs(output),
29+
"the LLD version string should be present in the output logs"
30+
);
31+
32+
// But it can also be disabled via linker features.
33+
let output = rustc()
34+
.env("RUSTC_LOG", "rustc_codegen_ssa::back::link=info")
35+
.arg("--crate-type=cdylib")
36+
.arg("--target=custom-target.json")
37+
.arg("-Zlinker-features=-lld")
38+
.arg("-Clink-args=-Wl,-v")
39+
.input("lib.rs")
40+
.run();
41+
assert!(
42+
!find_lld_version_in_logs(output),
43+
"the LLD version string should not be present in the output logs"
44+
);
45+
}
46+
47+
fn find_lld_version_in_logs(output: Output) -> bool {
48+
let lld_version_re = Regex::new(r"^LLD [0-9]+\.[0-9]+\.[0-9]+").unwrap();
49+
let stderr = std::str::from_utf8(&output.stderr).unwrap();
50+
stderr.lines().any(|line| lld_version_re.is_match(line))
51+
}

0 commit comments

Comments
 (0)