-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 doctests linking too many libs. #5651
Conversation
Fixes rust-lang#5650. cc rust-lang#5435 As part of my recent work on profiles, I introduced some situations where a library can be compiled multiple times with different settings. Doctests were greedily grabbing all dependencies for a package, regardless of which target is was for. This can cause doctests to fail if it links multiple copies of the same library. One way to trigger this is `cargo test --release` if you have dependencies, a build script, and `panic="abort"`. There are other (more obscure) ways to trigger it with profile overrides.
r? @matklad (rust_highfive has picked a reviewer for you, use r? to override) |
Notes:
|
Don't take this as any kind of review. For my own reasons, I'd appreciate a more detailed explanation. Specifically someday the resolver is going to grow private dependencies witch will lead to the same crate with different features ending up in the build plan. And I want a heads up of the corner cases we will have to fix when we get there. :-P |
pub to_doc_test: Vec<Package>, | ||
/// Libraries to test with rustdoc. | ||
/// The third value is the list of dependencies. | ||
pub to_doc_test: Vec<(Package, Target, Vec<(Target, PathBuf)>)>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about changing this triple to a struct, so as to make comment not-necessary? It might also be worthwhile to move the
if lib.extension() != Some(OsStr::new("rlib")) && !target.for_host() {
logic to the place where we generate these dependencies?
Thanks @ehuss ! The code looks correct to me, but I wonder if we could centralize decisions about doctest dependencies in one place? Currently we have two filtering steps: when genreating deps and then when we construct command line for rustdoc.
In general, it's fine to remove stuff. I'd love to hear @alexcrichton opinion about this specifically though, because I don't know the original rational behind this field. As this is a bug fix, let's not remove stuff right now, but leave a comment noting that this field is probably unused. Should this be backported to beta? |
In rare cases, the profile_for is set incorrectly for this temporary unit used to compute dependencies. However, it's not needed since the RunCustomBuild Unit's parent is already in the map.
- Consolidate logic for determining doctest dependencies. - Use a struct for the doctest info in `Compilation`.
@Eh2406 sure, it's very particular to how the rustdoc libs were collected and a side effect of build scripts, and dealing with
There are multiple parts to the solution:
I'm not aware of any other current issues with compiling a crate multiple times with different settings. There is an issue with |
I think that might be a good idea. I'm not sure how often people run |
Note: This exacerbated an existing bug with how "Fresh" is displayed with doctests. There are some scenarios today where |
ping @matklad, did you want to take another look at this? |
LGTM! @bors r+ @alexcrichton, should we remove |
📌 Commit 478d1ce has been approved by |
Sounds fine by me! |
Fix doctests linking too many libs. Fixes #5650. cc #5435 As part of my recent work on profiles, I introduced some situations where a library can be compiled multiple times with different settings. Doctests were greedily grabbing all dependencies for a package, regardless of which target is was for. This can cause doctests to fail if it links multiple copies of the same library. One way to trigger this is `cargo test --release` if you have dependencies, a build script, and `panic="abort"`. There are other (more obscure) ways to trigger it with profile overrides.
☀️ Test successful - status-appveyor, status-travis |
[BETA] Fix doctests linking too many libs. Backport of #5651.
Some logic which was tweaked around the dependencies of build script targets was tweaked slightly in a way that causes cargo to stack overflow by accientally adding a dependency loop. This commit implements one of the strategies discussed in rust-lang#5711 to fix this situation. The problem here is that when calculating the deps of a build script we need the build scripts of *other* packages, but the exact profile is somewhat difficult to guess at the moment we're generating our build script unit. To solve this the dependencies towards other build scripts' executions is added in a different pass after all other units have been assembled. At this point we should know for sure that all build script executions are in the dependency graph, and we just need to add a few more edges. Closes rust-lang#5708
Partially revert dep changes in #5651 Some logic which was tweaked around the dependencies of build script targets was tweaked slightly in a way that causes cargo to stack overflow by accientally adding a dependency loop. This commit implements one of the strategies discussed in #5711 to fix this situation. The problem here is that when calculating the deps of a build script we need the build scripts of *other* packages, but the exact profile is somewhat difficult to guess at the moment we're generating our build script unit. To solve this the dependencies towards other build scripts' executions is added in a different pass after all other units have been assembled. At this point we should know for sure that all build script executions are in the dependency graph, and we just need to add a few more edges. Closes #5708
Some logic which was tweaked around the dependencies of build script targets was tweaked slightly in a way that causes cargo to stack overflow by accientally adding a dependency loop. This commit implements one of the strategies discussed in rust-lang#5711 to fix this situation. The problem here is that when calculating the deps of a build script we need the build scripts of *other* packages, but the exact profile is somewhat difficult to guess at the moment we're generating our build script unit. To solve this the dependencies towards other build scripts' executions is added in a different pass after all other units have been assembled. At this point we should know for sure that all build script executions are in the dependency graph, and we just need to add a few more edges. Closes rust-lang#5708
- [beta] Partially revert dep changes in rust-lang/cargo#5651 (rust-lang/cargo#5722)
[BETA] Update cargo - [beta] Partially revert dep changes in rust-lang/cargo#5651 (rust-lang/cargo#5722)
…ichton Remove Compilation.libraries Actioning #5651 (comment)
…ichton Remove Compilation.libraries Actioning #5651 (comment)
- [beta] Partially revert dep changes in rust-lang/cargo#5651 (rust-lang/cargo#5722)
[BETA] Update cargo - [beta] Partially revert dep changes in rust-lang/cargo#5651 (rust-lang/cargo#5722)
This commit fixes rust-lang#8966 by updating the unit generation logic to avoid generating an erroneous circular dependency between the execution of two build scripts. This has been present for Cargo in a long time since rust-lang#5651 (an accidental regression), but the situation appears rare enough that we didn't get to it until now! Closes rust-lang#8966
Fix the unit dependency graph with dev-dependency `links` This commit fixes #8966 by updating the unit generation logic to avoid generating an erroneous circular dependency between the execution of two build scripts. This has been present for Cargo in a long time since #5651 (an accidental regression), but the situation appears rare enough that we didn't get to it until now! Closes #8966
Fixes #5650. cc #5435
As part of my recent work on profiles, I introduced some situations where a
library can be compiled multiple times with different settings. Doctests were
greedily grabbing all dependencies for a package, regardless of which target
is was for. This can cause doctests to fail if it links multiple copies of
the same library.
One way to trigger this is
cargo test --release
if you have dependencies, abuild script, and
panic="abort"
. There are other (more obscure) ways totrigger it with profile overrides.