Skip to content

Commit

Permalink
Added ability to crosscompile doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
Goirad committed Sep 18, 2019
1 parent cdf7f63 commit 8c93de6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl<'cfg> Compilation<'cfg> {
self.fill_env(process(cmd), pkg, true)
}

fn target_runner(&self) -> &Option<(PathBuf, Vec<String>)> {
pub fn target_runner(&self) -> &Option<(PathBuf, Vec<String>)> {
&self.target_runner
}

Expand Down
18 changes: 13 additions & 5 deletions src/cargo/ops/cargo_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,7 @@ fn run_doc_tests(
let mut errors = Vec::new();
let config = options.compile_opts.config;

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

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

p.arg("-Z");
p.arg("unstable-options");
p.arg("--enable-per-target-ignores");

runtool.as_ref().map(|(runtool, runtool_args)| {
p.arg("--target").arg(&compilation.target);
p.arg("--runtool").arg(runtool);
for arg in runtool_args {
p.arg("--runtool-arg").arg(arg);
}
});

for &rust_dep in &[&compilation.deps_output] {
let mut arg = OsString::from("dependency=");
arg.push(rust_dep);
Expand Down Expand Up @@ -194,7 +203,6 @@ fn run_doc_tests(
if let Some(flags) = compilation.rustdocflags.get(&package.package_id()) {
p.args(flags);
}

config
.shell()
.verbose(|shell| shell.status("Running", p.to_string()))?;
Expand Down
7 changes: 5 additions & 2 deletions tests/testsuite/cross_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,8 @@ fn cross_tests() {
[COMPILING] foo v0.0.0 ([CWD])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target/{triple}/debug/deps/foo-[..][EXE]
[RUNNING] target/{triple}/debug/deps/bar-[..][EXE]",
[RUNNING] target/{triple}/debug/deps/bar-[..][EXE]
[DOCTEST] Skipping doctests, no runner defined for target",
triple = target
))
.with_stdout_contains("test test_foo ... ok")
Expand Down Expand Up @@ -595,6 +596,7 @@ fn no_cross_doctests() {
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target/{triple}/debug/deps/foo-[..][EXE]
[DOCTEST] Skipping doctests, no runner defined for target
",
triple = target
))
Expand Down Expand Up @@ -1223,7 +1225,8 @@ fn cross_test_dylib() {
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target/{arch}/debug/deps/foo-[..][EXE]
[RUNNING] target/{arch}/debug/deps/test-[..][EXE]",
[RUNNING] target/{arch}/debug/deps/test-[..][EXE]
[DOCTEST] Skipping doctests, no runner defined for target",
arch = cross_compile::alternate()
))
.with_stdout_contains_n("test foo ... ok", 2)
Expand Down

0 comments on commit 8c93de6

Please sign in to comment.