Skip to content

Commit 7b85605

Browse files
committed
run-make-support: enable automatic cross-compilation for rustdoc too
1 parent f39042b commit 7b85605

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
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
@@ -69,7 +69,7 @@ pub use llvm::{
6969
};
7070
pub use python::python_command;
7171
pub use rustc::{bare_rustc, rustc, rustc_path, Rustc};
72-
pub use rustdoc::{rustdoc, Rustdoc};
72+
pub use rustdoc::{bare_rustdoc, rustdoc, Rustdoc};
7373

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

0 commit comments

Comments
 (0)