Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4c6478d

Browse files
committedMar 5, 2025
Auto merge of rust-lang#138066 - Kobzol:runmake-cross-target, r=<try>
[WIP] Enable automatic cross-compilation in run-make tests This will probably break... a lot of stuff. Related issue: rust-lang#137085 r? `@ghost` try-job: test-various-1 try-job: test-various-2
2 parents 4559163 + cbc3f76 commit 4c6478d

File tree

23 files changed

+83
-72
lines changed

23 files changed

+83
-72
lines changed
 

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::command::Command;
66
use crate::env::env_var;
77
use crate::path_helpers::cwd;
88
use crate::util::set_host_compiler_dylib_path;
9-
use crate::{is_aix, is_darwin, is_msvc, is_windows, uname};
9+
use crate::{is_aix, is_darwin, is_msvc, is_windows, target, uname};
1010

1111
/// Construct a new `rustc` invocation. This will automatically set the library
1212
/// search path as `-L cwd()`. Use [`bare_rustc`] to avoid this.
@@ -52,12 +52,17 @@ impl Rustc {
5252
// `rustc` invocation constructor methods
5353

5454
/// Construct a new `rustc` invocation. This will automatically set the library
55-
/// search path as `-L cwd()`. Use [`bare_rustc`] to avoid this.
55+
/// search path as `-L cwd()` and also the compilation target.
56+
/// Use [`bare_rustc`] to avoid this.
5657
#[track_caller]
5758
pub fn new() -> Self {
5859
let mut cmd = setup_common();
5960
cmd.arg("-L").arg(cwd());
60-
Self { cmd }
61+
62+
let mut rustc = Self { cmd };
63+
// Automatically support cross-compilation
64+
rustc.target(target());
65+
rustc
6166
}
6267

6368
/// Construct a bare `rustc` invocation with no flags set.

‎tests/run-make/amdgpu-kd/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
//@ needs-llvm-components: amdgpu
77
//@ needs-rust-lld
88

9-
use run_make_support::{llvm_readobj, rustc};
9+
use run_make_support::{bare_rustc, llvm_readobj};
1010

1111
fn main() {
12-
rustc()
12+
bare_rustc()
1313
.crate_name("foo")
1414
.target("amdgcn-amd-amdhsa")
1515
.arg("-Ctarget-cpu=gfx900")

‎tests/run-make/apple-deployment-target/rmake.rs

-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ fn main() {
4141

4242
// Remove env vars to get `rustc`'s default
4343
let output = rustc()
44-
.target(target())
4544
.env_remove("MACOSX_DEPLOYMENT_TARGET")
4645
.env_remove("IPHONEOS_DEPLOYMENT_TARGET")
4746
.env_remove("WATCHOS_DEPLOYMENT_TARGET")
@@ -58,7 +57,6 @@ fn main() {
5857
run_in_tmpdir(|| {
5958
let rustc = || {
6059
let mut rustc = rustc();
61-
rustc.target(target());
6260
rustc.crate_type("lib");
6361
rustc.emit("obj");
6462
rustc.input("foo.rs");
@@ -82,7 +80,6 @@ fn main() {
8280

8381
let rustc = || {
8482
let mut rustc = rustc();
85-
rustc.target(target());
8683
rustc.crate_type("dylib");
8784
rustc.input("foo.rs");
8885
rustc.output("libfoo.dylib");
@@ -108,7 +105,6 @@ fn main() {
108105
run_in_tmpdir(|| {
109106
let rustc = || {
110107
let mut rustc = rustc();
111-
rustc.target(target());
112108
rustc.crate_type("bin");
113109
rustc.input("foo.rs");
114110
rustc.output("foo");
@@ -147,7 +143,6 @@ fn main() {
147143
run_in_tmpdir(|| {
148144
let rustc = || {
149145
let mut rustc = rustc();
150-
rustc.target(target());
151146
rustc.incremental("incremental");
152147
rustc.crate_type("lib");
153148
rustc.emit("obj");

‎tests/run-make/apple-sdk-version/rmake.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ fn has_sdk_version(file: &str, version: &str) {
2424

2525
fn main() {
2626
// Fetch rustc's inferred deployment target.
27-
let current_deployment_target =
28-
rustc().target(target()).print("deployment-target").run().stdout_utf8();
27+
let current_deployment_target = rustc().print("deployment-target").run().stdout_utf8();
2928
let current_deployment_target = current_deployment_target.split('=').last().unwrap().trim();
3029

3130
// Fetch current SDK version via. xcrun.
@@ -45,15 +44,15 @@ fn main() {
4544
let current_sdk_version = current_sdk_version.trim();
4645

4746
// Check the SDK version in the object file produced by the codegen backend.
48-
rustc().target(target()).crate_type("lib").emit("obj").input("foo.rs").output("foo.o").run();
47+
rustc().crate_type("lib").emit("obj").input("foo.rs").output("foo.o").run();
4948
// Set to 0, which means not set or "n/a".
5049
has_sdk_version("foo.o", "n/a");
5150

5251
// Check the SDK version in the .rmeta file, as set in `create_object_file`.
5352
//
5453
// This is just to ensure that we don't set some odd version in `create_object_file`,
5554
// if the rmeta file is packed in a different way in the future, this can safely be removed.
56-
rustc().target(target()).crate_type("rlib").input("foo.rs").output("libfoo.rlib").run();
55+
rustc().crate_type("rlib").input("foo.rs").output("libfoo.rlib").run();
5756
// Extra .rmeta file (which is encoded as an object file).
5857
cmd("ar").arg("-x").arg("libfoo.rlib").arg("lib.rmeta").run();
5958
has_sdk_version("lib.rmeta", "n/a");
@@ -69,7 +68,6 @@ fn main() {
6968
// Test with clang
7069
let file_name = format!("foo_cc{file_ext}");
7170
rustc()
72-
.target(target())
7371
.crate_type("bin")
7472
.arg("-Clinker-flavor=gcc")
7573
.input("foo.rs")
@@ -80,7 +78,6 @@ fn main() {
8078
// Test with ld64
8179
let file_name = format!("foo_ld{file_ext}");
8280
rustc()
83-
.target(target())
8481
.crate_type("bin")
8582
.arg("-Clinker-flavor=ld")
8683
.input("foo.rs")

‎tests/run-make/atomic-lock-free/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
//@ only-linux
55

6-
use run_make_support::{llvm_components_contain, llvm_readobj, rustc};
6+
use run_make_support::{bare_rustc, llvm_components_contain, llvm_readobj};
77

88
fn compile(target: &str) {
9-
rustc().input("atomic_lock_free.rs").target(target).run();
9+
bare_rustc().input("atomic_lock_free.rs").target(target).run();
1010
}
1111

1212
fn check() {

‎tests/run-make/avr-rjmp-offset/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
// crashes... so I'm going to disable this test for windows for now.
1616
//@ ignore-windows-gnu
1717

18-
use run_make_support::{llvm_objdump, rustc};
18+
use run_make_support::{bare_rustc, llvm_objdump};
1919

2020
fn main() {
21-
rustc()
21+
bare_rustc()
2222
.input("avr-rjmp-offsets.rs")
2323
.opt_level("s")
2424
.panic("abort")

‎tests/run-make/comment-section/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
// FIXME(jieyouxu): check cross-compile setup
88
//@ ignore-cross-compile
99

10-
use run_make_support::{cwd, env_var, llvm_readobj, rfs, rustc};
10+
use run_make_support::{bare_rustc, cwd, env_var, llvm_readobj, rfs};
1111

1212
fn main() {
1313
let target = env_var("TARGET");
1414

15-
rustc()
15+
bare_rustc()
1616
.arg("-")
1717
.stdin_buf("fn main() {}")
1818
.emit("link,obj")

‎tests/run-make/llvm-ident/rmake.rs

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ fn main() {
1616
.arg("-Csave-temps")
1717
.codegen_units(16)
1818
.opt_level("2")
19-
.target(&env_var("TARGET"))
2019
.stdin_buf("fn main(){}")
2120
.run();
2221

‎tests/run-make/min-global-align/rmake.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,21 @@
77
// Reason: this test is specific to linux, considering compilation is targeted
88
// towards linux architectures only.
99

10-
use run_make_support::{assert_count_is, llvm_components_contain, rfs, rustc};
10+
use run_make_support::{assert_count_is, bare_rustc, llvm_components_contain, rfs};
1111

1212
fn main() {
1313
// Most targets are happy with default alignment -- take i686 for example.
1414
if llvm_components_contain("x86") {
15-
rustc().target("i686-unknown-linux-gnu").emit("llvm-ir").input("min_global_align.rs").run();
15+
bare_rustc()
16+
.target("i686-unknown-linux-gnu")
17+
.emit("llvm-ir")
18+
.input("min_global_align.rs")
19+
.run();
1620
assert_count_is(3, rfs::read_to_string("min_global_align.ll"), "align 1");
1721
}
1822
// SystemZ requires even alignment for PC-relative addressing.
1923
if llvm_components_contain("systemz") {
20-
rustc()
24+
bare_rustc()
2125
.target("s390x-unknown-linux-gnu")
2226
.emit("llvm-ir")
2327
.input("min_global_align.rs")

‎tests/run-make/mismatching-target-triples/rmake.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55
// error message is used.
66
// See https://github.com/rust-lang/rust/issues/10814
77

8-
use run_make_support::rustc;
8+
use run_make_support::bare_rustc;
99

1010
fn main() {
11-
rustc().input("foo.rs").target("i686-unknown-linux-gnu").run();
12-
rustc().input("bar.rs").target("x86_64-unknown-linux-gnu").run_fail().assert_stderr_contains(
13-
r#"couldn't find crate `foo` with expected target triple x86_64-unknown-linux-gnu"#,
14-
);
11+
bare_rustc().input("foo.rs").target("i686-unknown-linux-gnu").run();
12+
bare_rustc()
13+
.input("bar.rs")
14+
.library_search_path(".")
15+
.target("x86_64-unknown-linux-gnu")
16+
.run_fail()
17+
.assert_stderr_contains(
18+
r#"couldn't find crate `foo` with expected target triple x86_64-unknown-linux-gnu"#,
19+
);
1520
}

‎tests/run-make/mte-ffi/rmake.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ fn run_test(variant: &str) {
2222
flags
2323
};
2424
println!("{variant} test...");
25-
rustc()
26-
.input(format!("foo_{variant}.rs"))
27-
.target(target())
28-
.linker("aarch64-linux-gnu-gcc")
29-
.run();
25+
rustc().input(format!("foo_{variant}.rs")).linker("aarch64-linux-gnu-gcc").run();
3026
gcc()
3127
.input(format!("bar_{variant}.c"))
3228
.input(dynamic_lib_name("foo"))

‎tests/run-make/musl-default-linking/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use run_make_support::{rustc, serde_json};
1+
use run_make_support::{bare_rustc, rustc, serde_json};
22

33
// Please do NOT add more targets to this list!
44
// Per https://github.com/rust-lang/compiler-team/issues/422,
@@ -36,7 +36,7 @@ fn main() {
3636
continue;
3737
}
3838

39-
let target_spec_json = rustc()
39+
let target_spec_json = bare_rustc()
4040
.print("target-spec-json")
4141
.target(target)
4242
.arg("-Zunstable-options")

‎tests/run-make/print-cfg/rmake.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::collections::HashSet;
1414
use std::iter::FromIterator;
1515
use std::path::PathBuf;
1616

17-
use run_make_support::{rfs, rustc};
17+
use run_make_support::{bare_rustc, rfs};
1818

1919
struct PrintCfg {
2020
target: &'static str,
@@ -86,7 +86,7 @@ fn check(PrintCfg { target, includes, disallow }: PrintCfg) {
8686

8787
// --print=cfg
8888
{
89-
let output = rustc().target(target).print("cfg").run();
89+
let output = bare_rustc().target(target).print("cfg").run();
9090
let stdout = output.stdout_utf8();
9191

9292
check_(&stdout, includes, disallow);
@@ -96,7 +96,7 @@ fn check(PrintCfg { target, includes, disallow }: PrintCfg) {
9696
{
9797
let tmp_path = PathBuf::from(format!("{target}.cfg"));
9898

99-
rustc().target(target).print(&format!("cfg={}", tmp_path.display())).run();
99+
bare_rustc().target(target).print(&format!("cfg={}", tmp_path.display())).run();
100100

101101
let output = rfs::read_to_string(&tmp_path);
102102

‎tests/run-make/print-target-cpus-native/rmake.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//@ needs-llvm-components: aarch64 x86
33
// FIXME(#132514): Is needs-llvm-components actually necessary for this test?
44

5-
use run_make_support::{assert_contains_regex, rfs, rustc, target};
5+
use run_make_support::{assert_contains_regex, bare_rustc, rfs, rustc, target};
66

77
// Test that when querying `--print=target-cpus` for a target with the same
88
// architecture as the host, the first CPU is "native" with a suitable remark.
@@ -17,7 +17,7 @@ fn main() {
1717

1818
// With an explicit target that happens to be the host.
1919
let host = target(); // Because of ignore-cross-compile, assume host == target.
20-
rustc().print("target-cpus").target(host).run().assert_stdout_contains_regex(expected);
20+
bare_rustc().print("target-cpus").target(host).run().assert_stdout_contains_regex(expected);
2121

2222
// With an explicit output path.
2323
rustc().print("target-cpus=./xyzzy.txt").run().assert_stdout_equals("");
@@ -34,6 +34,10 @@ fn main() {
3434
};
3535
for target in cross_targets {
3636
println!("Trying target: {target}");
37-
rustc().print("target-cpus").target(target).run().assert_stdout_contains_regex(expected);
37+
bare_rustc()
38+
.print("target-cpus")
39+
.target(target)
40+
.run()
41+
.assert_stdout_contains_regex(expected);
3842
}
3943
}

‎tests/run-make/print-to-output/rmake.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
use std::path::PathBuf;
1111

12-
use run_make_support::{rfs, rustc, target};
12+
use run_make_support::{bare_rustc, rfs, target};
1313

1414
struct Option<'a> {
1515
target: &'a str,
@@ -44,13 +44,16 @@ fn check(args: Option) {
4444
}
4545

4646
// --print={option}
47-
let stdout = rustc().target(args.target).print(args.option).run().stdout_utf8();
47+
let stdout = bare_rustc().target(args.target).print(args.option).run().stdout_utf8();
4848

4949
// --print={option}=PATH
5050
let output = {
5151
let tmp_path = PathBuf::from(format!("{}.txt", args.option));
5252

53-
rustc().target(args.target).print(&format!("{}={}", args.option, tmp_path.display())).run();
53+
bare_rustc()
54+
.target(args.target)
55+
.print(&format!("{}={}", args.option, tmp_path.display()))
56+
.run();
5457

5558
rfs::read_to_string(&tmp_path)
5659
};

‎tests/run-make/rust-lld-custom-target/rmake.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
//@ needs-rust-lld
99
//@ only-x86_64-unknown-linux-gnu
1010

11+
use run_make_support::bare_rustc;
1112
use run_make_support::regex::Regex;
12-
use run_make_support::rustc;
1313

1414
fn main() {
1515
// Compile to a custom target spec with rust-lld enabled by default. We'll check that by asking
1616
// the linker to display its version number with a link-arg.
17-
let output = rustc()
17+
let output = bare_rustc()
1818
.crate_type("cdylib")
1919
.arg("-Wlinker-messages")
2020
.target("custom-target.json")
@@ -28,7 +28,7 @@ fn main() {
2828
);
2929

3030
// But it can also be disabled via linker features.
31-
let output = rustc()
31+
let output = bare_rustc()
3232
.crate_type("cdylib")
3333
.arg("-Wlinker-messages")
3434
.target("custom-target.json")

‎tests/run-make/rustc-macro-dep-files/rmake.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use run_make_support::{diff, rustc, target};
88

99
fn main() {
1010
rustc().input("foo.rs").run();
11-
rustc().input("bar.rs").target(target()).emit("dep-info").run();
11+
rustc().input("bar.rs").emit("dep-info").run();
1212
// The emitted file should not contain "proc-macro source".
1313
diff().expected_file("correct.d").actual_file("bar.d").run();
1414
}

‎tests/run-make/rustdoc-target-spec-json-path/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Test that rustdoc will properly canonicalize the target spec json path just like rustc.
22

3-
use run_make_support::{cwd, rustc, rustdoc};
3+
use run_make_support::{bare_rustc, cwd, rustdoc};
44

55
fn main() {
66
let out_dir = "rustdoc-target-spec-json-path";
7-
rustc().crate_type("lib").input("dummy_core.rs").target("target.json").run();
7+
bare_rustc().crate_type("lib").input("dummy_core.rs").target("target.json").run();
88
rustdoc()
99
.input("my_crate.rs")
1010
.out_dir(out_dir)

‎tests/run-make/simd-ffi/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Note that this test does not check linking or binary execution.
66
// See https://github.com/rust-lang/rust/pull/21233
77

8-
use run_make_support::{llvm_components_contain, rustc};
8+
use run_make_support::{bare_rustc, llvm_components_contain};
99

1010
fn main() {
1111
let mut targets = Vec::new();
@@ -52,7 +52,7 @@ fn main() {
5252
// enabled by-default for i686 and ARM; these features will be invalid
5353
// on some platforms, but LLVM just prints a warning so that's fine for
5454
// now.
55-
rustc()
55+
bare_rustc()
5656
.target(&target)
5757
.emit("llvm-ir,asm")
5858
.input("simd.rs")
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.