Skip to content
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 minimal versions dependencies #346

Merged
merged 4 commits into from
Jul 5, 2024

Conversation

faern
Copy link
Contributor

@faern faern commented Jun 28, 2024

The CI job I added in this PR is something I try to run on all my crates as well. It's something that catch if the crate (or a transitive dependency) has under-specified a dependency.

cargo +nightly update -Z minimal-versions downgrades the entire dependency tree to the lowest allowed versions according to all the dependency semver specs in their Cargo.toml files.

It's very common to just add foo = "0.3" manually and then write code and run. Not realizing cargo automatically pulls in the latest version at the time. That might be foo 0.3.8 and you might unknowingly depend on features introduced in foo 0.3.4. A CI check like this makes sure you don't under-specify version requirements like that.

I found this because I depend on trycmd and this became an error with filetime. See this CI run: https://github.com/mullvad/unicop/actions/runs/9709586296/job/26798567031?pr=2. You depend on filetime::set_file_mtime, but that was introduced in filetime 0.2.6. However, I had to bump the version even further, because filetime did not build with minimal versions until 0.2.8.

This is the oldest version that works with snapbox
.github/workflows/ci.yml Outdated Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
@faern faern force-pushed the fix-minimal-versions-dependencies branch from 60a18c5 to cc1fcf9 Compare June 28, 2024 14:29
@coveralls
Copy link

coveralls commented Jun 28, 2024

Pull Request Test Coverage Report for Build 9714439987

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 51.654%

Totals Coverage Status
Change from base Build 9501692150: 0.0%
Covered Lines: 1390
Relevant Lines: 2691

💛 - Coveralls

.github/workflows/ci.yml Outdated Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
@faern faern force-pushed the fix-minimal-versions-dependencies branch from cc1fcf9 to 194c988 Compare June 29, 2024 03:28
Catch if we have under-specified any semver dependency
@faern faern force-pushed the fix-minimal-versions-dependencies branch from 194c988 to 9b4fb26 Compare June 29, 2024 03:38
@epage epage enabled auto-merge June 29, 2024 12:01
@coveralls
Copy link

coveralls commented Jun 29, 2024

Pull Request Test Coverage Report for Build 9721314969

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 51.654%

Totals Coverage Status
Change from base Build 9501692150: 0.0%
Covered Lines: 1390
Relevant Lines: 2691

💛 - Coveralls

@epage
Copy link
Contributor

epage commented Jun 29, 2024

Looks like a dep has a minimal-versions problem

@faern
Copy link
Contributor Author

faern commented Jun 29, 2024

Looks like a dep has a minimal-versions problem

Ok. Crap. We'll see when I have time to submit the same to them then.

auto-merge was automatically disabled July 2, 2024 07:10

Head branch was pushed to by a user without write access

@faern
Copy link
Contributor Author

faern commented Jul 2, 2024

Fixed. There were two more crates in this dependency tree which did not specify their dependencies correctly at their oldest versions allowed by this crate. But all of them had fixed the issue in newer versions. So just bumping the minimum version here in this repository fixes the issue.

Arguably those crates should also have a minimal-versions CI job. But they currently have no issue with this, and I don't currently have the time to submit that upstream :)

@faern faern force-pushed the fix-minimal-versions-dependencies branch from cd6d2ff to a3a20b9 Compare July 2, 2024 07:24
@coveralls
Copy link

coveralls commented Jul 5, 2024

Pull Request Test Coverage Report for Build 9756713128

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 51.654%

Totals Coverage Status
Change from base Build 9501692150: 0.0%
Covered Lines: 1390
Relevant Lines: 2691

💛 - Coveralls

@epage epage merged commit 9c7c871 into assert-rs:main Jul 5, 2024
16 of 17 checks passed
@epage
Copy link
Contributor

epage commented Jul 5, 2024

btw why did this matter and why was this started off with --all-targets?

In theory, minimal versions is only relevant for dependents, and not yourself. We could lower the ecosystem burden of adopting this by leaving off the --all-targets flag and only checking default targets.

@faern
Copy link
Contributor Author

faern commented Jul 9, 2024

--all-targets was put there to catch invalidly specified dependencies used in examples and tests etc as well as the main library/binary code.

How much of a burden do you regard this CI check to be to adopt? I don't think it's very hard at all to keep the dependencies well specified, once this check is in place. And when adopting this CI job it's very easy to fix any existing issues. The only time it's a real problem is if a dependency you depend on have made the same error. But then it's only luck if that dependency happens to be a dev dependency instead of a prod dependency and you ignore checking dev dependencies by leaving out --all-targets.

I personally find it does not simplify things a lot to remove --all-targets but instead it makes the CI checked miss what it was supposed to uphold.

@epage
Copy link
Contributor

epage commented Jul 9, 2024

From my understanding, the primary value add of verifying version requirements is for people who depend on you. I'm not seeing the value for tests and examples.

However, I'm much more free with my dev-dependencies than other dependencies and by excluding dev-dependencies, it reduces the number of people I have to bug or workaround to make this work as I adopt it across all of my projects.

@faern
Copy link
Contributor Author

faern commented Jul 10, 2024

I see your point. If you write a library, keeping everything neat and tidy for your own project's sake vs keeping it correct for your consumers are two different things. However it's still objectively wrong to say [dev-dependency] foo = "0.2" if your tests use features in foo 0.2.3. However, I can agree that this error is not likely to cause much trouble in practice. And as you say, if/while the ecosystem often commit these crimes, it's going to inflict a bit more pain on you downstream, the more dependencies you strictly check for this correctness property.

On the other hand, checking stricter and actively pushing these CI jobs upstream (like I just did) will spread it faster 🤷

I don't have a very strong opinion about dev-dependencies. But I do think we should push for this being a more standard CI check in general. Would be great if it could be stabilized, so nightly is not required.

@faern
Copy link
Contributor Author

faern commented Jul 23, 2024

Would it be possible to get a release of trycmd? Since the latest version on crates.io still depend on snapbox ^0.6.0, which has the minimal-versions issue, my minimal-versions CI fail. Thank you 😊

@epage
Copy link
Contributor

epage commented Jul 23, 2024

Released

@smoelius
Copy link
Contributor

FWIW, I found this discussion very enlightening. Thank you, @faern! Thank you, @epage!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants