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

Conversation

ehuss
Copy link
Contributor

@ehuss ehuss commented Apr 28, 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 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 config option is honored for using a custom linker.

Already stabilized in rustdoc is the ability to ignore tests per-target.

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 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, 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

Test coverage

Cargo tests:

Rustdoc tests:

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).

@ehuss ehuss added the T-cargo Team: Cargo label Apr 28, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 28, 2025

r? @weihanglo

rustbot has assigned @weihanglo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-documenting-cargo-itself Area: Cargo's documentation A-unstable Area: nightly unstable support Command-test S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 28, 2025
@ehuss
Copy link
Contributor Author

ehuss commented Apr 28, 2025

@rust-lang/cargo I'm proposing to stabilize this, though I think it should wait until 1.89. I figured I'd get this process started in case anyone had any concerns or needs time to look at it.

@rfcbot fcp merge

@rfcbot
Copy link
Collaborator

rfcbot commented Apr 28, 2025

Team member @ehuss has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period An FCP proposal has started, but not yet signed off. disposition-merge FCP with intent to merge labels Apr 28, 2025
@ehuss ehuss force-pushed the stabilize-doctest-xcompile branch from 2603268 to fccb97d Compare April 29, 2025 01:08
@ehuss ehuss moved this to FCP merge in Cargo status tracker Apr 29, 2025
@rfcbot rfcbot added final-comment-period FCP — a period for last comments before action is taken and removed proposed-final-comment-period An FCP proposal has started, but not yet signed off. labels May 4, 2025
@rfcbot
Copy link
Collaborator

rfcbot commented May 4, 2025

🔔 This is now entering its final comment period, as per the review above. 🔔

@ehuss ehuss force-pushed the stabilize-doctest-xcompile branch from fccb97d to 3e7aaf4 Compare May 4, 2025 15:12
@rustbot

This comment has been minimized.

This stabilizes the doctest-xcompile feature by unconditionally enabling
it.
@ehuss ehuss force-pushed the stabilize-doctest-xcompile branch from 3e7aaf4 to 83a6acd Compare May 6, 2025 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-documenting-cargo-itself Area: Cargo's documentation A-unstable Area: nightly unstable support Command-test disposition-merge FCP with intent to merge final-comment-period FCP — a period for last comments before action is taken S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-cargo Team: Cargo
Projects
Status: FCP merge
4 participants