Skip to content

Commit 4ec4d0e

Browse files
committed
Enable run-make-support auto cross-compilation for rustdoc too
1 parent 3e948fd commit 4ec4d0e

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

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
///

0 commit comments

Comments
 (0)