crane icon indicating copy to clipboard operation
crane copied to clipboard

unnecessary rebuild of unrelated packages in monorepo on member version bump

Open iwinux opened this issue 2 years ago • 1 comments

Suppose I have crates/foo and crates/bar in a monorepo. Whenever I bump the version of crates/foo, the content of Cargo.lock at the repo root also changes. That inevitably triggers rebuild of crates/bar and all of its deps, even if crates/bar does not depends on crates/foo and none of its files (except for the shared Cargo.lock) change.

Is there any way to avoid this?

iwinux avatar Oct 30 '23 03:10 iwinux

Hi @iwinux thanks for the report!

Currently we copy over the Cargo.lock completely untouched when creating the dummified sources (to build only dependency crates). When a workspace package's version changes, it gets recorded in the Cargo.lock and as you've observed it leads to a rebuild...

I don't think there is a (good?) way to avoid this besides adding an additional Cargo.lock file (i.e. workspace) for crates/bar and telling crane to build that workspace separately (crates/foo can still refer to crates/bar, but that workspace will also get rebuilt whenever crates/foo or crates/bar's versions change)


Implementing https://github.com/ipetkov/crane/issues/288 may be able to help with this (or rather it will avoid having to rebuild all of crates/bar's dependencies. Changing any version of a workspace package would still end up rebuilding the workspace crates even if all external deps aren't fwiw)

ipetkov avatar Nov 06 '23 17:11 ipetkov