From 8c93de6a827952ab1341e28be923a2aab221f3c7 Mon Sep 17 00:00:00 2001 From: Dario Gonzalez Date: Fri, 26 Apr 2019 14:05:37 -0700 Subject: [PATCH] Added ability to crosscompile doctests --- src/cargo/core/compiler/compilation.rs | 2 +- src/cargo/ops/cargo_test.rs | 18 +++++++++++++----- tests/testsuite/cross_compile.rs | 7 +++++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index dcd2e1923bf..35dc7e26656 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -163,7 +163,7 @@ impl<'cfg> Compilation<'cfg> { self.fill_env(process(cmd), pkg, true) } - fn target_runner(&self) -> &Option<(PathBuf, Vec)> { + pub fn target_runner(&self) -> &Option<(PathBuf, Vec)> { &self.target_runner } diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index 1079df47efa..0bb3a65c687 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -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 { @@ -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); @@ -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()))?; diff --git a/tests/testsuite/cross_compile.rs b/tests/testsuite/cross_compile.rs index 671afe7003a..c7121d9a077 100644 --- a/tests/testsuite/cross_compile.rs +++ b/tests/testsuite/cross_compile.rs @@ -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") @@ -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 )) @@ -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)