about summary refs log tree commit diff
path: root/third_party/nix/default.nix
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2020-07-17T01·19+0100
committertazjin <mail@tazj.in>2020-07-18T00·01+0000
commitf4f72bcf21127a1f75baa988b765317e80a7486e (patch)
tree138eb7710d8ab361c7a2f9ff51677ed91431ba9e /third_party/nix/default.nix
parente4b7d6d5925208214927a9e8c8fd72c246bc70ff (diff)
test(3p/nix): Set up scaffolding & fix up tests for value-to-{json|xml} r/1369
Configures the CMake build to load & run the GoogleTest tests.

I (grfn) also updated this to get the tests running as part of the nix
derivation, which required defining our own manual configurePhase and
installCheckPhase, rather than depending on the one provided by stdenv.
Not doing this would cause cmake to attempt to *run* the tests as part
of the buildPhase, which wouldn't work because the dynamic libraries
hadn't been put into a place where the test executables knew where to
find them. We're not sure *why* this fixes it, and for some reason
fixing this also breaks the automatic behavior of nixpkgs of passing
-j$NIX_BUILD_CORES -l$NIX_BUILD_CORES to make, but that's eaasy enough
to fix manually in a preBuild

Paired-With: Griffin Smith <grfn@gws.fyi>
Change-Id: I79d61854a3ff47301cdce8a40c76820a97bdf901
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1240
Tested-by: BuildkiteCI
Reviewed-by: glittershark <grfn@gws.fyi>
Diffstat (limited to 'third_party/nix/default.nix')
-rw-r--r--third_party/nix/default.nix27
1 files changed, 27 insertions, 0 deletions
diff --git a/third_party/nix/default.nix b/third_party/nix/default.nix
index f998960214..ad1ff5beeb 100644
--- a/third_party/nix/default.nix
+++ b/third_party/nix/default.nix
@@ -52,6 +52,7 @@ in pkgs.llvmPackages.libcxxStdenv.mkDerivation {
     flex
     glog
     grpc
+    gtest
     libseccomp
     libsodium
     openssl
@@ -60,11 +61,37 @@ in pkgs.llvmPackages.libcxxStdenv.mkDerivation {
     xz
   ];
 
+  doCheck = false;
+  doInstallCheck = true;
+
   propagatedBuildInputs = with pkgs; [
     boost
     largeBoehm
   ];
 
+  configurePhase = ''
+    mkdir build
+    cd build
+    cmake .. \
+      -DCMAKE_INSTALL_PREFIX=$out \
+      -DCMAKE_BUILD_TYPE=Release \
+      -DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF \
+      -DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF \
+      -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON
+  '';
+
+  installCheckPhase = ''
+    export NIX_DATA_DIR=$out/share
+    make test
+  '';
+
+  preBuild = ''
+    if [ -n "$NIX_BUILD_CORES" ]; then
+      makeFlags+="-j$NIX_BUILD_CORES "
+      makeFlags+="-l$NIX_BUILD_CORES "
+    fi
+  '';
+
   # Forward the location of the generated Protobuf / gRPC files so
   # that they can be included by CMake.
   NIX_PROTO_SRCS = protoSrcs;