Files
logos-liblogos/nix/tests.nix
Iuri Matias 9cb8c09dbc replace qt logs (#110)
replace qt logs

fix spdlog in the tests

fix spdlog in the tests
2026-04-15 15:46:19 -04:00

83 lines
2.9 KiB
Nix

# Builds tests
{ pkgs, common, build }:
pkgs.stdenv.mkDerivation {
pname = "${common.pname}-tests";
version = common.version;
inherit (build) src;
inherit (common) buildInputs meta env;
# Add platform-specific tools conditionally
nativeBuildInputs = common.nativeBuildInputs
++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ pkgs.darwin.cctools ]
++ pkgs.lib.optionals pkgs.stdenv.isLinux [ pkgs.patchelf ];
# Use the same CMake flags as the main build
cmakeFlags = common.cmakeFlags;
# Configure phase - reuse build outputs
configurePhase = ''
runHook preConfigure
# Copy the built artifacts from the main build
cp -r ${build}/* .
chmod -R u+w .
# Reconfigure to generate test targets
cmake -B build -S ${build.src} \
-GNinja \
-DLOGOS_CPP_SDK_ROOT=${common.env.LOGOS_CPP_SDK_ROOT} \
-DLOGOS_MODULE_ROOT=${common.env.LOGOS_MODULE_ROOT} \
-DPROCESS_STATS_ROOT=${common.env.PROCESS_STATS_ROOT} \
-DLOGOS_PACKAGE_MANAGER_ROOT=${common.env.LOGOS_PACKAGE_MANAGER_ROOT} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$out
runHook postConfigure
'';
# Build phase - build the test executable
buildPhase = ''
runHook preBuild
cd build
ninja logos_core_tests
runHook postBuild
'';
# Install phase - install the test executable
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp bin/logos_core_tests $out/bin/
# Copy the libraries so tests can run
mkdir -p $out/lib
cp -r lib/* $out/lib/ || true
# Copy package_manager_lib from its nix store path
cp ${common.env.LOGOS_PACKAGE_MANAGER_ROOT}/lib/libpackage_manager_lib.* $out/lib/ || true
${pkgs.lib.optionalString pkgs.stdenv.isDarwin ''
# Fix RPATH to find libraries in $out/lib on macOS
install_name_tool \
-change @rpath/liblogos_core.dylib $out/lib/liblogos_core.dylib \
$out/bin/logos_core_tests || true
''}
${pkgs.lib.optionalString pkgs.stdenv.isLinux ''
# Fix RPATH on Linux to avoid /build/ references and include all dependencies.
# spdlog links libfmt; both must be on RPATH because patchelf replaces the default search paths.
_rpath="$out/lib:${pkgs.boost}/lib:${common.env.LOGOS_PACKAGE_MANAGER_ROOT}/lib:${pkgs.gtest}/lib:${pkgs.qt6.qtbase}/lib:${pkgs.qt6.qtremoteobjects}/lib:${pkgs.spdlog}/lib:${pkgs.fmt}/lib:${pkgs.stdenv.cc.cc.lib}/lib"
patchelf --set-rpath "$_rpath" $out/bin/logos_core_tests || true
# Fix RPATH on liblogos_core.so so it can find its transitive deps (e.g. libboost_process, spdlog, fmt)
_rpath_lib="$out/lib:${pkgs.boost}/lib:${common.env.LOGOS_PACKAGE_MANAGER_ROOT}/lib:${pkgs.qt6.qtbase}/lib:${pkgs.qt6.qtremoteobjects}/lib:${pkgs.spdlog}/lib:${pkgs.fmt}/lib:${pkgs.stdenv.cc.cc.lib}/lib"
patchelf --set-rpath "$_rpath_lib" $out/lib/liblogos_core.so || true
''}
runHook postInstall
'';
}