Skip to content

cross-compilation doctests warning should not be behind verbose flag #12118

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

Closed
timfish opened this issue May 10, 2023 · 19 comments · Fixed by #15462
Closed

cross-compilation doctests warning should not be behind verbose flag #12118

timfish opened this issue May 10, 2023 · 19 comments · Fixed by #15462
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. C-bug Category: bug E-easy Experience: Easy P-low Priority: Low S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing. Z-doctest-xcompile Nightly: doctest-xcompile

Comments

@timfish
Copy link

timfish commented May 10, 2023

Main tracking issue: #7040

Problem

I just spent a lot longer than I'm willing to admit trying to work out why my doctests were not running. After working out I'd done everything correctly I finally tried --verbose and found the warning about cross-compilation not being supported.

cargo test completes successfully and I've not even known that the doctests have been skipped for months! Why is this warning hidden behind the verbose flag?

Steps

Create a src file with failing doc tests:
lib.rs

/// ```
/// panic("something')
/// ```
pub fn my_function() { }

Ensure you're building for another target. For me, this was on an M1 mac with the following .cargo/config to make this a cross platform build:

[build]
target = "x86_64-apple-darwin"

Run cargo test --doc

Results in no output after the build output.

Version

cargo 1.69.0

@timfish timfish added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels May 10, 2023
@weihanglo
Copy link
Member

It was an intentional choice in #10132. Warning for every doctest target may be noisy. Could be improved by warning just once in normal mode if there is a cross-compile doctest, hinting people to use --verbose to see the full list of skipped doctest targets.

Relevant code is here:

CompileKind::Target(target) => {
if target.short_name() != compilation.host {
// Skip doctests, -Zdoctest-xcompile not enabled.
config.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;
}
}

@weihanglo weihanglo added A-diagnostics Area: Error and warning messages generated by Cargo itself. S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing. Z-doctest-xcompile Nightly: doctest-xcompile and removed S-triage Status: This issue is waiting on initial triage. labels May 10, 2023
@weihanglo
Copy link
Member

Just a friendly reminder. It would be great for collaboration if people always strive to provide reproducible steps and version information for their issues. That may increase the chance for anyone wanting to fix gets started sooner.

@timfish
Copy link
Author

timfish commented May 10, 2023

provide reproducible steps and version information for their issues

Apologies. Just added these.

@weihanglo weihanglo added E-easy Experience: Easy P-low Priority: Low labels May 27, 2023
@weihanglo
Copy link
Member

Labeled as P-low Priority: Low as we are considering to stabilize -Zdoctest-xcompile, so this warning may be unnecessary. There is no ETA though.

@1garo
Copy link

1garo commented Jun 12, 2023

Would be okay if I work on this one? @weihanglo

@1garo
Copy link

1garo commented Jun 12, 2023

I'm just having trouble building, I been having the message below in some crates:

error[E0658]: use of unstable library feature 'once_cell'

Any ideia?

@Rustin170506
Copy link
Member

Try to use the latest stable version or nightly version rustc.

@1garo
Copy link

1garo commented Jun 12, 2023

Try to use the latest stable version or nightly version rustc.

Thanks! Now I'm having some problem with linking error: linking with cc failed: exit status: 1 when cargo build, but cargo check is fine!

$ rustput -V
rustc 1.72.0-nightly

Mac M1 ventura 13.2

image

@weihanglo
Copy link
Member

Labeled as P-low Priority: Low as we are considering to stabilize -Zdoctest-xcompile, so this warning may be unnecessary. There is no ETA though.

As it is labeled as P-low and S-needs-mentor, I'd suggest working on other issues if you're interested in contributing Cargo.

@progressive-galib
Copy link

progressive-galib commented Dec 11, 2024

Labeled as P-low Priority: Low as we are considering to stabilize -Zdoctest-xcompile, so this warning may be unnecessary. There is no ETA though.

has doctest cross complie stabilized ? if not i am going to work on this issue #12118 and warn when not verbose.

