Skip to content

[WIP] Enable automatic cross-compilation for run-make rustdoc tests #139731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions src/tools/run-make-support/src/external_deps/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,35 @@ use std::path::Path;

use crate::command::Command;
use crate::env::env_var;
use crate::target;
use crate::util::set_host_compiler_dylib_path;

/// Construct a new `rustdoc` invocation.
/// Construct a new `rustdoc` invocation with target automatically set to cross-compile target. Use
/// [`bare_rustdoc`] to avoid this.
#[track_caller]
pub fn rustdoc() -> Rustdoc {
Rustdoc::new()
}

/// Bare `rustdoc` invocation, no args set.
#[track_caller]
pub fn bare_rustdoc() -> Rustdoc {
Rustdoc::bare()
}

#[derive(Debug)]
#[must_use]
pub struct Rustdoc {
cmd: Command,
target: Option<String>,
}

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

#[track_caller]
fn setup_common() -> Command {
Expand All @@ -28,11 +42,19 @@ fn setup_common() -> Command {
}

impl Rustdoc {
/// Construct a bare `rustdoc` invocation.
/// Construct a new `rustdoc` invocation with target automatically set to cross-compile target.
/// Use [`bare_rustdoc`] to avoid this.
#[track_caller]
pub fn new() -> Self {
let cmd = setup_common();
Self { cmd }
Self { cmd, target: Some(target()) }
}

/// Bare `rustdoc` invocation, no args set.
#[track_caller]
pub fn bare() -> Self {
let cmd = setup_common();
Self { cmd, target: None }
}

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub use llvm::{
};
pub use python::python_command;
pub use rustc::{bare_rustc, rustc, rustc_path, Rustc};
pub use rustdoc::{rustdoc, Rustdoc};
pub use rustdoc::{bare_rustdoc, rustdoc, Rustdoc};

/// [`diff`][mod@diff] is implemented in terms of the [similar] library.
///
Expand Down
5 changes: 3 additions & 2 deletions tests/run-make/rustdoc-default-output/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
// ensures the output of rustdoc's help menu is as expected.
// See https://github.com/rust-lang/rust/issues/88756

use run_make_support::{diff, rustdoc};
use run_make_support::{bare_rustdoc, diff};

fn main() {
let out = rustdoc().run().stdout_utf8();
// Use `bare_rustdoc` to ensure no `--target` is set.
let out = bare_rustdoc().run().stdout_utf8();
diff()
.expected_file("output-default.stdout")
.actual_text("actual", out)
Expand Down
Loading