diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index 71a81cfe5d5..c37183a3310 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -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>, @@ -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>, D::Error> @@ -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.89", 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)?, diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index d5f282c22ce..bde55875141 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -176,7 +176,6 @@ fn run_doc_tests( ) -> Result, 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 { @@ -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)?; @@ -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)); diff --git a/src/doc/src/reference/unstable.md b/src/doc/src/reference/unstable.md index 114543dca12..2a45f54f6a9 100644 --- a/src/doc/src/reference/unstable.md +++ b/src/doc/src/reference/unstable.md @@ -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. @@ -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) @@ -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.89. Running doctests with `cargo test` will now honor the `--target` flag. diff --git a/tests/testsuite/artifact_dep.rs b/tests/testsuite/artifact_dep.rs index fc4b8f63e4a..3da74c19819 100644 --- a/tests/testsuite/artifact_dep.rs +++ b/tests/testsuite/artifact_dep.rs @@ -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; } @@ -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(); diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index 52cd4e702c3..fd945b8b60f 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -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 diff --git a/tests/testsuite/cargo/z_help/stdout.term.svg b/tests/testsuite/cargo/z_help/stdout.term.svg index b8fc4407b7c..0468eb61bc2 100644 --- a/tests/testsuite/cargo/z_help/stdout.term.svg +++ b/tests/testsuite/cargo/z_help/stdout.term.svg @@ -1,4 +1,4 @@ - +