bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
34.88k stars 3.41k forks source link

Support and test compiling with `-Z minimal-versions` #9593

Open SkiFire13 opened 1 year ago

SkiFire13 commented 1 year ago

-Z minimal-versions is an unstable cargo flag to generate a Cargo.lock with the minimal versions possible, rather than the latest ones. This helps finding cases where a crate depends on features of a dependency which were released in a later semver-compatible version than the one reported in the Cargo.toml.

I tried running cargo minimal-versions (which automates a bunch of work you have to do to correctly use -Z minimal-versions) and the result was not that good, although most issues were due to dependencies not respecing minimal versions themself.

I found the following issues (though there could be more hidden, see the final note):

I decided to report the last three issues because, while they are not strictly bevy's fault, they impact building bevy with minimal versions.

Note that the analysis must consider the whole workspace together (crates in tools included), and this may hide problems in the single crates due to newer dependencies specified by other crates (and this could also apply to dependencies of dependencies...). So for example if bevy_ecs declared a dependency on foo 1 but actually used features from foo 1.1, and bevy_reflect declared a dependency on foo 1.1, then no error would be raised while compiling bevy_ecs, even though it technically declared a wrong dependency. To find some of these kind of errors you would have to compile the single crates outside the workspace, which is a lot more work to do. This could be doable just for crates that can be used alone, like bevy_ecs and bevy_reflect though.

It would be nice if in the future this was automatically tested, to ensure that people don't get weird errors like in #9374, or recently one posted on Discord with tracing older than 0.1.36 (which seems to not happen on the master branch likely due to some transitive dependency).

hymm commented 1 year ago

I think the lock_api issue is at least partially why cargo run -p ci doesn't work on my machine. It's picking up 0.4.6 when I run that command, whereas it picks up 0.4.10 when I run cargo test or cargo run --example directly in my console.

IceSentry commented 12 months ago

I just got hit by the bevy_text depending on 0.24 instead of 0.24.1 issue. I guess until we have CI to check this a PR that fixes all the issues you mentioned would probably be good.

rlidwka commented 12 months ago

looks like another dependency is found here: https://github.com/bevyengine/bevy/pull/9653

hymm commented 11 months ago

I tried adding lock_api = 0.4.7 to bevy_reflect, but it doesn't seem to work. I get a conflicting version error, when I try to run cargo run -p ci

Updating crates.io index
error: failed to select a version for `lock_api`.
    ... required by package `bevy_reflect v0.12.0-dev (E:\Github\bevy\crates\bevy_reflect)`
    ... which satisfies path dependency `bevy_reflect` (locked to 0.12.0-dev) of package `bevy_ecs v0.12.0-dev (E:\Github\bevy\crates\bevy_ecs)`
    ... which satisfies path dependency `bevy_ecs` (locked to 0.12.0-dev) of package `bevy_ecs_compile_fail_tests v0.1.0 (E:\Github\bevy\crates\bevy_ecs_compile_fail_tests)`
versions that meet the requirements `^0.4.7` are: 0.4.10, 0.4.9, 0.4.8, 0.4.7

all possible versions conflict with previously selected packages.

  previously selected package `lock_api v0.4.6`
    ... which satisfies dependency `lock_api = "^0.4.6"` (locked to 0.4.6) of package `parking_lot v0.12.1`
    ... which satisfies dependency `parking_lot = "^0.12.1"` (locked to 0.12.1) of package `bevy_reflect v0.12.0-dev (E:\Github\bevy\crates\bevy_reflect)`
    ... which satisfies path dependency `bevy_reflect` (locked to 0.12.0-dev) of package `bevy_ecs v0.12.0-dev (E:\Github\bevy\crates\bevy_ecs)`
    ... which satisfies path dependency `bevy_ecs` (locked to 0.12.0-dev) of package `bevy_ecs_compile_fail_tests v0.1.0 (E:\Github\bevy\crates\bevy_ecs_compile_fail_tests)`

failed to select a version for `lock_api` which could resolve this conflict
thread 'main' panicked at 'Compiler errors of the ECS compile fail tests seem to be different than expected! Check locally and compare rust versions.: command exited with non-zero code `cargo test --target-dir ../../target`: 101', tools\ci\src\main.rs:99:18
SkiFire13 commented 11 months ago

I tried adding lock_api = 0.4.7 to bevy_reflect, but it doesn't seem to work. I get a conflicting version error, when I try to run cargo run -p ci

I can reproduce this if I manually change the Cargo.lock file to use lock_api version 0.4.6, however there seems to be no good reason why it should be like this. Running cargo update inside crates/bevy_ecs_compile_fail_tests fixes the issue, but this shouldn't be necessary.

On the sidenote, does anyone know why the bevy_*_compile_fail_tests are excluded from the workspace? This prevents them from sharing the same Cargo.lock file, which might be a problem in this case.