Skip to content

Commit

Permalink
buildRustPackage: Add cargoTestFlags
Browse files Browse the repository at this point in the history
This makes it possible to pass flags to `cargo test`, which is needed if
a crate is compiled with custom feature flags.
  • Loading branch information
Max Hausch committed Mar 2, 2021
1 parent fa62f37 commit ebe3ae4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions doc/languages-frameworks/rust.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ rustPlatform.buildRustPackage {
Please note that the code will be compiled twice here: once in `release` mode
for the `buildPhase`, and again in `debug` mode for the `checkPhase`.

Test flags, e.g., `--features xxx/yyy`, can be passed to `cargo test` via the
`cargoTestFlags` attribute.

Another attribute, called `checkFlags`, is used to pass arguments to the test
binary itself, as stated
(here)[https://doc.rust-lang.org/cargo/commands/cargo-test.html].

#### Tests relying on the structure of the `target/` directory

Some tests may rely on the structure of the `target/` directory. Those tests
Expand Down
3 changes: 2 additions & 1 deletion pkgs/build-support/rust/hooks/cargo-check-hook.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
declare -a checkFlags
declare -a cargoTestFlags

cargoCheckHook() {
echo "Executing cargoCheckHook"
Expand All @@ -15,7 +16,7 @@ cargoCheckHook() {
threads=1
fi

argstr="--${cargoCheckType} --target @rustTargetPlatformSpec@ --frozen";
argstr="--${cargoCheckType} --target @rustTargetPlatformSpec@ --frozen ${cargoTestFlags}";

(
set -x
Expand Down

0 comments on commit ebe3ae4

Please sign in to comment.