Skip to content

Resolve minimal versions in Cargo-minimal.lock on dependency changes - #4898

Merged
apoelstra merged 3 commits into
rust-bitcoin:masterfrom
nyonson:version-creep-two
Aug 23, 2025
Merged

apoelstra merged 3 commits into
rust-bitcoin:masterfrom
nyonson:version-creep-two

Conversation

@nyonson

@nyonson nyonson commented Aug 19, 2025

Copy link
Copy Markdown
Contributor

Attempt two to close #4313

I first attempted to iron out dependency drift in #4330, but wasn't quite able to check all the boxes. I think I might have now though by just running the two cargo flags, direct-minimal-versions and minimal-versions, one after the other in the update lock file script. Running direct first checks for the issue where direct dependencies might be lying. And running minimal-versions after that forces all transitive versions down to their minimums, fixing any drift (can see this in the lock file change). We can trust that minimal-versions won't bump our own direct deps because we just checked them.

The first commit is ironing out little issues required to use direct-minimal-versions. Essentially fixing manifests which are out of date and lying about the required version. The serde bump might be a large one, but I was running into an issue where it was pulling in an old proc-macro2 which required a rust compiler option, proc_macro_span_shrink, that is no longer available.

The second commit updates the lock file script to use the new flags and generates the new lock files.

The third commit might be drop-able, but I found it kinda of strange that only the default features where being used to generate the dependency lock files. Now, granted, the rust-bitcoin dependency tree is so lean that it appears enabling all features doesn't add any new dependencies, but still makes me feel better for the future.

* Standardizing the minimal versions of `serde_json` and `serde_test` in
the workspace. This allows the unstable "direct-minimal-versions" flag
of cargo to be used since it requires one minimal version in a
workspace. Since these are all dev dependencies (including the fuzz
crate) there shouldn't be any change for external consumers.
* arrayvec needs a small bump due to its version in hex.
* Arbitrary 1.4.0 does not work with the current 1.63.0 MSRV due to some
core::error usage.
* Update serde's contraint to the minimum version which the
workspace has been using due to implicit upgrades. Attempts were first
made to see if 1.0.103 could be used, but at the very least, would
require a fair amount of lint settings to be overridden due to the old
code. 1.0.195 is used because it also irons out an issue where old
versions of serde pulled in old proc_macro2 versions which use a nightly
feature, `proc_macro_span_shrink`, that has been dropped.
Instead of letting minimal versions potentially drift upwards, reset
the Cargo-minimal.lock file each time dependencies are updated. The
new script uses a combination of the `direct-minimal-version` and
`minimal-versions` flags to ensure the minimal version dependency
tree is tested.
Ensure all optional feature dependencies are tested when creating the
lock files. rust-bitcoin's dependency tree is so lean right now though,
this is currently a no-op.
@github-actions github-actions Bot added C-bitcoin PRs modifying the bitcoin crate C-hashes PRs modifying the hashes crate C-units PRs modifying the units crate C-internals PRs modifying the internals crate test C-primitives labels Aug 19, 2025
@coveralls

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 17082959623

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 6 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.02%) to 83.487%

Files with Coverage Reduction New Missed Lines %
bitcoin/src/psbt/mod.rs 6 86.71%
Totals Coverage Status
Change from base Build 17070812027: -0.02%
Covered Lines: 21573
Relevant Lines: 25840

💛 - Coveralls

@tcharding tcharding left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK d39a8ac

@tcharding

Copy link
Copy Markdown
Member

Thanks for the work man. My ack is only a soft one because I'm not super versed or as concerned as I probably should be with all the lock files and whatnot.

@apoelstra

Copy link
Copy Markdown
Member

In d39a8ac:

Always good to do more checks, but fwiw the call to cargo check is not intended to actually test anything. It's just supposed to regenerate the lockfile because there is no other direct way to do so. (Though now that I look, there is clearly a cargo generate-lockfiles command which supports these -Z flags.... I wonder when that showed up..)

@apoelstra

Copy link
Copy Markdown
Member

Oh, never mind me, the cargo check calls I'm talking about are ones that you just added here (with a big block comment explaining that you're testing our own .toml files to be sure we're not lying about minimal versions).

And yes, cargo check with all features is probably more useful than with default features. (Our CI, and my local CI, will test a more extensive matrix).

@apoelstra apoelstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK d39a8ac; successfully ran local tests

@nyonson

nyonson commented Aug 23, 2025 •

Copy link
Copy Markdown
Contributor Author

(Though now that I look, there is clearly a cargo generate-lockfiles command which supports these -Z flags.... I wonder when that showed up..)

I initially wrote off generate-lockfile because it doesn't support an --all-features flag, and I assumed that meant it might not capture some optional dependency versions in the lockfile. However, looks like cargo has an internal flag for some commands where it just always requires optional deps. Did some local tests and that appears to be the case with generate-lockfile. I also made sure it still fails when dependencies are off. So might make this script more clear to switch to it instead of using check to generate the lockfile.

@apoelstra

Copy link
Copy Markdown
Member

Lockfiles always include all dependencies for all features and all targets. This is actually extremely annoying because it means that the lockfiles we ship with this library are full of dev-dependency crap and stuff for systems that nobody uses. And there is no tooling for filtering, diffing, or merging these.

But it's better than Python, so 🤷

@nyonson

nyonson commented Aug 23, 2025

Copy link
Copy Markdown
Contributor Author

Lockfiles always include all dependencies for all features and all targets.

Ah TIL thanks, not sure why I assumed otherwise. Given this, I think it makes sense to just use generate-lockfiles for clarity in the script. The check here is redundant given CI is where are the tests will run anyways.

Did have ai make me this little table fwiw.

| Command | Existing Lockfile | Behavior |
|---------|------------------|----------|
| `cargo check` | Exists | **Conservative** - Only adds missing deps, keeps existing versions |
| `cargo generate-lockfile` | Exists | **Aggressive** - Upgrades all deps to latest compatible |
| `cargo check` | Missing | Creates lockfile with latest compatible versions |
| `cargo generate-lockfile` | Missing | Creates lockfile with latest compatible versions |

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-bitcoin PRs modifying the bitcoin crate C-hashes PRs modifying the hashes crate C-internals PRs modifying the internals crate C-primitives C-units PRs modifying the units crate test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can Cargo-minimal.lock versions drift upwards on downgrades?

4 participants