bcachefs-tools icon indicating copy to clipboard operation
bcachefs-tools copied to clipboard

Make rust versioning make sense (allow building against older rust versions).

Open YellowOnion opened this issue 1 year ago • 8 comments

according to this: https://github.com/koverstreet/bcachefs-tools/blob/master/rust-src/Cargo.toml#L6

We use version 1.65, but on nixos-stable I get an error:

 error: package `clap_complete v4.4.4` cannot be built because it requires rustc 1.70.0 or newer, while the currently active rustc version is 1.69.0
       > Either upgrade to rustc 1.70.0 or newer, or use

It's probably a good habit to keep an eye on versions, and not expect everyone to be running the latest rust.

@koverstreet @bczhc

YellowOnion avatar Nov 16 '23 13:11 YellowOnion

Note that: cargo check will validate.

YellowOnion avatar Nov 16 '23 13:11 YellowOnion

Thanks for pointing this. I've fixed it in https://github.com/koverstreet/bcachefs-tools/pull/173/commits/bf81a90343a788056f36b976c95f03912f4b777f.

bczhc avatar Nov 16 '23 13:11 bczhc

@koverstreet is your custom repo for bindgen still needed? it's not listed on your git anymore, I'm worried it might end up getting garbage collected.

YellowOnion avatar Nov 16 '23 14:11 YellowOnion

@bczhc okay after banging my head against the wall for a few hours, the only way to validate with 100% certianity, is to use cargo / rust 1.65, cargo update will just add deps that violate the version policy. and I'm still not sure that actually helps.

YellowOnion avatar Nov 16 '23 15:11 YellowOnion

Indeed.. Now cargo update doesn't consider MSRVs. I did a quick search and found https://github.com/rust-lang/cargo/issues/9930.

There's a nightly flag minimal-versions can be used: cargo update -Z minimal-versions

bczhc avatar Nov 16 '23 16:11 bczhc

Yeah, the custom bindgen is still needed.

Doing a proper fix for that is going to require tracking down someone involved with rustc.

koverstreet avatar Nov 16 '23 20:11 koverstreet

There's a nightly flag minimal-versions can be used: cargo update -Z minimal-versions

You can use the nightly flag -Z msrv-policy and it'll try to resolve compatible semver releases of all deps by the rust-version in your Cargo.toml.

  • It relies on the dependency chain each specifying their compatible rust-version as well, otherwise it will assume compatibility.
  • Some crates will specify the lowest supported rust version, but it is not with default features so may be a little bit higher (eg: hashbrown presently claims 1.63 but is 1.64 by default unless you pin a dependency (or opt-out of the equivalent default feature).
  • Some crates introduce implicit bumps in their own codebase and forget to bump their rust-version (happened recently with tokio-util)

Another alternative is -Z direct-minimal-versions which resolves your direct deps semver as the minimal version. IIRC you can pair that with -Z msrv-policy for implicit deps.

Eventually you'll either need to raise the MSRV of your own crate or to keep it low start pinning implicit deps with cargo update --package <crate> --precise <semver> when necessary (eg: -Z msrv-policy isn't compatible).


For CI you can use Cargo.lock.msrv and rename that to Cargo.lock to verify MSRV support.

BTW, rust 1.56 introduces edition 2021, so you might as well bump that:

https://github.com/koverstreet/bcachefs-tools/blob/a613340b26ad88801666362d2824118396f34c38/rust-src/Cargo.toml#L5

Note that your Cargo.toml has patch versions which are probably not the lowest compatible required to install with (-Z direct-minimal-versions), so these could probably be adjusted too:

https://github.com/koverstreet/bcachefs-tools/blob/a613340b26ad88801666362d2824118396f34c38/rust-src/Cargo.toml#L16

Usually that's either the version resolved at the time of adding the dep, or from automated upgrade tools like dependabot bumping unnecessarily.

polarathene avatar Nov 16 '23 21:11 polarathene

@polarathene thanks for the advice, I wonder if there's a variant that checks conformity to be included in a test suit so that it can be automated.

@koverstreet I wrote a version that seems to compile on 1.69 it's on my master https://github.com/YellowOnion/bcachefs-tools/commits/master

YellowOnion avatar Nov 20 '23 13:11 YellowOnion