Skip to content
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

Fix LTO with doctests. #8657

Merged
merged 1 commit into from
Aug 28, 2020
Merged

Fix LTO with doctests. #8657

merged 1 commit into from
Aug 28, 2020

Conversation

ehuss
Copy link
Contributor

@ehuss ehuss commented Aug 28, 2020

This fixes an issue where cargo test --release would fail to run doctests if LTO is set in profile.release or profile.bench.

The issue is that dependencies were built with -Clinker-plugin-lto, but the final rustdoc invocation did not issue -C lto. This causes a link failure (or crash!) because the necessary object code was missing. This is because rustdoc historically did not support codegen flags, so Cargo has never passed them in. Rustdoc now supports codegen flags (via rust-lang/rust#63827), so it should be safe to start passing them in. For now, I am only adding LTO, but more should be added in the future.

There are two bugs here. One is that LTO flags aren't passed to rustdoc. The other is that the "doctest" unit was using the wrong profile (it was using dev/release when it should be using test/bench).

There are two distinct scenarios here. One where just release has lto set. And one where both release and bench have lto set. This is relevant because LTO mostly cares about what the final artifact wants, and in the case where bench does not have lto set, then LTO will not be used for tests. This will hopefully be a little cleaner in the future when #6988 is stabilized, which causes the test/bench profiles to inherit from the dev/bench profiles, which means you won't need to manually synchronize the test/bench profiles with dev/release.

Fixes #8654

@rust-highfive
Copy link

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 28, 2020
@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Collaborator

bors commented Aug 28, 2020

📌 Commit 5bbad10 has been approved by alexcrichton

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 28, 2020
@bors
Copy link
Collaborator

bors commented Aug 28, 2020

⌛ Testing commit 5bbad10 with merge 55e59bd...

@bors
Copy link
Collaborator

bors commented Aug 28, 2020

☀️ Test successful - checks-actions
Approved by: alexcrichton
Pushing 55e59bd to master...

@bors bors merged commit 55e59bd into rust-lang:master Aug 28, 2020
ehuss pushed a commit to ehuss/cargo that referenced this pull request Aug 28, 2020
Fix LTO with doctests.

This fixes an issue where `cargo test --release` would fail to run doctests if LTO is set in `profile.release` or `profile.bench`.

The issue is that dependencies were built with `-Clinker-plugin-lto`, but the final rustdoc invocation did not issue `-C lto`. This causes a link failure (or crash!) because the necessary object code was missing.  This is because rustdoc historically did not support codegen flags, so Cargo has never passed them in.  Rustdoc now supports codegen flags (via rust-lang/rust#63827), so it should be safe to start passing them in.  For now, I am only adding LTO, but more should be added in the future.

There are two bugs here. One is that LTO flags aren't passed to rustdoc. The other is that the "doctest" unit was using the wrong profile (it was using dev/release when it should be using test/bench).

There are two distinct scenarios here.  One where just `release` has `lto` set.  And one where both `release` and `bench` have `lto` set.  This is relevant because LTO mostly cares about what the final artifact wants, and in the case where `bench` does not have `lto` set, then LTO will not be used for tests. This will hopefully be a little cleaner in the future when rust-lang#6988 is stabilized, which causes the test/bench profiles to *inherit* from the dev/bench profiles, which means you won't need to manually synchronize the test/bench profiles with dev/release.

Fixes rust-lang#8654
bors added a commit that referenced this pull request Aug 28, 2020
[beta] Fix LTO with doctests.

Beta packports:
* #8653 Fix cache_messages::rustdoc test broken on beta. — so that CI tests pass
* #8648 Add spaces after -C and -Z flags for consistency — so that #8657 can be merged
* #8657 Fix LTO with doctests.

Although the LTO regression is on 1.46, I probably won't do a stable backport even if there is a point release, as I think it would be good to have sufficient time for testing on nightly, and I don't want to rush it. I'm willing to reconsider that, though.
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 31, 2020
Update cargo

8 commits in 51b66125ba97d2906f461b3f4e0408f206299bb6..126907a7cfccbe93778530e6a6bbaa3adb6c515c
2020-08-19 20:22:52 +0000 to 2020-08-31 20:42:11 +0000
- Fix flakiness in close_output test (rust-lang/cargo#8668)
- Reload unstable table from config file in `reload_rooted_at` (rust-lang/cargo#8656)
- Bump to 0.49.0, update changelog (rust-lang/cargo#8659)
- Fix LTO with doctests. (rust-lang/cargo#8657)
- Add spaces after -C and -Z flags for consistency (rust-lang/cargo#8648)
- Fix cache_messages::rustdoc test broken on beta. (rust-lang/cargo#8653)
- fix: remove unnecessary allocations (rust-lang/cargo#8641)
- Fixed a spelling and some clippy warnings (rust-lang/cargo#8637)
@ehuss ehuss modified the milestones: 1.48.0, 1.47.0 Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression: lto = true in build.rs causes cargo test --release --doc to fail to link
4 participants