nix-community / crate2nix

rebuild only changed crates in CI with crate2nix and nix
https://nix-community.github.io/crate2nix/
Apache License 2.0
352 stars 83 forks source link

Allow unifying features a.l.a. cargo build --all #190

Open Fuuzetsu opened 3 years ago

Fuuzetsu commented 3 years ago

Cargo has a questionable behaviour where

cargo build -pfoo
cargo build -pbar

does not give the same result as

cargo build -pfoo -pbar

In the first case, it will build all the dependencies of foo separately of all the dependencies of bar if they do have different features flags. In the second case, it will take the union of feature flags of the packages. It will only build the common dependency crates once.

In case of crate2nix, we are forced to always use the first method. This becomes quite a bit of a problem if you have many workspaces in your project. If you have a crate called foo and then have 10 different crates bar1, bar2, …, bar10 that depend on it and set some various set of features, you are going to be compiling foo 10 times as far as I understand. This may be desirable and is what cargo does if we invoke -pbarN separately for each package.

It'd be quite nice if there was a way to just have a single foo and have all the packages use it however. I'm not sure if that's easy or not to do but it could save a lot of time.

Relevant discussion on the Rust issue tracker https://github.com/rust-lang/cargo/issues/4463