Skip to content

Commit c2e1200

Browse files
committed
build gtest statically
1 parent dcd34df commit c2e1200

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

nix/all.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ pkgs.stdenv.mkDerivation {
5656
mkdir -p $out/bin
5757
cp build/tests/lgx_tests $out/bin/
5858
cp build/tests/lgx_lib_tests $out/bin/
59+
60+
# Fix rpath for lgx_lib_tests to find liblgx.so at $out/lib
61+
# Keep Nix store entries (libstdc++, etc.) but replace /build/ paths
62+
if [ -f $out/bin/lgx_lib_tests ]; then
63+
if [[ "$(uname)" == "Darwin" ]]; then
64+
install_name_tool -add_rpath $out/lib $out/bin/lgx_lib_tests
65+
else
66+
old_rpath=$(patchelf --print-rpath $out/bin/lgx_lib_tests)
67+
new_rpath=$(echo "$old_rpath" | tr ':' '\n' | grep -v '/build/' | tr '\n' ':' | sed 's/:$//')
68+
patchelf --set-rpath "$out/lib:$new_rpath" $out/bin/lgx_lib_tests
69+
fi
70+
fi
5971
6072
# Fix rpath for lgx_lib_tests to find the shared library
6173
if [ -f $out/bin/lgx_lib_tests ]; then

nix/default.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
pkgs.zlib
1818
pkgs.icu
1919
pkgs.nlohmann_json
20-
pkgs.gtest
20+
# GTest built static so test binaries don't depend on libgtest at runtime
21+
(pkgs.gtest.overrideAttrs (old: {
22+
cmakeFlags = (old.cmakeFlags or [ ]) ++ [ "-DBUILD_SHARED_LIBS=OFF" ];
23+
}))
2124
];
2225

2326
# Common CMake flags

0 commit comments

Comments
 (0)