Skip to content

Commit a8e7f33

Browse files
committed
Export tests option for Rust
1 parent 0545524 commit a8e7f33

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

examples/rust-flake-project/build.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
crateName = "rust-flake-project";
99

1010
devShellHook = config.settings.shell.hook;
11-
11+
exportTests = true;
1212
};
1313
in
1414
{

flake-lang/rust/description.md

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Creates a flake for a Rust project.
3333
- `generateDocs`(default=true): Generate Rustdoc
3434
- `runTests`(default=true): Run testsuite using cargo-nextest
3535
- `runClippy`(default=true): Run clippy linter
36+
- `exportTests`(default=false): Build testsuite as standalone executables
3637

3738
**Returns:**
3839

flake-lang/rust/flake-rust.nix

+15
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ inputCrane: pkgs:
4747
extraEnvVars ? null
4848
# Generate Rustdoc
4949
, generateDocs ? true
50+
# Build testsuite as standalone executables
51+
, exportTests ? false
5052
# Run testsuite using cargo-nextest
5153
, runTests ? true
5254
# Run clippy linter
@@ -206,6 +208,18 @@ in
206208
inherit doInstallCargoArtifacts;
207209
});
208210

211+
}) // (optionalAttrs exportTests {
212+
"${crateName}-rust-test" = craneLib.buildPackage (commonArgs // {
213+
inherit cargoArtifacts;
214+
cargoExtraArgs = cargoNextestExtraArgs + " --tests";
215+
nativeBuildInputs = commonArgs.nativeBuildInputs ++ testTools ++ [ pkgs.jq ];
216+
installPhaseCommand = ''
217+
files=$(cat $cargoBuildLog | jq 'select(.target.kind | . != null and contains(["test"])).executable')
218+
mkdir -p $out/bin
219+
220+
echo $files | xargs -r mv -t $out/bin
221+
'';
222+
});
209223
}) // {
210224
"${crateName}-rust" = craneLib.buildPackage (commonArgs // {
211225
inherit cargoArtifacts;
@@ -217,6 +231,7 @@ in
217231
"${crateName}-rust-src" = vendoredSrc;
218232

219233
"${crateName}-rust-build-env" = buildEnv;
234+
220235
};
221236

222237
checks =

0 commit comments

Comments
 (0)