@progressive-galib
Copy link

nearly done, now i need some crate that needs doctest to check the warning is working.

progressive-galib added a commit to progressive-galib/cargo that referenced this issue Dec 11, 2024
…ipping doctest on xcompiling even when not under verbose flag
@progressive-galib
Copy link

done

@progressive-galib
Copy link

merge please @weihanglo

@weihanglo
Copy link
Member

@progressive-galib

Since @ehuss has stepped in #14920 and got some opinions, I would let them take over the review.

Per my early comment #12118 (comment), I still prefer we push forward the stabilization of #7040, though it is a cross-team effort and currently stuck with some incompatibility rust-lang/rust#64245 (comment).

@progressive-galib
Copy link

i think until we stabilize doctest cross compile we should merge it and remove it one that is stable.

@weihanglo
Copy link
Member

I have no preference of merging now or not.

@progressive-galib
Copy link

@ehuss have you gotten any more second opinions and third opinions ?

@progressive-galib
Copy link

@weihanglo still no review ?

@weihanglo
Copy link
Member

I've reviewed. See #12118 (comment).

github-merge-queue bot pushed a commit that referenced this issue May 14, 2025
This stabilizes the doctest-xcompile feature by unconditionally enabling
it.

Closes #7040
Closes #12118

## What is being stabilized?

This changes it so that cargo will run doctests when using the
`--target` flag for a target that is not the host. Previously, cargo
would ignore doctests (and show a note if passing `--verbose`).

