ipetkov / crane

A Nix library for building cargo projects. Never build twice thanks to incremental artifact caching.
https://crane.dev
MIT License
872 stars 82 forks source link

Way to get the binary for `cargo-test/cargo-nextest` #600

Open guskovd opened 4 months ago

guskovd commented 4 months ago

Way to get the binary for cargo-test/cargo-nextest

For some reason, I would like to run tests not at the time of building the application, but after

For example, this can be useful when running integration tests

Therefore, I would like to understand whether such binaries can be assembled using crane?

dpc commented 4 months ago

Yeah. cargo nextest --no-run. Though I'm not sure if normal craneLib.buildPackage, would pick these binaries out of ./target. You might need to keep the target and just extract it outside of Nix or something. It's definitely doable though. Anything cargo can do directly, crane can handle too.

https://github.com/fedimint/fedimint/blob/084798db569773b61e9e0470d69ad37b2d1b548d/scripts/tests/test-ci-all.sh#L29

ipetkov commented 4 months ago

@guskovd you can set doCheck = false; in your buildPackage derivation, and directly use craneLib.cargoTest or craneLib.cargoNextest to run the tests both of which should automatically find any test binaries compiled by cargo. Hope this helps!