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 fb25ca8

Browse files
authoredJun 16, 2025··
Auto merge of #139244 - jieyouxu:exp/auto-cross-run-make, r=<try>
[WIP] Enable automatic cross-compilation in run-make tests > [!CAUTION] > > Stacked on top of #142414, needs rebase. Supersedes #138066. Blocker for #141856. Based on #138066 with #139242 + #139239 cherry-picked in, plus `rustdoc()` cross-compile changes. r? `@ghost` try-job: armhf-gnu try-job: test-various
2 parents 68ac5ab + 4ec4d0e commit fb25ca8

File tree

117 files changed

+247
-54
lines changed

Some content is hidden

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

117 files changed

+247
-54
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

0 commit comments

Comments
 (0)
Please sign in to comment.