A wrapper for running the doctest can be specified with the
[`target.*.runner`](https://doc.rust-lang.org/cargo/reference/config.html#targettriplerunner)
configuration option (which is powered by the `--test-runtool` rustdoc
flag). This would typically be something like qemu to run under
emulation. It is my understanding that this should work just like
running other kinds of tests.

Additionally, the
[`target.*.linker`](https://doc.rust-lang.org/cargo/reference/config.html#targettriplelinker)
config option is honored for using a custom linker.

Already stabilized in rustdoc is the ability to [ignore tests
per-target](https://doc.rust-lang.org/nightly/rustdoc/write-documentation/documentation-tests.html#ignoring-targets).

## Motivation

The lack of doctest cross-compile support has always been simply due to
the lack of functionality in rustdoc to support this. Rustdoc gained the
ability to cross-compile doctests some time ago, but there were
additional flags like the test runner that were not stabilized until
just recently.

This is intended to ensure that projects have full test coverage even
when doing cross-compilation. It can be
[surprising](#12118) to some
that this was not happening, particularly since cargo is silent about
it.

## Risks

The cargo team had several conversations about how to roll out this
feature. Ultimately we decided to enable it unconditionally with the
understanding that most projects will probably want to have their
doctests covered, and that any breakage will be a local concern that can
be resolved by either fixing the test or ignoring the target.

Tests in rust-lang/rust run into this issue, [particularly on
android](rust-lang/rust#119147 (comment)),
and those will need to be fixed before this reaches beta. This is
something I am looking into.

Some cross-compiling scenarios may need codegen flags that are not
supported. It's not clear how common this will be, or if ignoring will
be a solution, or how difficult it would be to update rustdoc and cargo
to support these. Additionally, the split between RUSTFLAGS and
RUSTDOCFLAGS can be cumbersome.

## Implementation history

- rust-lang/rust#60387 -- Support added to
rustdoc to support the `--target` flag and runtool and
per-target-ignores.
- #6892 -- Initial support in
cargo.
- #7391 -- Added unstable
documentation.
- #8094 -- Fix target for doc
test cross compilation
- #8358 -- Fixed regression with
`--target=HOST` not working on stable.
- #10132 -- Added note about
doctests not running (under `--verbose`).
- rust-lang/rust#112751 -- Fixed
`--test-run-directory` interaction with `--test-runtool`.
- rust-lang/rust#137096 -- Stabilization (and
rename) of the rustdoc `--test-runtool` and `--test-runtool-arg` CLI
args, and drops `--enable-per-target-ignores` unconditionally enabling
it.

## Test coverage

Cargo tests:
-
[artifact_dep::cross_doctests_works_with_artifacts](https://github.com/ehuss/cargo/blob/56c08f84e28d3653ae0c842f331a226738108188/tests/testsuite/artifact_dep.rs#L1248-L1326)
-- Checks that doctest has access to the artifact dependencies.
-
[build_script::duplicate_script_with_extra_env](https://github.com/ehuss/cargo/blob/56c08f84e28d3653ae0c842f331a226738108188/tests/testsuite/build_script.rs#L5514-L5614)
-- Checks that build-script env and cfg values are correctly handled on
host versus target when cross running doctests.
-
[cross_compile::cross_tests](https://github.com/ehuss/cargo/blob/56c08f84e28d3653ae0c842f331a226738108188/tests/testsuite/cross_compile.rs#L416-L502)
-- Basic test that cross-compiled tests work.
-
[cross_compile::doctest_xcompile_linker](https://github.com/ehuss/cargo/blob/56c08f84e28d3653ae0c842f331a226738108188/tests/testsuite/cross_compile.rs#L1139-L1182)
-- Checks that the linker config argument works.
-
[custom_target::custom_target_minimal](https://github.com/ehuss/cargo/blob/56c08f84e28d3653ae0c842f331a226738108188/tests/testsuite/custom_target.rs#L39-L71)
-- Checks that `.json` targets work with rustdoc cross tests.
-
[test::cargo_test_doctest_xcompile_ignores](https://github.com/ehuss/cargo/blob/56c08f84e28d3653ae0c842f331a226738108188/tests/testsuite/test.rs#L4743-L4777)
-- Checks the `ignore-*` syntax works.
-
[test::cargo_test_doctest_xcompile_runner](https://github.com/ehuss/cargo/blob/2603268cda3e32565ac27ee642f2b755fa590bac/tests/testsuite/test.rs#L4783-L4863)
-- Checks runner with cross doctests.
-
[test::cargo_test_doctest_xcompile_no_runner](https://github.com/ehuss/cargo/blob/2603268cda3e32565ac27ee642f2b755fa590bac/tests/testsuite/test.rs#L4869-L4907)
-- Checks cross doctests without a runner.

Rustdoc tests:
-
[run-make/doctest-runtool](https://github.com/rust-lang/rust/tree/25cdf1f67463c9365d8d83778c933ec7480e940b/tests/run-make/doctests-runtool)
-- Tests behavior of `--test-run-directory` with relative paths of the
runner.
-
[rustdoc/doctest/doctest-runtool](https://github.com/rust-lang/rust/blob/25cdf1f67463c9365d8d83778c933ec7480e940b/tests/rustdoc/doctest/doctest-runtool.rs)
-- Tests for `--test-runtool` and `--test-runtool-arg`.

## Future concerns

There have been some discussions
(rust-lang/testing-devex-team#5) about
changing how doctests are driven. My understanding is that stabilizing
this should not affect those plans, since if cargo becomes the driver,
it will simply need to build things with `--target` and use the
appropriate runner.

## Change notes

This PR changed tests a little:
- artifact_dep::no_cross_doctests_works_with_artifacts was changed now
that doctests actually work.
- cross_compile::cross_tests was changed to properly check doctests.
- cross_compile::no_cross_doctests dropped since it is no longer
relevant.
- standard_lib::doctest didn't need `-Zdoctest-xcompile` since
`-Zbuild-std` no longer uses a target.
- test::cargo_test_doctest_xcompile was removed since it is a duplicate
of cross_compile::cross_tests

I think this should probably wait until the next release cutoff, moving
this to 1.89 (will update the PR accordingly if that happens).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. C-bug Category: bug E-easy Experience: Easy P-low Priority: Low S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing. Z-doctest-xcompile Nightly: doctest-xcompile
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants