Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 70e2b4a

Browse files
committed
Auto merge of #139244 - jieyouxu:exp/auto-cross-run-make, r=Kobzol
Enable automatic cross-compilation in run-make tests Supersedes #138066. Blocker for #141856. Based on #138066 plus `rustdoc()` cross-compile changes. ### Summary This PR automatically specifies `--target` to `rustc()` and `rustdoc()` to have `rustc`/`rustdoc` produce cross-compiled artifacts in run-make tests by default, unless: - `//@ ignore-cross-compile` is used, or - `bare_{rustc,rustdoc}` are used, or - Explicit `.target()` is specified, which overrides the default cross-compile target. Some tests are necessarily modified: - Tests that have `.target(target())` have that incantation removed (since this is now automatically the default). - Some tests have `//@ needs-target-std`, but are a necessary-but-insufficient condition, and are changed to `//@ ignore-cross-compile` instead as host-only tests. - A few tests received `//@ ignore-musl` that fail against `x86_64-unknown-linux-musl` because of inability to find `-lunwind`. AFAICT, they don't *need* to test cross-compiled artifacts. - Some tests are constrained to host-only for now, because the effort to make them pass on cross-compile does not seem worth the complexity, and it's not really *meaningfully* improving test coverage. try-job: dist-various-1
2 parents 8a65ee0 + 2beccc4 commit 70e2b4a

File tree

72 files changed

+206
-112
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+206
-112
lines changed

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

