nabijaczleweli / rust-embed-resource

A Cargo build script library to handle compilation and inclusion of Windows resources, in the most resilient fashion imaginable
MIT License
173 stars 29 forks source link

Exact version dependency on TOML causes version resolution conflicts #51

Closed LPGhatguy closed 1 year ago

LPGhatguy commented 1 year ago

Hello!

In 703b673a0d41034a457cc56095f1b51d884953d5, the toml crate was changed to an exact dependency on version 0.5.8. Based on the appveyor link, it looks like this was done because of toml using a feature stabilized in Rust 1.36.0 (impl From<&String> for String)[^1], but embed-resource's MSRV is 1.35.0.

This change prohibits users of embed-resource from also using toml 0.5.9. In my project's case, that release includes a fix for a specific bug that produces invalid TOML.

When resolving dependencies, Cargo does not allow two semver-compatible versions of the same crate to co-exist, even when one is a build dependency. As a result, libraries should never use exact version dependencies. They often result in version resolution conflicts and break some built-in Cargo commands, like cargo add:

$ cargo add toml
    Updating crates.io index
      Adding toml v0.5.9 to dependencies.
             Features:
             - indexmap
             - preserve_order
error: failed to select a version for `toml`.
    ... required by package `embed-resource v1.7.4`
    ... which satisfies dependency `embed-resource = "^1.7.4"` of package `cyrtanthus v0.1.0`
    ... which satisfies path dependency `cyrtanthus` (locked to 0.1.0) of package `cyrtanthus-desktop v0.1.0`
versions that meet the requirements `=0.5.8` are: 0.5.8

all possible versions conflict with previously selected packages.

  previously selected package `toml v0.5.9`
    ... which satisfies dependency `toml = "^0.5.9"` of package `cyrtanthus v0.1.0)`
    ... which satisfies path dependency `cyrtanthus` (locked to 0.1.0) of package `cyrtanthus-desktop v0.1.0)`

failed to select a version for `toml` which could resolve this conflict

I am aware of a couple options that could fix this issue:

  1. Raise embed-resource's MSRV to at least 1.36.0 (released July 2019) and remove this exact version dependency.
  2. File an issue with the toml authors to push a new 0.5.10 release that supports Rust 1.35.0. This seems unlikely: 1.36.0 is a very common MSRV and it appears the authors are in the middle of a major refactor for toml 0.6.

[^1]: Rust's stable docs indicate that this was stabilized in Rust 1.35.0. However, the earliest version of Rust that I could find this implementation in is Rust 1.36.0: https://doc.rust-lang.org/1.36.0/std/string/struct.String.html#impl-From%3C%26%27_%20String%3E

nabijaczleweli commented 1 year ago

There's recent precedent for this in cargo-update 11.0.0, and the same applies here unfortunately – relaxed to "0.5".

nabijaczleweli commented 1 year ago

Released in v1.8.0