btrbk: add mainProgram
[NixPkgs.git] / pkgs / by-name / li / libhwy / package.nix
blob7bf78ec875e21062a9b4eb05ed01b26417353315
1 { lib
2 , stdenv
3 , cmake
4 , ninja
5 , gtest
6 , fetchFromGitHub
7 , fetchpatch
8 }:
10 stdenv.mkDerivation rec {
11   pname = "libhwy";
12   version = "1.0.7";
14   src = fetchFromGitHub {
15     owner = "google";
16     repo = "highway";
17     rev = version;
18     hash = "sha256-Z+mAR9nSAbCskUvo6oK79Yd85bu0HtI2aR5THS1EozM=";
19   };
21   patches = lib.optional stdenv.hostPlatform.isRiscV
22     # Adds CMake option HWY_CMAKE_RVV
23     # https://github.com/google/highway/pull/1743
24     (fetchpatch {
25       name = "libhwy-add-rvv-optout.patch";
26       url = "https://github.com/google/highway/commit/5d58d233fbcec0c6a39df8186a877329147324b3.patch";
27       hash = "sha256-ileSNYddOt1F5rooRB0fXT20WkVlnG+gP5w7qJdBuww=";
28     });
30   hardeningDisable = lib.optionals stdenv.hostPlatform.isAarch64 [
31     # aarch64-specific code gets:
32     # __builtin_clear_padding not supported for variable length aggregates
33     "trivialautovarinit"
34   ];
36   nativeBuildInputs = [ cmake ninja ];
38   # Required for case-insensitive filesystems ("BUILD" exists)
39   dontUseCmakeBuildDir = true;
41   cmakeFlags = let
42     libExt = stdenv.hostPlatform.extensions.library;
43   in [
44     "-GNinja"
45     "-DCMAKE_INSTALL_LIBDIR=lib"
46     "-DCMAKE_INSTALL_INCLUDEDIR=include"
47   ] ++ lib.optionals doCheck [
48     "-DHWY_SYSTEM_GTEST:BOOL=ON"
49     "-DGTEST_INCLUDE_DIR=${lib.getDev gtest}/include"
50     "-DGTEST_LIBRARY=${lib.getLib gtest}/lib/libgtest${libExt}"
51     "-DGTEST_MAIN_LIBRARY=${lib.getLib gtest}/lib/libgtest_main${libExt}"
52   ] ++ lib.optionals stdenv.hostPlatform.isAarch32 [
53     "-DHWY_CMAKE_ARM7=ON"
54   ] ++ lib.optionals stdenv.hostPlatform.isx86_32 [
55     # Quoting CMakelists.txt:
56     #   This must be set on 32-bit x86 with GCC < 13.1, otherwise math_test will be
57     #   skipped. For GCC 13.1+, you can also build with -fexcess-precision=standard.
58     # Fixes tests:
59     #   HwyMathTestGroup/HwyMathTest.TestAllAtanh/EMU128
60     #   HwyMathTestGroup/HwyMathTest.TestAllLog1p/EMU128
61     "-DHWY_CMAKE_SSE2=ON"
62   ] ++ lib.optionals stdenv.hostPlatform.isRiscV [
63     # Runtime dispatch is not implemented https://github.com/google/highway/issues/838
64     # so tests (and likely normal operation) fail with SIGILL on processors without V.
65     # Until the issue is resolved, we disable RVV completely.
66     "-DHWY_CMAKE_RVV=OFF"
67   ];
69   # hydra's darwin machines run into https://github.com/libjxl/libjxl/issues/408
70   doCheck = !stdenv.hostPlatform.isDarwin;
72   meta = with lib; {
73     description = "Performance-portable, length-agnostic SIMD with runtime dispatch";
74     homepage = "https://github.com/google/highway";
75     license = with licenses; [ asl20 bsd3 ];
76     platforms = platforms.unix;
77     maintainers = with maintainers; [ zhaofengli ];
78   };