From bdc960ea0c71c436493ab0b8756ad4ecccf0b6b3 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 29 Aug 2026 01:04:49 +0200 Subject: [PATCH] libhwy: split in several outputs and enable shared libs --- .../move-contrib-to-its-own-output.patch | 19 ++++ pkgs/by-name/li/libhwy/package.nix | 99 ++++++++++++------- pkgs/by-name/ss/ssimulacra2/package.nix | 1 + 3 files changed, 83 insertions(+), 36 deletions(-) create mode 100644 pkgs/by-name/li/libhwy/move-contrib-to-its-own-output.patch diff --git a/pkgs/by-name/li/libhwy/move-contrib-to-its-own-output.patch b/pkgs/by-name/li/libhwy/move-contrib-to-its-own-output.patch new file mode 100644 index 000000000000..72c21d52b979 --- /dev/null +++ b/pkgs/by-name/li/libhwy/move-contrib-to-its-own-output.patch @@ -0,0 +1,19 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -657,4 +657,4 @@ + install(TARGETS hwy_contrib EXPORT hwy_targets +- LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" +- ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" +- RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") ++ LIBRARY DESTINATION "${CMAKE_CONTRIB_PREFIX}/${CMAKE_INSTALL_LIBDIR}" ++ ARCHIVE DESTINATION "${CMAKE_CONTRIB_PREFIX}/${CMAKE_INSTALL_LIBDIR}" ++ RUNTIME DESTINATION "${CMAKE_CONTRIB_PREFIX}/${CMAKE_INSTALL_BINDIR}") +diff --git a/libhwy-contrib.pc.in b/libhwy-contrib.pc.in +--- a/libhwy-contrib.pc.in ++++ b/libhwy-contrib.pc.in +@@ -1,3 +1,3 @@ + prefix=@CMAKE_INSTALL_PREFIX@ +-exec_prefix=${prefix} ++exec_prefix=@CMAKE_CONTRIB_PREFIX@ + libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@ diff --git a/pkgs/by-name/li/libhwy/package.nix b/pkgs/by-name/li/libhwy/package.nix index fc60dbff5d0a..b507bebd61ec 100644 --- a/pkgs/by-name/li/libhwy/package.nix +++ b/pkgs/by-name/li/libhwy/package.nix @@ -5,19 +5,32 @@ ninja, gtest, fetchFromGitHub, + testers, + nix-update-script, }: -stdenv.mkDerivation rec { +stdenv.mkDerivation (finalAttrs: { pname = "libhwy"; version = "1.4.0"; + __structuredAttrs = true; + outputs = [ + "out" + "dev" + "contrib" + ]; + src = fetchFromGitHub { owner = "google"; repo = "highway"; - rev = version; + tag = finalAttrs.version; hash = "sha256-YUYZO9KLffczjwIz3mBBceD6oM1giLCFLDHgDCevdRA="; }; + patches = [ + ./move-contrib-to-its-own-output.patch + ]; + hardeningDisable = lib.optionals stdenv.hostPlatform.isAarch64 [ # aarch64-specific code gets: # __builtin_clear_padding not supported for variable length aggregates @@ -29,46 +42,56 @@ stdenv.mkDerivation rec { ninja ]; + checkInputs = [ + gtest + ]; + # Required for case-insensitive filesystems ("BUILD" exists) dontUseCmakeBuildDir = true; - cmakeFlags = - let - libExt = stdenv.hostPlatform.extensions.library; - in - [ - "-GNinja" - "-DCMAKE_INSTALL_LIBDIR=lib" - "-DCMAKE_INSTALL_INCLUDEDIR=include" - ] - ++ lib.optionals doCheck [ - "-DHWY_SYSTEM_GTEST:BOOL=ON" - "-DGTEST_INCLUDE_DIR=${lib.getDev gtest}/include" - "-DGTEST_LIBRARY=${lib.getLib gtest}/lib/libgtest${libExt}" - "-DGTEST_MAIN_LIBRARY=${lib.getLib gtest}/lib/libgtest_main${libExt}" - ] - ++ lib.optionals stdenv.hostPlatform.isAarch32 [ - "-DHWY_CMAKE_ARM7=ON" - ] - ++ lib.optionals stdenv.hostPlatform.isx86_32 [ - # Quoting CMakelists.txt: - # This must be set on 32-bit x86 with GCC < 13.1, otherwise math_test will be - # skipped. For GCC 13.1+, you can also build with -fexcess-precision=standard. - # Fixes tests: - # HwyMathTestGroup/HwyMathTest.TestAllAtanh/EMU128 - # HwyMathTestGroup/HwyMathTest.TestAllLog1p/EMU128 - "-DHWY_CMAKE_SSE2=ON" - ] - ++ lib.optionals stdenv.hostPlatform.isRiscV [ - # Runtime dispatch is not implemented https://github.com/google/highway/issues/838 - # so tests (and likely normal operation) fail with SIGILL on processors without V. - # Until the issue is resolved, we disable RVV completely. - "-DHWY_CMAKE_RVV=OFF" - ]; + cmakeFlags = [ + "-GNinja" + "-DCMAKE_INSTALL_LIBDIR=lib" + "-DCMAKE_INSTALL_INCLUDEDIR=include" + "-DCMAKE_CONTRIB_PREFIX=${placeholder "contrib"}" + (lib.cmakeBool "BUILD_SHARED_LIBS" (!stdenv.hostPlatform.isStatic)) + (lib.cmakeBool "HWY_ENABLE_TESTS" finalAttrs.finalPackage.doCheck) + ] + ++ lib.optional finalAttrs.finalPackage.doCheck (lib.cmakeBool "HWY_SYSTEM_GTEST" true) + ++ lib.optionals stdenv.hostPlatform.isAarch32 [ + "-DHWY_CMAKE_ARM7=ON" + ] + ++ lib.optionals stdenv.hostPlatform.isx86_32 [ + # Quoting CMakelists.txt: + # This must be set on 32-bit x86 with GCC < 13.1, otherwise math_test will be + # skipped. For GCC 13.1+, you can also build with -fexcess-precision=standard. + # Fixes tests: + # HwyMathTestGroup/HwyMathTest.TestAllAtanh/EMU128 + # HwyMathTestGroup/HwyMathTest.TestAllLog1p/EMU128 + "-DHWY_CMAKE_SSE2=ON" + ] + ++ lib.optionals stdenv.hostPlatform.isRiscV [ + # Runtime dispatch is not implemented https://github.com/google/highway/issues/838 + # so tests (and likely normal operation) fail with SIGILL on processors without V. + # Until the issue is resolved, we disable RVV completely. + "-DHWY_CMAKE_RVV=OFF" + ]; + + # Consumers rely on test headers being exported, but CMake install them only when tests are enabled. + postInstall = lib.optionalString (!finalAttrs.finalPackage.doCheck) '' + install -Dm644 hwy/tests/*.h -t $out/include/hwy/tests/ + ''; # hydra's darwin machines run into https://github.com/libjxl/libjxl/issues/408 doCheck = !stdenv.hostPlatform.isDarwin; + passthru = { + updateScript = nix-update-script { }; + tests.pkg-config = testers.hasPkgConfigModules { + package = finalAttrs.finalPackage; + }; + }; + meta = { description = "Performance-portable, length-agnostic SIMD with runtime dispatch"; homepage = "https://github.com/google/highway"; @@ -78,5 +101,9 @@ stdenv.mkDerivation rec { ]; platforms = lib.platforms.unix; maintainers = with lib.maintainers; [ zhaofengli ]; + pkgConfigModules = [ + "libhwy" + "libhwy-contrib" + ]; }; -} +}) diff --git a/pkgs/by-name/ss/ssimulacra2/package.nix b/pkgs/by-name/ss/ssimulacra2/package.nix index d7ce465793ac..f8c575bb2194 100644 --- a/pkgs/by-name/ss/ssimulacra2/package.nix +++ b/pkgs/by-name/ss/ssimulacra2/package.nix @@ -36,6 +36,7 @@ stdenv.mkDerivation (finalAttrs: { rev = version; hash = "sha256-v2HyyHtBydr7QiI83DW1yRv2kWjUOGxFT6mmdrN9XPo="; }; + outputs = [ "out" ]; patches = [ ]; postPatch = '' substituteInPlace CMakeLists.txt --replace-fail "set(CMAKE_CXX_STANDARD 11)" "set(CMAKE_CXX_STANDARD 17)"