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

Merged
merged 2 commits into from
May 14, 2025
Merged

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
@@ -5600,10 +5600,10 @@ test check_target ... ok
"#]])
.run();

// Remove check once 1.87 is stable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why 1.87 not 1.88?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this was written a long time ago, and I missed updating this line. 😆

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but looks like we'll miss 1.88 after 10-day FCP 😬

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

@ehuss ehuss force-pushed the stabilize-doctest-xcompile branch from 3e7aaf4 to 83a6acd Compare May 6, 2025 16:33
@rfcbot rfcbot added finished-final-comment-period FCP complete to-announce and removed final-comment-period FCP — a period for last comments before action is taken labels May 14, 2025
@rfcbot
Copy link
Collaborator

rfcbot commented May 14, 2025

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ehuss feel free to merge it after updating all 1.88 occurrences to 1.89

This stabilizes the doctest-xcompile feature by unconditionally enabling
it.
@ehuss ehuss force-pushed the stabilize-doctest-xcompile branch from 83a6acd to 4194703 Compare May 14, 2025 15:54
@ehuss ehuss added this pull request to the merge queue May 14, 2025
Merged via the queue into rust-lang:master with commit 47c911e May 14, 2025
23 checks passed
@ehuss ehuss deleted the stabilize-doctest-xcompile branch May 14, 2025 18:23
bors added a commit to rust-lang-ci/rust that referenced this pull request May 16, 2025
Update cargo

5 commits in 056f5f4f3c100cb36b5e9aed2d20b9ea70aae295..47c911e9e6f6461f90ce19142031fe16876a3b95
2025-05-09 14:54:18 +0000 to 2025-05-14 17:53:17 +0000
- Stabilize doctest-xcompile (rust-lang/cargo#15462)
- feat: skip `publish=false` pkg when publishing entire workspace (rust-lang/cargo#15525)
- chore: bump to 0.90.0; update changelog (rust-lang/cargo#15520)
- chore(triagebot): add `[no-mentions]` and `[note]` (rust-lang/cargo#15517)
- add glob pattern support for known_hosts (rust-lang/cargo#15508)

r? ghost
@rustbot rustbot added this to the 1.89.0 milestone May 16, 2025
@RalfJung
Copy link
Member

FYI, this has been causing us some trouble in Miri: we need rustdoc to invoke Miri as the runner in a consistent way. When Miri gets tested in the rustc test suite, that is using beta cargo, but for our users out there it will be nightly cargo.

What we used to do is to just set --test-runtool ourselves (which we can do since cargo invokes cargo-miri as rustdoc binary, and then we do some flag adjustments before invoking the actual rustdoc). That broke when cargo started to set that flag, once this PR landed (we also set target.'cfg(all())'.runner so that Miri is used to run regular tests). So instead I made it so we rely on cargo setting that flag. But then I had to add -Zdoctest-xcompile to ensure Miri's tests still pass in ./x... and then the tests failed in Miri's repo because of the warning that the flag is now stable (and also all our users will see that warning until the next subtree bump). What I ended up doing is use some env vars to detect whether we run in ./x or not and then decide whether to pass -Zdoctest-xcompile or not -- I hope that will work.

Not sure what the less to learn here is, but it would have been good to have some way to consistently invoke old and new cargo such that it behaves in exactly the same way, e.g. by having some way to suppress the warning that using the flag is a NOP as the feature is already stable.

github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request May 19, 2025
Update cargo

5 commits in 056f5f4f3c100cb36b5e9aed2d20b9ea70aae295..47c911e9e6f6461f90ce19142031fe16876a3b95
2025-05-09 14:54:18 +0000 to 2025-05-14 17:53:17 +0000
- Stabilize doctest-xcompile (rust-lang/cargo#15462)
- feat: skip `publish=false` pkg when publishing entire workspace (rust-lang/cargo#15525)
- chore: bump to 0.90.0; update changelog (rust-lang/cargo#15520)
- chore(triagebot): add `[no-mentions]` and `[note]` (rust-lang/cargo#15517)
- add glob pattern support for known_hosts (rust-lang/cargo#15508)

r? ghost
@weihanglo
Copy link
Member

Sorry about the situation Ralf 😞.

e.g. by having some way to suppress the warning that using the flag is a NOP as the feature is already stable.

Cargo now has its own (unstable) linting system, and feel free to propose new lint via this issue template! It is currently limited to handle only Cargo.toml, but I believe eventually it will expand to config.toml and other areas.

but it would have been good to have some way to consistently invoke old and new cargo such that it behaves in exactly the same way

Might not be applicable to this, though the team discussed how to test the compatibility between old and new cargoes. If you have some other ideas, feel free to share!

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 finished-final-comment-period FCP complete S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-cargo Team: Cargo to-announce
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

cross-compilation doctests warning should not be behind verbose flag Tracking issue for cross-compiling doc tests (doctest-xcompile)
5 participants