Skip to content

Commit a5235b7

Browse files
committed
moved cross-compiling doctests behind the doctest-xcompile feature flag
1 parent 8c93de6 commit a5235b7

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

src/cargo/core/features.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ pub struct CliUnstable {
336336
pub binary_dep_depinfo: bool,
337337
pub build_std: Option<Vec<String>>,
338338
pub timings: Option<Vec<String>>,
339+
pub doctest_xcompile: bool,
339340
}
340341

341342
impl CliUnstable {
@@ -393,6 +394,7 @@ impl CliUnstable {
393394
self.build_std = Some(crate::core::compiler::standard_lib::parse_unstable_flag(v))
394395
}
395396
"timings" => self.timings = Some(parse_timings(v)),
397+
"doctest-xcompile" => self.doctest_xcompile = true,
396398
_ => failure::bail!("unknown `-Z` flag specified: {}", k),
397399
}
398400

src/cargo/ops/cargo_test.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,16 @@ fn run_doc_tests(
140140
let mut errors = Vec::new();
141141
let config = options.compile_opts.config;
142142

143-
let runtool = compilation.target_runner();
143+
// The unstable doctest-xcompile feature enables both per-target-ignores and
144+
// cross-compiling doctests. As a side effect, this feature also gates running
145+
// doctests with runtools when target == host.
146+
let doctest_xcompile = config.cli_unstable().doctest_xcompile;
147+
let mut runtool: &Option<(std::path::PathBuf, Vec<String>)> = &None;
148+
if doctest_xcompile {
149+
runtool = compilation.target_runner();
150+
} else if compilation.host != compilation.target {
151+
return Ok((Test::Doc, errors));
152+
}
144153

145154
for doctest_info in &compilation.to_doc_test {
146155
let Doctest {
@@ -155,9 +164,10 @@ fn run_doc_tests(
155164
.arg("--crate-name")
156165
.arg(&target.crate_name());
157166

158-
p.arg("-Z");
159-
p.arg("unstable-options");
160-
p.arg("--enable-per-target-ignores");
167+
if doctest_xcompile {
168+
p.arg("-Zunstable-options");
169+
p.arg("--enable-per-target-ignores");
170+
}
161171

162172
runtool.as_ref().map(|(runtool, runtool_args)| {
163173
p.arg("--target").arg(&compilation.target);

tests/testsuite/cross_compile.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,7 @@ fn cross_tests() {
535535
[COMPILING] foo v0.0.0 ([CWD])
536536
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
537537
[RUNNING] target/{triple}/debug/deps/foo-[..][EXE]
538-
[RUNNING] target/{triple}/debug/deps/bar-[..][EXE]
539-
[DOCTEST] Skipping doctests, no runner defined for target",
538+
[RUNNING] target/{triple}/debug/deps/bar-[..][EXE]",
540539
triple = target
541540
))
542541
.with_stdout_contains("test test_foo ... ok")
@@ -596,7 +595,6 @@ fn no_cross_doctests() {
596595
[COMPILING] foo v0.0.1 ([CWD])
597596
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
598597
[RUNNING] target/{triple}/debug/deps/foo-[..][EXE]
599-
[DOCTEST] Skipping doctests, no runner defined for target
600598
",
601599
triple = target
602600
))
@@ -1225,8 +1223,7 @@ fn cross_test_dylib() {
12251223
[COMPILING] foo v0.0.1 ([CWD])
12261224
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
12271225
[RUNNING] target/{arch}/debug/deps/foo-[..][EXE]
1228-
[RUNNING] target/{arch}/debug/deps/test-[..][EXE]
1229-
[DOCTEST] Skipping doctests, no runner defined for target",
1226+
[RUNNING] target/{arch}/debug/deps/test-[..][EXE]",
12301227
arch = cross_compile::alternate()
12311228
))
12321229
.with_stdout_contains_n("test foo ... ok", 2)

0 commit comments

Comments
 (0)