Lines changed: 17 additions & 7 deletions
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.
@@ -27,9 +27,15 @@ pub fn bare_rustc() -> Rustc {
2727
#[must_use]
2828
pub struct Rustc {
2929
cmd: Command,
30+
target: Option<String>,
3031
}
3132

32-
crate::macros::impl_common_helpers!(Rustc);
33+
// Only fill in the target just before execution, so that it can be overridden.
34+
crate::macros::impl_common_helpers!(Rustc, |rustc: &mut Rustc| {
35+
if let Some(target) = &rustc.target {
36+
rustc.cmd.arg(&format!("--target={target}"));
37+
}
38+
});
3339

3440
pub fn rustc_path() -> String {
3541
env_var("RUSTC")
@@ -46,19 +52,22 @@ impl Rustc {
4652
// `rustc` invocation constructor methods
4753

4854
/// Construct a new `rustc` invocation. This will automatically set the library
49-
/// 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.
5057
#[track_caller]
5158
pub fn new() -> Self {
5259
let mut cmd = setup_common();
5360
cmd.arg("-L").arg(cwd());
54-
Self { cmd }
61+
62+
// Automatically default to cross-compilation
63+
Self { cmd, target: Some(target()) }
5564
}
5665

5766
/// Construct a bare `rustc` invocation with no flags set.
5867
#[track_caller]
5968
pub fn bare() -> Self {
6069
let cmd = setup_common();
61-
Self { cmd }
70+
Self { cmd,target:None }
6271
}
6372

6473
// Argument provider methods
@@ -234,8 +243,9 @@ impl Rustc {
234243

235244
/// Specify the target triple, or a path to a custom target json spec file.
236245
pub fn target<S: AsRef<str>>(&mut self, target: S) -> &mut Self {
237-
let target = target.as_ref();
238-
self.cmd.arg(format!("--target={target}"));
246+
// We store the target as a separate field, so that it can be specified multiple times.
247+
// This is in particular useful to override the default target set in Rustc::new().
248+
self.target = Some(target.as_ref().to_string());
239249
self
240250
}
241251

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

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,36 @@ use std::path::Path;
33

44
use crate::command::Command;
55
use crate::env::env_var;
6+
use crate::target;
67
use crate::util::set_host_compiler_dylib_path;
78

8-
/// Construct a new `rustdoc` invocation. This will configure the host compiler runtime libs.
9+
/// Construct a new `rustdoc` invocation with target automatically set to cross-compile target and
10+
/// with host compiler runtime libs configured. Use [`bare_rustdoc`] to avoid automatically setting
11+
/// cross-compile target.
912
#[track_caller]
1013
pub fn rustdoc() -> Rustdoc {
1114
Rustdoc::new()
1215
}
1316

17+
/// Bare `rustdoc` invocation, no args set.
18+
#[track_caller]
19+
pub fn bare_rustdoc() -> Rustdoc {
20+
Rustdoc::bare()
21+
}
22+
1423
#[derive(Debug)]
1524
#[must_use]
1625
pub struct Rustdoc {
1726
cmd: Command,
27+
target: Option<String>,
1828
}
1929

20-
crate::macros::impl_common_helpers!(Rustdoc);
30+
// Only fill in the target just before execution, so that it can be overridden.
31+
crate::macros::impl_common_helpers!(Rustdoc, |rustdoc: &mut Rustdoc| {
32+
if let Some(target) = &rustdoc.target {
33+
rustdoc.cmd.arg(&format!("--target={target}"));
34+
}
35+
});
2136

2237
#[track_caller]
2338
fn setup_common() -> Command {
@@ -28,11 +43,20 @@ fn setup_common() -> Command {
2843
}
2944

3045
impl Rustdoc {
31-
/// Construct a bare `rustdoc` invocation. This will configure the host compiler runtime libs.
46+
/// Construct a new `rustdoc` invocation with target automatically set to cross-compile target
47+
/// and with host compiler runtime libs configured. Use [`bare_rustdoc`] to avoid automatically
48+
/// setting cross-compile target.
3249
#[track_caller]
3350
pub fn new() -> Self {
3451
let cmd = setup_common();
35-
Self { cmd }
52+
Self { cmd, target: Some(target()) }
53+
}
54+
55+
/// Bare `rustdoc` invocation, no args set.
56+
#[track_caller]
57+
pub fn bare() -> Self {
58+
let cmd = setup_common();
59+
Self { cmd, target: None }
3660
}
3761

3862
/// Specify where an external library is located.
@@ -85,8 +109,9 @@ impl Rustdoc {
85109

86110
/// Specify the target triple, or a path to a custom target json spec file.
87111
pub fn target<S: AsRef<str>>(&mut self, target: S) -> &mut Self {
88-
let target = target.as_ref();
89-
self.cmd.arg(format!("--target={target}"));
112+
// We store the target as a separate field, so that it can be specified multiple times.
113+
// This is in particular useful to override the default target set in `Rustdoc::new()`.
114+
self.target = Some(target.as_ref().to_string());
90115
self
91116
}
92117

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub use llvm::{
6868
};
6969
pub use python::python_command;
7070
pub use rustc::{bare_rustc, rustc, rustc_path, Rustc};
71-
pub use rustdoc::{rustdoc, Rustdoc};
71+
pub use rustdoc::{bare_rustdoc,rustdoc, Rustdoc};
7272

7373
/// [`diff`][mod@diff] is implemented in terms of the [similar] library.
7474
///

‎src/tools/run-make-support/src/macros.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@
2323
/// }
2424
/// ```
2525
///
26+
/// You can pass an optional second parameter which should be a function that is passed
27+
/// `&mut self` just before the command is executed.
28+
///
2629
/// [`Command`]: crate::command::Command
2730
/// [`CompletedProcess`]: crate::command::CompletedProcess
2831
macro_rules! impl_common_helpers {
2932
($wrapper: ident) => {
33+
$crate::macros::impl_common_helpers!($wrapper, |_| {});
34+
};
35+
($wrapper: ident, $before_exec: expr) => {
3036
impl $wrapper {
3137
/// In very rare circumstances, you may need a e.g. `bare_rustc()` or `bare_rustdoc()`
3238
/// with host runtime libs configured, but want the underlying raw
@@ -130,12 +136,14 @@ macro_rules! impl_common_helpers {
130136
/// Run the constructed command and assert that it is successfully run.
131137
#[track_caller]
132138
pub fn run(&mut self) -> crate::command::CompletedProcess {
139+
$before_exec(&mut *self);
133140
self.cmd.run()
134141
}
135142

136143
/// Run the constructed command and assert that it does not successfully run.
137144
#[track_caller]
138145
pub fn run_fail(&mut self) -> crate::command::CompletedProcess {
146+
$before_exec(&mut *self);
139147
self.cmd.run_fail()
140148
}
141149

@@ -145,6 +153,7 @@ macro_rules! impl_common_helpers {
145153
/// whenever possible.
146154
#[track_caller]
147155
pub fn run_unchecked(&mut self) -> crate::command::CompletedProcess {
156+
$before_exec(&mut *self);
148157
self.cmd.run_unchecked()
149158
}
150159

‎tests/run-make/allow-warnings-cmdline-stability/rmake.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ needs-target-std
1+
//@ ignore-cross-compile
22
// Test that `-Awarnings` suppresses warnings for unstable APIs.
33

44
use run_make_support::rustc;

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

Lines changed: 0 additions & 5 deletions
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‎

Lines changed: 3 additions & 6 deletions
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/crate-circular-deps-link/rmake.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//@ needs-target-std
2-
//
1+
//@ ignore-cross-compile
2+
33
// Test that previously triggered a linker failure with root cause
44
// similar to one found in the issue #69368.
55
//

‎tests/run-make/doctests-merge/rmake.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//@ needs-target-std
1+
//@ ignore-cross-compile (needs to run doctests)
2+
23
use std::path::Path;
34

45
use run_make_support::{cwd, diff, rustc, rustdoc};

‎tests/run-make/doctests-runtool/rmake.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//@ needs-target-std
2-
//
1+
//@ ignore-cross-compile (needs to run host tool binary)
2+
33
// Tests behavior of rustdoc `--test-runtool`.
44

55
use std::path::PathBuf;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /