Skip to content

Commit 4e14cc1

Browse files
committed
Auto merge of #8358 - ehuss:fix-target-host-doctest, r=alexcrichton
Fix doctests not running with --target=HOST. There was a regression in #8167 where `cargo test --target=$HOST` stopped running doctests. This caused doctests to silently stop running in rust-lang/rust (rust-lang/rust#73286). This PR restores the original behavior where `--target=$HOST` behaves as-if it is a normal host test. There was a discussion about this at #8167 (review), but I think I let it slip through the cracks.
2 parents 56636e9 + 1bf67a0 commit 4e14cc1

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/cargo/core/compiler/compilation.rs

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ pub struct Compilation<'cfg> {
6666
/// Flags to pass to rustdoc when invoked from cargo test, per package.
6767
pub rustdocflags: HashMap<PackageId, Vec<String>>,
6868

69+
/// The target host triple.
70+
pub host: String,
71+
6972
config: &'cfg Config,
7073

7174
/// Rustc process to be used by default
@@ -123,6 +126,7 @@ impl<'cfg> Compilation<'cfg> {
123126
cfgs: HashMap::new(),
124127
rustdocflags: HashMap::new(),
125128
config: bcx.config,
129+
host: bcx.host_triple().to_string(),
126130
rustc_process: rustc,
127131
rustc_workspace_wrapper_process,
128132
primary_rustc_process,

src/cargo/ops/cargo_test.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ fn run_doc_tests(
137137
compilation: &Compilation<'_>,
138138
) -> CargoResult<(Test, Vec<ProcessError>)> {
139139
let mut errors = Vec::new();
140+
let doctest_xcompile = config.cli_unstable().doctest_xcompile;
140141

141142
for doctest_info in &compilation.to_doc_test {
142143
let Doctest {
@@ -145,9 +146,16 @@ fn run_doc_tests(
145146
unit,
146147
} = doctest_info;
147148

148-
// Skip any `--target` tests unless `doctest-xcompile` is specified.
149-
if !config.cli_unstable().doctest_xcompile && !unit.kind.is_host() {
150-
continue;
149+
if !doctest_xcompile {
150+
match unit.kind {
151+
CompileKind::Host => {}
152+
CompileKind::Target(target) => {
153+
if target.short_name() != compilation.host {
154+
// Skip doctests, -Zdoctest-xcompile not enabled.
155+
continue;
156+
}
157+
}
158+
}
151159
}
152160

153161
config.shell().status("Doc-tests", unit.target.name())?;
@@ -157,7 +165,7 @@ fn run_doc_tests(
157165
.arg("--crate-name")
158166
.arg(&unit.target.crate_name());
159167

160-
if config.cli_unstable().doctest_xcompile {
168+
if doctest_xcompile {
161169
if let CompileKind::Target(target) = unit.kind {
162170
// use `rustc_target()` to properly handle JSON target paths
163171
p.arg("--target").arg(target.rustc_target());

tests/testsuite/cross_compile.rs

+1
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ fn no_cross_doctests() {
396396
[COMPILING] foo v0.0.1 ([CWD])
397397
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
398398
[RUNNING] target/{triple}/debug/deps/foo-[..][EXE]
399+
[DOCTEST] foo
399400
",
400401
triple = target
401402
))

0 commit comments

Comments
 (0)