libhwy: split in several outputs and enable shared libs (#557544)

This commit is contained in:
Arne Keller
2026-09-04 12:48:59 +00:00
committed by GitHub
3 changed files with 83 additions and 36 deletions

View File

@@ -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@

View File

@@ -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"
];
};
}
})

View File

@@ -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)"