Skip to content

Commit 8c93de6

Browse files
committed
Added ability to crosscompile doctests
1 parent cdf7f63 commit 8c93de6

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

src/cargo/core/compiler/compilation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl<'cfg> Compilation<'cfg> {
163163
self.fill_env(process(cmd), pkg, true)
164164
}
165165

166-
fn target_runner(&self) -> &Option<(PathBuf, Vec<String>)> {
166+
pub fn target_runner(&self) -> &Option<(PathBuf, Vec<String>)> {
167167
&self.target_runner
168168
}
169169

src/cargo/ops/cargo_test.rs

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

143-
// We don't build/run doc tests if `target` does not equal `host`.
144-
if compilation.host != compilation.target {
145-
return Ok((Test::Doc, errors));
146-
}
143+
let runtool = compilation.target_runner();
147144

148145
for doctest_info in &compilation.to_doc_test {
149146
let Doctest {
@@ -158,6 +155,18 @@ fn run_doc_tests(
158155
.arg("--crate-name")
159156
.arg(&target.crate_name());
160157

158+
p.arg("-Z");
159+
p.arg("unstable-options");
160+
p.arg("--enable-per-target-ignores");
161+
162+
runtool.as_ref().map(|(runtool, runtool_args)| {
163+
p.arg("--target").arg(&compilation.target);
164+
p.arg("--runtool").arg(runtool);
165+
for arg in runtool_args {
166+
p.arg("--runtool-arg").arg(arg);
167+
}
168+
});
169+
161170
for &rust_dep in &[&compilation.deps_output] {
162171
let mut arg = OsString::from("dependency=");
163172
arg.push(rust_dep);
@@ -194,7 +203,6 @@ fn run_doc_tests(
194203
if let Some(flags) = compilation.rustdocflags.get(&package.package_id()) {
195204
p.args(flags);
196205
}
197-
198206
config
199207
.shell()
200208
.verbose(|shell| shell.status("Running", p.to_string()))?;

tests/testsuite/cross_compile.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,8 @@ 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]",
538+
[RUNNING] target/{triple}/debug/deps/bar-[..][EXE]
539+
[DOCTEST] Skipping doctests, no runner defined for target",
539540
triple = target
540541
))
541542
.with_stdout_contains("test test_foo ... ok")
@@ -595,6 +596,7 @@ fn no_cross_doctests() {
595596
[COMPILING] foo v0.0.1 ([CWD])
596597
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
597598
[RUNNING] target/{triple}/debug/deps/foo-[..][EXE]
599+
[DOCTEST] Skipping doctests, no runner defined for target
598600
",
599601
triple = target
600602
))
@@ -1223,7 +1225,8 @@ fn cross_test_dylib() {
12231225
[COMPILING] foo v0.0.1 ([CWD])
12241226
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
12251227
[RUNNING] target/{arch}/debug/deps/foo-[..][EXE]
1226-
[RUNNING] target/{arch}/debug/deps/test-[..][EXE]",
1228+
[RUNNING] target/{arch}/debug/deps/test-[..][EXE]
1229+
[DOCTEST] Skipping doctests, no runner defined for target",
12271230
arch = cross_compile::alternate()
12281231
))
12291232
.with_stdout_contains_n("test foo ... ok", 2)

0 commit comments

Comments
 (0)