about summary refs log tree commit diff
path: root/doc
diff options
context:
space:
mode:
authorMaximilian Bosch <maximilian@mbosch.me>2020-05-24 18:37:34 +0200
committerMaximilian Bosch <maximilian@mbosch.me>2020-05-24 18:37:34 +0200
commit6574ba1946f3957fbf8bc1ba56850e26e15fa096 (patch)
treed332831116e945bfd4abeaf196673dd47e44bccd /doc
parent913dcddb6852e53e64cd6f6e7f998d6b6f57841e (diff)
downloadnixlib-6574ba1946f3957fbf8bc1ba56850e26e15fa096.tar
nixlib-6574ba1946f3957fbf8bc1ba56850e26e15fa096.tar.gz
nixlib-6574ba1946f3957fbf8bc1ba56850e26e15fa096.tar.bz2
nixlib-6574ba1946f3957fbf8bc1ba56850e26e15fa096.tar.lz
nixlib-6574ba1946f3957fbf8bc1ba56850e26e15fa096.tar.xz
nixlib-6574ba1946f3957fbf8bc1ba56850e26e15fa096.tar.zst
nixlib-6574ba1946f3957fbf8bc1ba56850e26e15fa096.zip
rust*: add docs for testing packages
See also https://discourse.nixos.org/t/rust-build-speed-improvements/7225
Diffstat (limited to 'doc')
-rw-r--r--doc/languages-frameworks/rust.section.md66
1 files changed, 66 insertions, 0 deletions
diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md
index cec3373cbee6..066633b53c43 100644
--- a/doc/languages-frameworks/rust.section.md
+++ b/doc/languages-frameworks/rust.section.md
@@ -75,6 +75,72 @@ pkgs.rustPlatform.buildRustPackage {
 }
 ```
 
+### Running package tests
+
+When using `buildRustPackage`, the `checkPhase` is enabled by default and runs
+`cargo test` on the package to build. To make sure that we don't compile the
+sources twice and to actually test the artifacts that will be used after that, 
+the tests will be ran in the `release`-mode by default.
+
+However, in some cases the test-suite of a package doesn't work properly in the
+`release` mode. In that case, the mode for `checkPhase` can be changed like this:
+
+```nix
+rustPlatform.buildRustPackage {
+  /* ... */
+  checkType = "debug";
+}
+```
+
+#### Tests relying on the structure of the `target/`-directory
+
+Some tests may rely on the structure of the `target/`-directory. Those tests
+are likely to fail since we use `cargo --target` during build. This means that
+the artifacts
+[are stored in `target/<architecture>/release/`](https://doc.rust-lang.org/cargo/guide/build-cache.html)
+rather than `target/release/`.
+
+This can only be circumvented by patching the affected tests accordingly.
+
+#### Disabling package-tests
+
+In some cases it's necessary to disable the tests (which can be done by declaring
+`doCheck = false;`) which is fine in the following cases:
+
+* If no tests exist, the `checkPhase` should be explicitly disabled to skip
+  unnecessary build-steps to speed-up the build.
+
+* If tests are highly impure (e.g. due to heavy network usage), it's also fine
+  disable tests.
+
+There are obviously some other corner-cases where it's sensible to disable tests,
+those aren't hard-rules, in the end this is a case-by-case decision.
+
+Please check however if it's possible to disable a problematic subset of the
+test-suite and leave comment which explains why that's needed.
+
+### Building a package in the `debug` mode
+
+By default, `buildRustPackage` will use the `release`-mode for building. If a package
+should be built in the `debug`-mode however, it can be configured like this:
+
+```nix
+rustPlatform.buildRustPackage {
+  /* ... */
+  buildType = "debug";
+}
+```
+
+Obviously, the `checkPhase` will be ran in `debug`-mode as well in this case.
+
+### Custom `build`/`install`-procedures
+
+Some packages may use custom scripts for building/installing, e.g. with a `Makefile`.
+In that case it's recommended to always override the `build-`/`install-`/`checkPhase`.
+
+Otherwise, it may be possible that one of the internal steps fails because of the
+modified directory structure of `target/`.
+
 ## Compiling Rust crates using Nix instead of Cargo
 
 ### Simple operation