Skip to content

Commit eec3135

Browse files
committed
Auto merge of rust-lang#139731 - jieyouxu:rmake-rustdoc-auto-cross, r=<try>
[WIP] Enable automatic cross-compilation for run-make rustdoc tests Extracted out of rust-lang#139244. Helps with rust-lang#138066. r? `@ghost` try-job: armhf-gnu try-job: test-various try-job: x86_64-msvc-1 try-job: i686-msvc-1 try-job: x86_64-mingw-1 try-job: aarch64-apple try-job: x86_64-apple-1
2 parents ae06b79 + 33a2041 commit eec3135

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

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

+29-6
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,35 @@ 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.
9+
/// Construct a new `rustdoc` invocation with target automatically set to cross-compile target. Use
10+
/// [`bare_rustdoc`] to avoid this.
911
#[track_caller]
1012
pub fn rustdoc() -> Rustdoc {
1113
Rustdoc::new()
1214
}
1315

16+
/// Bare `rustdoc` invocation, no args set.
17+
#[track_caller]
18+
pub fn bare_rustdoc() -> Rustdoc {
19+
Rustdoc::bare()
20+
}
21+
1422
#[derive(Debug)]
1523
#[must_use]
1624
pub struct Rustdoc {
1725
cmd: Command,
26+
target: Option<String>,
1827
}
1928

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

2236
#[track_caller]
2337
fn setup_common() -> Command {
@@ -28,11 +42,19 @@ fn setup_common() -> Command {
2842
}
2943

3044
impl Rustdoc {
31-
/// Construct a bare `rustdoc` invocation.
45+
/// Construct a new `rustdoc` invocation with target automatically set to cross-compile target.
46+
/// Use [`bare_rustdoc`] to avoid this.
3247
#[track_caller]
3348
pub fn new() -> Self {
3449
let cmd = setup_common();
35-
Self { cmd }
50+
Self { cmd, target: Some(target()) }
51+
}
52+
53+
/// Bare `rustdoc` invocation, no args set.
54+
#[track_caller]
55+
pub fn bare() -> Self {
56+
let cmd = setup_common();
57+
Self { cmd, target: None }
3658
}
3759

3860
/// Specify where an external library is located.
@@ -85,8 +107,9 @@ impl Rustdoc {
85107

86108
/// Specify the target triple, or a path to a custom target json spec file.
87109
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}"));
110+
// We store the target as a separate field, so that it can be specified multiple times.
111+
// This is in particular useful to override the default target set in `Rustdoc::new()`.
112+
self.target = Some(target.as_ref().to_string());
90113
self
91114
}
92115

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub use llvm::{
7070
};
7171
pub use python::python_command;
7272
pub use rustc::{bare_rustc, rustc, rustc_path, Rustc};
73-
pub use rustdoc::{rustdoc, Rustdoc};
73+
pub use rustdoc::{bare_rustdoc, rustdoc, Rustdoc};
7474

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

tests/run-make/rustdoc-default-output/rmake.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
// ensures the output of rustdoc's help menu is as expected.
44
// See https://github.com/rust-lang/rust/issues/88756
55

6-
use run_make_support::{diff, rustdoc};
6+
use run_make_support::{bare_rustdoc, diff};
77

88
fn main() {
9-
let out = rustdoc().run().stdout_utf8();
9+
// Use `bare_rustdoc` to ensure no `--target` is set.
10+
let out = bare_rustdoc().run().stdout_utf8();
1011
diff()
1112
.expected_file("output-default.stdout")
1213
.actual_text("actual", out)

0 commit comments

Comments
 (0)