Skip to content

Commit 3e7aaf4

Browse files
committed
Stabilize doctest-xcompile
This stabilizes the doctest-xcompile feature by unconditionally enabling it.
1 parent ab15d58 commit 3e7aaf4

File tree

10 files changed

+91
-292
lines changed

10 files changed

+91
-292
lines changed

src/cargo/core/features.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,6 @@ unstable_cli_options!(
769769
codegen_backend: bool = ("Enable the `codegen-backend` option in profiles in .cargo/config.toml file"),
770770
config_include: bool = ("Enable the `include` key in config files"),
771771
direct_minimal_versions: bool = ("Resolve minimal dependency versions instead of maximum (direct dependencies only)"),
772-
doctest_xcompile: bool = ("Compile and run doctests for non-host target using runner config"),
773772
dual_proc_macros: bool = ("Build proc-macros for both the host and the target"),
774773
feature_unification: bool = ("Enable new feature unification modes in workspaces"),
775774
features: Option<Vec<String>>,
@@ -878,6 +877,8 @@ const STABILIZED_LINTS: &str = "The `[lints]` table is now always available.";
878877
const STABILIZED_CHECK_CFG: &str =
879878
"Compile-time checking of conditional (a.k.a. `-Zcheck-cfg`) is now always enabled.";
880879

880+
const STABILIZED_DOCTEST_XCOMPILE: &str = "Doctest cross-compiling is now always enabled.";
881+
881882
fn deserialize_comma_separated_list<'de, D>(
882883
deserializer: D,
883884
) -> Result<Option<Vec<String>>, D::Error>
@@ -1274,7 +1275,7 @@ impl CliUnstable {
12741275
"codegen-backend" => self.codegen_backend = parse_empty(k, v)?,
12751276
"config-include" => self.config_include = parse_empty(k, v)?,
12761277
"direct-minimal-versions" => self.direct_minimal_versions = parse_empty(k, v)?,
1277-
"doctest-xcompile" => self.doctest_xcompile = parse_empty(k, v)?,
1278+
"doctest-xcompile" => stabilized_warn(k, "1.88", STABILIZED_DOCTEST_XCOMPILE),
12781279
"dual-proc-macros" => self.dual_proc_macros = parse_empty(k, v)?,
12791280
"feature-unification" => self.feature_unification = parse_empty(k, v)?,
12801281
"gc" => self.gc = parse_empty(k, v)?,

src/cargo/ops/cargo_test.rs

+9-34
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ fn run_doc_tests(
176176
) -> Result<Vec<UnitTestError>, CliError> {
177177
let gctx = ws.gctx();
178178
let mut errors = Vec::new();
179-
let doctest_xcompile = gctx.cli_unstable().doctest_xcompile;
180179
let color = gctx.shell().color_choice();
181180

182181
for doctest_info in &compilation.to_doc_test {
@@ -189,28 +188,6 @@ fn run_doc_tests(
189188
env,
190189
} = doctest_info;
191190

192-
if !doctest_xcompile {
193-
match unit.kind {
194-
CompileKind::Host => {}
195-
CompileKind::Target(target) => {
196-
if target.short_name() != compilation.host {
197-
// Skip doctests, -Zdoctest-xcompile not enabled.
198-
gctx.shell().verbose(|shell| {
199-
shell.note(format!(
200-
"skipping doctests for {} ({}), \
201-
cross-compilation doctests are not yet supported\n\
202-
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#doctest-xcompile \
203-
for more information.",
204-
unit.pkg,
205-
unit.target.description_named()
206-
))
207-
})?;
208-
continue;
209-
}
210-
}
211-
}
212-
}
213-
214191
gctx.shell().status("Doc-tests", unit.target.name())?;
215192
let mut p = compilation.rustdoc_process(unit, *script_meta)?;
216193

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

240-
if doctest_xcompile {
241-
if let Some((runtool, runtool_args)) = compilation.target_runner(unit.kind) {
242-
p.arg("--test-runtool").arg(runtool);
243-
for arg in runtool_args {
244-
p.arg("--test-runtool-arg").arg(arg);
245-
}
246-
}
247-
if let Some(linker) = linker {
248-
let mut joined = OsString::from("linker=");
249-
joined.push(linker);
250-
p.arg("-C").arg(joined);
217+
if let Some((runtool, runtool_args)) = compilation.target_runner(unit.kind) {
218+
p.arg("--test-runtool").arg(runtool);
219+
for arg in runtool_args {
220+
p.arg("--test-runtool-arg").arg(arg);
251221
}
252222
}
223+
if let Some(linker) = linker {
224+
let mut joined = OsString::from("linker=");
225+
joined.push(linker);
226+
p.arg("-C").arg(joined);
227+
}
253228

254229
if unit.profile.panic != PanicStrategy::Unwind {
255230
p.arg("-C").arg(format!("panic={}", unit.profile.panic));

src/doc/src/reference/unstable.md

+4-16
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ Each new feature described below should explain how to use it.
8484
* [root-dir](#root-dir) --- Controls the root directory relative to which paths are printed
8585
* Compile behavior
8686
* [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.
87-
* [doctest-xcompile](#doctest-xcompile) --- Supports running doctests with the `--target` flag.
8887
* [build-std](#build-std) --- Builds the standard library instead of using pre-built binaries.
8988
* [build-std-features](#build-std-features) --- Sets features to use with the standard library.
9089
* [binary-dep-depinfo](#binary-dep-depinfo) --- Causes the dep-info file to track binary dependencies.
@@ -277,21 +276,6 @@ Avaiable template variables:
277276
The `-Zroot-dir` flag sets the root directory relative to which paths are printed.
278277
This affects both diagnostics and paths emitted by the `file!()` macro.
279278

280-
## doctest-xcompile
281-
* Tracking Issue: [#7040](https://github.com/rust-lang/cargo/issues/7040)
282-
* Tracking Rustc Issue: [#64245](https://github.com/rust-lang/rust/issues/64245)
283-
284-
This flag changes `cargo test`'s behavior when handling doctests when
285-
a target is passed. Currently, if a target is passed that is different
286-
from the host cargo will simply skip testing doctests. If this flag is
287-
present, cargo will continue as normal, passing the tests to doctest,
288-
while also passing it a `--target` option, as well as passing along
289-
information from `.cargo/config.toml`. See the rustc issue for more information.
290-
291-
```sh
292-
cargo test --target foo -Zdoctest-xcompile
293-
```
294-
295279
## Build-plan
296280
* Tracking Issue: [#5579](https://github.com/rust-lang/cargo/issues/5579)
297281

@@ -2153,3 +2137,7 @@ See [`cargo fix --edition`](../commands/cargo-fix.md) and [The Edition Guide](..
21532137

21542138
Support for automatically deleting old files was stabilized in Rust 1.88.
21552139
More information can be found in the [config chapter](config.md#cache).
2140+
2141+
## doctest-xcompile
2142+
2143+
Doctest cross-compiling is now unconditionally enabled starting in Rust 1.88. Running doctests with `cargo test` will now honor the `--target` flag.

tests/testsuite/artifact_dep.rs

+8-24
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ fn non_build_script_deps_adopt_specified_target_unconditionally() {
12461246
}
12471247

12481248
#[cargo_test]
1249-
fn no_cross_doctests_works_with_artifacts() {
1249+
fn cross_doctests_works_with_artifacts() {
12501250
if cross_compile::disabled() {
12511251
return;
12521252
}
@@ -1302,40 +1302,24 @@ fn no_cross_doctests_works_with_artifacts() {
13021302
println!("c");
13031303
let target = cross_compile::alternate();
13041304

1305-
// This will build the library, but does not build or run doc tests.
1306-
// This should probably be a warning or error.
1307-
p.cargo("test -Z bindeps -v --doc --target")
1308-
.arg(&target)
1309-
.masquerade_as_nightly_cargo(&["bindeps"])
1310-
.with_stderr_data(str![[r#"
1311-
[COMPILING] bar v0.5.0 ([ROOT]/foo/bar)
1312-
[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/lib.rs [..]--target [ALT_TARGET] [..]
1313-
[RUNNING] `rustc --crate-name bar --edition=2015 bar/src/main.rs [..]--target [ALT_TARGET] [..]
1314-
[COMPILING] foo v0.0.1 ([ROOT]/foo)
1315-
[RUNNING] `rustc --crate-name foo [..]`
1316-
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1317-
[NOTE] skipping doctests for foo v0.0.1 ([ROOT]/foo) (lib), cross-compilation doctests are not yet supported
1318-
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#doctest-xcompile for more information.
1319-
1320-
"#]])
1321-
.run();
1322-
13231305
if !cross_compile::can_run_on_host() {
13241306
return;
13251307
}
13261308

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

tests/testsuite/build_script.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5600,10 +5600,10 @@ test check_target ... ok
56005600
"#]])
56015601
.run();
56025602

5603+
// Remove check once 1.88 is stable
56035604
if cargo_test_support::is_nightly() {
5604-
p.cargo("test --workspace -Z doctest-xcompile --doc --target")
5605+
p.cargo("test --workspace --doc --target")
56055606
.arg(&target)
5606-
.masquerade_as_nightly_cargo(&["doctest-xcompile"])
56075607
.with_stdout_data(str![[r#"
56085608
...
56095609
test foo/src/lib.rs - (line 2) ... ok

tests/testsuite/cargo/z_help/stdout.term.svg

+31-33
Loading

0 commit comments

Comments
 (0)