Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix target for doc test cross compilation #8094

Merged
merged 10 commits into from
Apr 17, 2020
7 changes: 5 additions & 2 deletions src/cargo/ops/cargo_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::ffi::OsString;

use crate::core::compiler::{Compilation, Doctest};
use crate::core::compiler::{Compilation, CompileKind, Doctest};
use crate::core::shell::Verbosity;
use crate::core::Workspace;
use crate::ops;
Expand Down Expand Up @@ -163,7 +163,10 @@ fn run_doc_tests(
.arg(&target.crate_name());

if doctest_xcompile {
p.arg("--target").arg(&compilation.target);
if let CompileKind::Target(target) = options.compile_opts.build_config.requested_kind {
// use `rustc_target()` to properly handle JSON target paths
p.arg("--target").arg(target.rustc_target());
}
p.arg("-Zunstable-options");
p.arg("--enable-per-target-ignores");
}
Expand Down
39 changes: 39 additions & 0 deletions tests/testsuite/cross_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,45 @@ fn no_cross_doctests() {
.run();
}

#[cargo_test]
fn cross_doctests() {
if cross_compile::disabled() || !cross_compile::can_run_on_host() || !is_nightly() {
return;
}

let p = project()
.file(
"src/lib.rs",
r#"
//! ```
//! extern crate foo;
//! assert!(true);
//! ```
"#,
)
.build();

let target = cross_compile::alternate();

// This tests the library and runs the doc tests.
p.cargo("test -v -Z doctest-xcompile --target")
.arg(&target)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be using a json spec target, since that's what this PR is fixing. I think it would be best for it to go in the custom_target.rs module with the other json spec tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that makes sense not sure why I missed that

.masquerade_as_nightly_cargo()
.with_stderr(&format!(
"\
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] `rustc --crate-name foo [..]
[RUNNING] `rustc --crate-name foo [..]--test[..]
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
[RUNNING] `[CWD]/target/{triple}/debug/deps/foo-[..][EXE]`
[DOCTEST] foo
[RUNNING] `rustdoc [..]
",
triple = target
))
.run();
}

#[cargo_test]
fn simple_cargo_run() {
if !cross_compile::can_run_on_host() {
Expand Down