oxalica / nocargo

[alpha] Build Rust crates with Nix Build System.
MIT License
138 stars 9 forks source link

shared local dependency in workspace causing rebuild of dependency for every crate member #23

Closed therishidesai closed 9 months ago

therishidesai commented 9 months ago

I have a shared local library in my workspace and for each crate member it triggers a rebuild of that specific dependency. Put another way I have local dependency A and then for crate members 1, 2, and 3 I have 3 different versions of A that get built and placed in the cache for 1, 2 and 3.

Any ideas on what could be causing this?

therishidesai commented 9 months ago

https://github.com/therishidesai/test-nocargo-ws

I can't seem to repro it with this toy example

therishidesai commented 9 months ago

I ran nix-diff on the two different versions of the library and this is the core diff:

              • The input derivation named `rust_syn-2.0.52-build` differs
                - /nix/store/lfbf0wqca8z844427g3fvnxl63cilmb7-rust_syn-2.0.52-build.drv:{out}
                + /nix/store/h6kzvylaa2j5pcyjx46j3z679i2mc4cj-rust_syn-2.0.52-build.drv:{out}
                • The environments do not match:
                    features=''
                    extra-traits full default full proc-macro2 proc-macro quote printing parsing derive clone-impls
                ''
therishidesai commented 9 months ago

I narrowed down what is going on. The library has some crates with certain feature flags on/off and then some of the executables have crates with transient dependencies to the same crates which is resulting in a diff.

I built a small repro here where test-lib, testA and testB all depend on the same serde version with the same feature flag on but testC only depends on serde without the feature flag. This means that the test-lib hash is different in testC vs in testA and testB

therishidesai commented 9 months ago

I guess it isn't possible to build a version of the library with every feature enabled since there could be a feature collision.

therishidesai commented 9 months ago

Going to close this issue. Probably the best way to avoid this is try to use workplace dependencies in as many spots as possible.