From fa62f3716077be3239765b041702ed401bc257e3 Mon Sep 17 00:00:00 2001 From: Max Hausch Date: Wed, 24 Feb 2021 09:25:49 +0100 Subject: [PATCH 1/2] doc: rust: Fix code blocks in markdown And add a word --- doc/languages-frameworks/rust.section.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 1a749d2c847..48510b37add 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -72,8 +72,8 @@ For `cargoHash` you can use: Per the instructions in the [Cargo Book](https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html) best practices guide, Rust applications should always commit the `Cargo.lock` file in git to ensure a reproducible build. However, a few packages do not, and -Nix depends on this file, so if it missing you can use `cargoPatches` to apply -it in the `patchPhase`. Consider sending a PR upstream with a note to the +Nix depends on this file, so if it is missing you can use `cargoPatches` to +apply it in the `patchPhase`. Consider sending a PR upstream with a note to the maintainer describing why it's important to include in the application. The fetcher will verify that the `Cargo.lock` file is in sync with the `src` @@ -146,6 +146,8 @@ where they are known to differ. But there are ways to customize the argument: rustc.platform = { foo = ""; bar = ""; }; }; } + ``` + will result in: ```shell --target /nix/store/asdfasdfsadf-thumb-crazy.json # contains {"foo":"","bar":""} @@ -156,7 +158,7 @@ path) can be passed directly to `buildRustPackage`: ```nix pkgs.rustPlatform.buildRustPackage { - (...) + /* ... */ target = "x86_64-fortanix-unknown-sgx"; } ``` From ebe3ae4d4d4668f3f47a30f10592714df1c9b803 Mon Sep 17 00:00:00 2001 From: Max Hausch Date: Wed, 24 Feb 2021 09:32:22 +0100 Subject: [PATCH 2/2] buildRustPackage: Add cargoTestFlags This makes it possible to pass flags to `cargo test`, which is needed if a crate is compiled with custom feature flags. --- doc/languages-frameworks/rust.section.md | 7 +++++++ pkgs/build-support/rust/hooks/cargo-check-hook.sh | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 48510b37add..a3f0238bf3a 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -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 diff --git a/pkgs/build-support/rust/hooks/cargo-check-hook.sh b/pkgs/build-support/rust/hooks/cargo-check-hook.sh index 82e669af3a0..bc913c6ab07 100644 --- a/pkgs/build-support/rust/hooks/cargo-check-hook.sh +++ b/pkgs/build-support/rust/hooks/cargo-check-hook.sh @@ -1,4 +1,5 @@ declare -a checkFlags +declare -a cargoTestFlags cargoCheckHook() { echo "Executing cargoCheckHook" @@ -15,7 +16,7 @@ cargoCheckHook() { threads=1 fi - argstr="--${cargoCheckType} --target @rustTargetPlatformSpec@ --frozen"; + argstr="--${cargoCheckType} --target @rustTargetPlatformSpec@ --frozen ${cargoTestFlags}"; ( set -x