image-rs / image

Encoding and decoding images in Rust
Apache License 2.0
4.86k stars 597 forks source link

Building with default features on macOS requires rustc v1.79 or newer. #2261

Closed dmbfm closed 2 months ago

dmbfm commented 2 months ago

I am using macOS Sonoma 14.4.1, rustc/cargo version 1.77.2. When trying to use the image crate with the default features enabled I get an error about the minimum required rust version.

Expected

Since the minimum version for the image crate is 1.67.1, the program should build correctly.

Actual behaviour

I get the following message when trying to run cargo build:

error: package `ravif v0.11.7` cannot be built because it requires rustc 1.79 or newer, while the currently active rustc version is 1.77.2
Either upgrade to rustc 1.79 or newer, or use
cargo update ravif@0.11.7 --precise ver
where `ver` is the latest version of `ravif` supporting rustc 1.77.2

Reproduction steps

cargo new image-test
cd image-test
cargo add image
cargo build
kornelski commented 2 months ago

I've made ravif demand 1.79, because a dependency of rav1ebitstream-io — started using inline const syntax, which requires 1.79. If you didn't get the version error on ravif, you'd get even more confusing build errors.

You can build it on older Rust if you downgrade bitstream-io to 2.3.0 and ravif to 0.11.5

The fix

cargo update
cargo update ravif --precise 0.11.5
cargo update bitstream-io --precise 2.3.0
dmbfm commented 2 months ago

It's not much of an issue for me really but if the MSRV of the image crate is 1.67.1, shouldn't it ideally work with the default features of the crate?

kornelski commented 2 months ago

The crate may be compatible with an older version of Rust itself, but it can't control what the 3rd party dependencies are doing. Pinning dependencies to older versions has other project-breaking consequences. Cargo doesn't have ability to select dependencies based on Rust compatibility yet (in stable releases), so if you need to work with an older version of Rust, you need to downgrade dependencies yourself.

dmbfm commented 2 months ago

Got it. Thanks!

HeroicKatora commented 2 months ago

@dmbfm This is quite recent and likely very relevant: https://github.com/rust-lang/cargo/issues/13873 Although it doesn't exist at the Rust toolchain version you're looking for (except with hacks over installing a much newer cargo than rustc detailed in the thread, maybe it actually would work) that's the workflow which should be working one day. The tooling team is likely to be very interested in your issue and whether it'd be solved by that implementation.

kornelski commented 2 months ago

MSRV-aware resolver unfortunately doesn't fix this, because bitstream-io 2.4.0 added 1.79-requiring code without rust-version. They've fixed it in 2.4.1, but MSRV-aware cargo downgrades to 2.4.0 only, not to 2.3.0.

fintelia commented 2 months ago

In CI we do validate that -Z minimal-versions compiles with the MSRV Rust version. You'd be missing out on lots of bug fixes and such, but at least it allows you to identify one consistent set of dependency versions that work