summary refs log tree commit diff
path: root/pkgs/build-support/rust/build-rust-crate/install-crate.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/build-support/rust/build-rust-crate/install-crate.nix')
-rw-r--r--pkgs/build-support/rust/build-rust-crate/install-crate.nix23
1 files changed, 21 insertions, 2 deletions
diff --git a/pkgs/build-support/rust/build-rust-crate/install-crate.nix b/pkgs/build-support/rust/build-rust-crate/install-crate.nix
index 934c3a03176..5ba7b69bedc 100644
--- a/pkgs/build-support/rust/build-rust-crate/install-crate.nix
+++ b/pkgs/build-support/rust/build-rust-crate/install-crate.nix
@@ -1,5 +1,6 @@
-crateName: metadata:
-''
+{ stdenv }:
+crateName: metadata: buildTests:
+if !buildTests then ''
   runHook preInstall
   # always create $out even if we do not have binaries. We are detecting binary targets during compilation, if those are missing there is no way to only have $lib
   mkdir $out
@@ -29,4 +30,22 @@ crateName: metadata:
     fi
   fi
   runHook postInstall
+'' else
+# for tests we just put them all in the output. No execution.
+''
+  runHook preInstall
+
+  mkdir -p $out/tests
+  if [ -e target/bin ]; then
+    find target/bin/ -type f -executable -exec cp {} $out/tests \;
+  fi
+  if [ -e target/lib ]; then
+    find target/lib/ -type f \! -name '*.rlib' \
+      -a \! -name '*${stdenv.hostPlatform.extensions.sharedLibrary}' \
+      -a \! -name '*.d' \
+      -executable \
+      -print0 | xargs --no-run-if-empty --null install --target $out/tests;
+  fi
+
+  runHook postInstall
 ''