LukeMathWalker / cargo-chef

A cargo-subcommand to speed up Rust Docker builds using Docker layer caching.
Apache License 2.0
1.72k stars 113 forks source link

Feature: Remove explicit transitive dependencies from packages during `chef prepare` #262

Closed mladedav closed 6 months ago

mladedav commented 6 months ago

Motivation

When we have a package a, a dependency b and its dependency c but then we find out that we need to use c directly, the lockfile will change and with it the generated recipe and everything will need to be rebuilt although the result will be the same.

The example looks like this:

a          a
|          |\
b    ->    b |
|          \ |
c            c

This is a bit of a niche optimization but can help sometimes.

Propsed solution

For each package in the worksapce, if it depends on any package directly but also transitively, the direct dependency can be safely erased.

This cannot be used if the direct dependency turns on a feature that would not be turned on otherwise.

LukeMathWalker commented 6 months ago

This is not something I want to cover—it's too advanced and I don't want to get buried deeper into the inner mechanics of cargo's resolver.
If either manifests or the lockfile changes, the cache is bust—and that's a good enough compromise for me.