nixpkgs/pkgs/build-support/rust/build-rust-crate
Andreas Rammhold a3a51763f9
buildRustCrate: add buildTests flag to tell rustc to build tests instead of binaries
This helps us instruct rustc to build tests instead of binaries. The
actual build will then ONLY produce test executables. This is a first
step towards having rust crate tests within nixpkgs.

We default back to only a single output in test cases since that is the
only reasonable thing to do here.

Producing libraries or binaries in addition to tests would theoretically
be feasible but usually generates different dependency trees. It is very
common to have some libraries in `[dev-depdendencies]` within Cargo.toml
just for your tests. To not start mixing things up going with a
dedicated derivation for the test build sounds like the best choice for
now.

To use this you must provide a proper test dependency chain to
`buildRustCrate` (as you would usually do with your non-test inputs).
And then set the `buildTests` attribute to `true`. The derivation will
then contain all tests that were built in `$out/tests`. All common test
patterns and directories should be supported and tested by this change.

Below is an example how you would run a single test from the derivation.
This commit contains some more examples in the `buildRustCrateTests`
attribute set that might be helpful.

```
let
  drv = buildRustCrate {
     …
     buildTests true;
  };
in runCommand "test-my-crate" {} ''
  touch $out
  exec ${drv}/tests/my-test
''
```
2020-01-07 11:57:34 +01:00
..
test buildRustCrate: add buildTests flag to tell rustc to build tests instead of binaries 2020-01-07 11:57:34 +01:00
build-crate.nix buildRustCrate: add buildTests flag to tell rustc to build tests instead of binaries 2020-01-07 11:57:34 +01:00
configure-crate.nix buildRustCrate: rename makeDeps function to mkRustcDepArgs 2019-12-11 23:23:55 +01:00
default.nix buildRustCrate: add buildTests flag to tell rustc to build tests instead of binaries 2020-01-07 11:57:34 +01:00
helpers.nix buildRustCrate: fixup usage of builtins.filterSource 2020-01-07 00:49:48 +01:00
install-crate.nix buildRustCrate: add buildTests flag to tell rustc to build tests instead of binaries 2020-01-07 11:57:34 +01:00
lib.sh buildRustCrate: add buildTests flag to tell rustc to build tests instead of binaries 2020-01-07 11:57:34 +01:00
log.nix buildRustCrate: move the color loggign & remove some runtime checks 2019-12-11 22:35:44 +01:00