Skip to content

Commit

Permalink
port rust-lld-custom-target test to rmake
Browse files Browse the repository at this point in the history
also make sure that rust-lld can be disabled via linker features, even
when enabled by default by the target spec
  • Loading branch information
lqd committed Apr 15, 2024
1 parent 9779592 commit 8fa6984
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
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
Expand Up @@ -249,7 +249,6 @@ run-make/rlib-format-packed-bundled-libs-2/Makefile
run-make/rlib-format-packed-bundled-libs-3/Makefile
run-make/rlib-format-packed-bundled-libs/Makefile
run-make/rmeta-preferred/Makefile
run-make/rust-lld-custom-target/Makefile
run-make/rustc-macro-dep-files/Makefile
run-make/rustdoc-determinism/Makefile
run-make/rustdoc-error-lines/Makefile
Expand Down
7 changes: 0 additions & 7 deletions tests/run-make/rust-lld-custom-target/Makefile

This file was deleted.

51 changes: 51 additions & 0 deletions tests/run-make/rust-lld-custom-target/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Test linking using `cc` with `rust-lld`, using a custom target with features described in MCP 510
// see https://github.com/rust-lang/compiler-team/issues/510 for more info:
//
// Starting from the `x86_64-unknown-linux-gnu` target spec, we add the following options:
// - a linker-flavor using lld via a C compiler
// - the self-contained linker component is enabled

//@ needs-rust-lld
//@ only-x86_64-unknown-linux-gnu

extern crate run_make_support;

use run_make_support::regex::Regex;
use run_make_support::rustc;
use std::process::Output;

fn main() {
// Compile to a custom target spec with rust-lld enabled by default. We'll check that by asking
// the linker to display its version number with a link-arg.
let output = rustc()
.env("RUSTC_LOG", "rustc_codegen_ssa::back::link=info")
.crate_type("cdylib")
.target("custom-target.json")
.arg("-Clink-args=-Wl,-v")
.input("lib.rs")
.run();
assert!(
find_lld_version_in_logs(output),
"the LLD version string should be present in the output logs"
);

// But it can also be disabled via linker features.
let output = rustc()
.env("RUSTC_LOG", "rustc_codegen_ssa::back::link=info")
.crate_type("cdylib")
.target("custom-target.json")
.arg("-Zlinker-features=-lld")
.arg("-Clink-args=-Wl,-v")
.input("lib.rs")
.run();
assert!(
!find_lld_version_in_logs(output),
"the LLD version string should not be present in the output logs"
);
}

fn find_lld_version_in_logs(output: Output) -> bool {
let lld_version_re = Regex::new(r"^LLD [0-9]+\.[0-9]+\.[0-9]+").unwrap();
let stderr = std::str::from_utf8(&output.stderr).unwrap();
stderr.lines().any(|line| lld_version_re.is_match(line))
}

0 comments on commit 8fa6984

Please sign in to comment.