Skip to content

Commit 6d76d7c

Browse files
committed
Auto merge of #8094 - Freax13:fix-target, r=ehuss
Fix target for doc test cross compilation - for target paths `Compilation::target` only contains the shortened file name, but we need to pass the full path to rustdoc
2 parents 03f11e8 + e5d9b03 commit 6d76d7c

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/cargo/ops/cargo_test.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::ffi::OsString;
22

3-
use crate::core::compiler::{Compilation, Doctest};
3+
use crate::core::compiler::{Compilation, CompileKind, Doctest};
44
use crate::core::shell::Verbosity;
55
use crate::core::Workspace;
66
use crate::ops;
@@ -163,7 +163,10 @@ fn run_doc_tests(
163163
.arg(&target.crate_name());
164164

165165
if doctest_xcompile {
166-
p.arg("--target").arg(&compilation.target);
166+
if let CompileKind::Target(target) = options.compile_opts.build_config.requested_kind {
167+
// use `rustc_target()` to properly handle JSON target paths
168+
p.arg("--target").arg(target.rustc_target());
169+
}
167170
p.arg("-Zunstable-options");
168171
p.arg("--enable-per-target-ignores");
169172
}

tests/testsuite/custom_target.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ fn custom_target_minimal() {
5151
p.cargo("build --lib --target custom-target.json -v").run();
5252
p.cargo("build --lib --target src/../custom-target.json -v")
5353
.run();
54+
55+
// Ensure that the correct style of flag is passed to --target with doc tests.
56+
p.cargo("test --doc --target src/../custom-target.json -v -Zdoctest-xcompile")
57+
.masquerade_as_nightly_cargo()
58+
.with_stderr_contains("[RUNNING] `rustdoc [..]--target [..]foo/custom-target.json[..]")
59+
.run();
5460
}
5561

5662
#[cargo_test]

0 commit comments

Comments
 (0)