nix-community / crate2nix

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

Build kinds support #285

Open jordanisaacs opened 1 year ago

jordanisaacs commented 1 year ago

Add build kind support (relying on https://github.com/NixOS/nixpkgs/pull/221440). Uses a new parameter buildKinds, same as the new buildRustCrate parameter. All dependencies will only build lib.

A breaking change is the removal of the runTests option. It is now a tools function, crateWithTest that handles the buildKinds for your when you call it. This is so you can override the testCrate derivation with your own version (eg if you only want to two derivations: one with tests + examples + benches, and then the final one).

TODO:

  1. Merge new cargo metadata and utilize it in codegen: https://github.com/rust-lang/cargo/issues/11846
  2. Figure out dev dependencies & building the library (see below comment)

Closes: https://github.com/kolloch/crate2nix/issues/284 https://github.com/kolloch/crate2nix/issues/145

jordanisaacs commented 1 year ago

Passes all the crate2nix tests!

jordanisaacs commented 1 year ago

Been playing around with this in a project of mine and it works great. The one issue I see which I am not sure the best way to fix (whether in buildRustCrate or crate2nix) is the ergonomics of dev dependencies.

Tests/examples/benches that are not the library test, rely on the library itself as a dependency. This is not reflected in the dependency list generated by crate2nix. You can get around this by adding lib to the build kinds, BUT then the library gets built with the dev dependencies. Open to suggestions.

flokli commented 7 months ago

@jordanisaacs did you keep tinkering with this? We'd like to build benchmarks with crate2nix for Tvix, so I'm curious to see if I can help out somehow.

jordanisaacs commented 7 months ago

@flokli It was a pretty big change that needs changes in three projects (crate2nix, cargo, and nixpkgs) and it didn't get any reviews so stopped pushing it forward. I would love to see this stuff get merged though.

I see the way forward being getting the nixpkgs PR merged first. That needs reviewers which you could help with. Then we can revisit crate2nix and what we need merged into cargo (e.g. what metadata do we need).

jordanisaacs commented 7 months ago

I do need to rebase the nixpkgs commit though. Will try and do it sometime this week.