Skip to content

Stabilize doctest-xcompile #15462

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,6 @@ unstable_cli_options!(
codegen_backend: bool = ("Enable the `codegen-backend` option in profiles in .cargo/config.toml file"),
config_include: bool = ("Enable the `include` key in config files"),
direct_minimal_versions: bool = ("Resolve minimal dependency versions instead of maximum (direct dependencies only)"),
doctest_xcompile: bool = ("Compile and run doctests for non-host target using runner config"),
dual_proc_macros: bool = ("Build proc-macros for both the host and the target"),
feature_unification: bool = ("Enable new feature unification modes in workspaces"),
features: Option<Vec<String>>,
Expand Down Expand Up @@ -879,6 +878,8 @@ const STABILIZED_LINTS: &str = "The `[lints]` table is now always available.";
const STABILIZED_CHECK_CFG: &str =
"Compile-time checking of conditional (a.k.a. `-Zcheck-cfg`) is now always enabled.";

const STABILIZED_DOCTEST_XCOMPILE: &str = "Doctest cross-compiling is now always enabled.";

fn deserialize_comma_separated_list<'de, D>(
deserializer: D,
) -> Result<Option<Vec<String>>, D::Error>
Expand Down Expand Up @@ -1275,7 +1276,7 @@ impl CliUnstable {
"codegen-backend" => self.codegen_backend = parse_empty(k, v)?,
"config-include" => self.config_include = parse_empty(k, v)?,
"direct-minimal-versions" => self.direct_minimal_versions = parse_empty(k, v)?,
"doctest-xcompile" => self.doctest_xcompile = parse_empty(k, v)?,
"doctest-xcompile" => stabilized_warn(k, "1.88", STABILIZED_DOCTEST_XCOMPILE),
"dual-proc-macros" => self.dual_proc_macros = parse_empty(k, v)?,
"feature-unification" => self.feature_unification = parse_empty(k, v)?,
"gc" => self.gc = parse_empty(k, v)?,
Expand Down
43 changes: 9 additions & 34 deletions src/cargo/ops/cargo_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ fn run_doc_tests(
) -> Result<Vec<UnitTestError>, CliError> {
let gctx = ws.gctx();
let mut errors = Vec::new();
let doctest_xcompile = gctx.cli_unstable().doctest_xcompile;
let color = gctx.shell().color_choice();

for doctest_info in &compilation.to_doc_test {
Expand All @@ -189,28 +188,6 @@ fn run_doc_tests(
env,
} = doctest_info;

if !doctest_xcompile {
match unit.kind {
CompileKind::Host => {}
CompileKind::Target(target) => {
if target.short_name() != compilation.host {
// Skip doctests, -Zdoctest-xcompile not enabled.
gctx.shell().verbose(|shell| {
shell.note(format!(
"skipping doctests for {} ({}), \
cross-compilation doctests are not yet supported\n\
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#doctest-xcompile \
for more information.",
unit.pkg,
unit.target.description_named()
))
})?;
continue;
}
}
}
}

gctx.shell().status("Doc-tests", unit.target.name())?;
let mut p = compilation.rustdoc_process(unit, *script_meta)?;

Expand All @@ -237,19 +214,17 @@ fn run_doc_tests(
p.arg("--target").arg(target.rustc_target());
}

if doctest_xcompile {
if let Some((runtool, runtool_args)) = compilation.target_runner(unit.kind) {
p.arg("--test-runtool").arg(runtool);
for arg in runtool_args {
p.arg("--test-runtool-arg").arg(arg);
}
}
if let Some(linker) = linker {
let mut joined = OsString::from("linker=");
joined.push(linker);
p.arg("-C").arg(joined);
if let Some((runtool, runtool_args)) = compilation.target_runner(unit.kind) {
p.arg("--test-runtool").arg(runtool);
for arg in runtool_args {
p.arg("--test-runtool-arg").arg(arg);
}
}
if let Some(linker) = linker {
let mut joined = OsString::from("linker=");
joined.push(linker);
p.arg("-C").arg(joined);
}

if unit.profile.panic != PanicStrategy::Unwind {
p.arg("-C").arg(format!("panic={}", unit.profile.panic));
Expand Down
20 changes: 4 additions & 16 deletions src/doc/src/reference/unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ Each new feature described below should explain how to use it.
* [root-dir](#root-dir) --- Controls the root directory relative to which paths are printed
* Compile behavior
* [mtime-on-use](#mtime-on-use) --- Updates the last-modified timestamp on every dependency every time it is used, to provide a mechanism to delete unused artifacts.
* [doctest-xcompile](#doctest-xcompile) --- Supports running doctests with the `--target` flag.
* [build-std](#build-std) --- Builds the standard library instead of using pre-built binaries.
* [build-std-features](#build-std-features) --- Sets features to use with the standard library.
* [binary-dep-depinfo](#binary-dep-depinfo) --- Causes the dep-info file to track binary dependencies.
Expand Down Expand Up @@ -278,21 +277,6 @@ Available template variables:
The `-Zroot-dir` flag sets the root directory relative to which paths are printed.
This affects both diagnostics and paths emitted by the `file!()` macro.

## doctest-xcompile
* Tracking Issue: [#7040](https://github.com/rust-lang/cargo/issues/7040)
* Tracking Rustc Issue: [#64245](https://github.com/rust-lang/rust/issues/64245)

This flag changes `cargo test`'s behavior when handling doctests when
a target is passed. Currently, if a target is passed that is different
from the host cargo will simply skip testing doctests. If this flag is
present, cargo will continue as normal, passing the tests to doctest,
while also passing it a `--target` option, as well as passing along
information from `.cargo/config.toml`. See the rustc issue for more information.

```sh
cargo test --target foo -Zdoctest-xcompile
```

## Build-plan
* Tracking Issue: [#5579](https://github.com/rust-lang/cargo/issues/5579)

Expand Down Expand Up @@ -2171,3 +2155,7 @@ See [`cargo fix --edition`](../commands/cargo-fix.md) and [The Edition Guide](..

Support for automatically deleting old files was stabilized in Rust 1.88.
More information can be found in the [config chapter](config.md#cache).

## doctest-xcompile

Doctest cross-compiling is now unconditionally enabled starting in Rust 1.88. Running doctests with `cargo test` will now honor the `--target` flag.
32 changes: 8 additions & 24 deletions tests/testsuite/artifact_dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ fn non_build_script_deps_adopt_specified_target_unconditionally() {
}

#[cargo_test]
fn no_cross_doctests_works_with_artifacts() {
fn cross_doctests_works_with_artifacts() {
if cross_compile::disabled() {
return;
}
Expand Down Expand Up @@ -1302,40 +1302,24 @@ fn no_cross_doctests_works_with_artifacts() {
println!("c");
let target = cross_compile::alternate();

// This will build the library, but does not build or run doc tests.
// This should probably be a warning or error.
p.cargo("test -Z bindeps -v --doc --target")
.arg(&target)
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr_data(str![[r#"
[COMPILING] bar v0.5.0 ([ROOT]/foo/bar)
[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..]--target [ALT_TARGET] [..]
[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/main.rs [..]--target [ALT_TARGET] [..]
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[RUNNING] `rustc --crate-name foo [..]`
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[NOTE] skipping doctests for foo v0.0.1 ([ROOT]/foo) (lib), cross-compilation doctests are not yet supported
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#doctest-xcompile for more information.

"#]])
.run();

if !cross_compile::can_run_on_host() {
return;
}

// This tests the library, but does not run the doc tests.
p.cargo("test -Z bindeps -v --target")
.arg(&target)
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr_data(str![[r#"
[FRESH] bar v0.5.0 ([ROOT]/foo/bar)
[COMPILING] bar v0.5.0 ([ROOT]/foo/bar)
[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..]--target [ALT_TARGET] [..]
[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/main.rs [..]--target [ALT_TARGET] [..]
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[RUNNING] `rustc --crate-name foo [..]--test[..]
[RUNNING] `rustc --crate-name foo [..]
[RUNNING] `rustc --crate-name foo [..]
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `[ROOT]/foo/target/[ALT_TARGET]/debug/deps/foo-[HASH][EXE]`
[NOTE] skipping doctests for foo v0.0.1 ([ROOT]/foo) (lib), cross-compilation doctests are not yet supported
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#doctest-xcompile for more information.
[DOCTEST] foo
[RUNNING] `rustdoc [..]--test src/lib.rs --test-run-directory [ROOT]/foo --target [ALT_TARGET] [..]

"#]])
.run();
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5600,10 +5600,10 @@ test check_target ... ok
"#]])
.run();

// Remove check once 1.88 is stable
if cargo_test_support::is_nightly() {
p.cargo("test --workspace -Z doctest-xcompile --doc --target")
p.cargo("test --workspace --doc --target")
.arg(&target)
.masquerade_as_nightly_cargo(&["doctest-xcompile"])
.with_stdout_data(str![[r#"
...
test foo/src/lib.rs - (line 2) ... ok
Expand Down
66 changes: 32 additions & 34 deletions tests/testsuite/cargo/z_help/stdout.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading