btrbk: add mainProgram (#356350)
[NixPkgs.git] / pkgs / by-name / li / libjxl / package.nix
blob2bd30ddda8e26f50c41d8b01c10e73dd4db25591
1 { stdenv, lib, fetchFromGitHub
2 , brotli
3 , cmake
4 , giflib
5 , gperftools
6 , gtest
7 , libhwy
8 , libjpeg
9 , libpng
10 , libwebp
11 , gdk-pixbuf
12 , openexr_3
13 , pkg-config
14 , makeWrapper
15 , zlib
16 , asciidoc
17 , graphviz
18 , doxygen
19 , python3
20 , lcms2
21 , enablePlugins ? true
24 let
25   loadersPath = "${gdk-pixbuf.binaryDir}/jxl-loaders.cache";
28 stdenv.mkDerivation rec {
29   pname = "libjxl";
30   version = "0.11.0";
32   outputs = [ "out" "dev" ];
34   src = fetchFromGitHub {
35     owner = "libjxl";
36     repo = "libjxl";
37     rev = "v${version}";
38     hash = "sha256-lBc0zP+f44YadwOU9+I+YYWzTrAg7FSfF3IQuh4LjM4=";
39     # There are various submodules in `third_party/`.
40     fetchSubmodules = true;
41   };
43   strictDeps = true;
45   nativeBuildInputs = [
46     cmake
47     pkg-config
48     gdk-pixbuf
49     makeWrapper
50     asciidoc
51     doxygen
52     python3
53   ];
55   depsBuildBuild = [
56     graphviz
57   ];
59   # Functionality not currently provided by this package
60   # that the cmake build can apparently use:
61   #     OpenGL/GLUT (for Examples -> comparison with sjpeg)
62   #     viewer (see `cmakeFlags`)
63   #     plugins like for GDK and GIMP (see `cmakeFlags`)
65   # Vendored libraries:
66   # `libjxl` currently vendors many libraries as git submodules that they
67   # might patch often (e.g. test/gmock, see
68   # https://github.com/NixOS/nixpkgs/pull/103160#discussion_r519487734).
69   # When it has stabilised in the future, we may want to tell the build
70   # to use use nixpkgs system libraries.
72   # As of writing, libjxl does not point out all its dependencies
73   # conclusively in its README or otherwise; they can best be determined
74   # by checking the CMake output for "Could NOT find".
75   buildInputs = [
76     lcms2
77     giflib
78     gperftools # provides `libtcmalloc`
79     gtest
80     libjpeg
81     libpng
82     libwebp
83     gdk-pixbuf
84     openexr_3
85     zlib
86   ];
88   propagatedBuildInputs = [
89     brotli
90     libhwy
91   ];
93   cmakeFlags = [
94     # For C dependencies like brotli, which are dynamically linked,
95     # we want to use the system libraries, so that we don't have to care about
96     # installing their .so files generated by this build.
97     # The other C++ dependencies are statically linked in, so there
98     # using the vendorered ones is easier.
99     "-DJPEGXL_FORCE_SYSTEM_BROTLI=ON"
101     # Use our version of highway, though it is still statically linked in
102     "-DJPEGXL_FORCE_SYSTEM_HWY=ON"
104     # Use our version of gtest
105     "-DJPEGXL_FORCE_SYSTEM_GTEST=ON"
107     # TODO: Update this package to enable this (overridably via an option):
108     # Viewer tools for evaluation.
109     # "-DJPEGXL_ENABLE_VIEWERS=ON"
110   ] ++ lib.optionals enablePlugins [
111     # Enable plugins, such as:
112     # * the `gdk-pixbuf` one, which allows applications like `eog` to load jpeg-xl files
113     # * the `gimp` one, which allows GIMP to load jpeg-xl files
114     "-DJPEGXL_ENABLE_PLUGINS=ON"
115   ] ++ lib.optionals stdenv.hostPlatform.isStatic [
116     "-DJPEGXL_STATIC=ON"
117   ] ++ lib.optionals stdenv.hostPlatform.isAarch32 [
118     "-DJPEGXL_FORCE_NEON=ON"
119   ];
121   # the second substitution fix regex for a2x script
122   # https://github.com/libjxl/libjxl/pull/3842
123   postPatch = ''
124     substituteInPlace plugins/gdk-pixbuf/jxl.thumbnailer \
125       --replace '/usr/bin/gdk-pixbuf-thumbnailer' "$out/libexec/gdk-pixbuf-thumbnailer-jxl"
126     substituteInPlace CMakeLists.txt \
127       --replace 'sh$' 'sh( -e$|$)'
128   '';
130   postInstall = lib.optionalString enablePlugins ''
131     GDK_PIXBUF_MODULEDIR="$out/${gdk-pixbuf.moduleDir}" \
132     GDK_PIXBUF_MODULE_FILE="$out/${loadersPath}" \
133       gdk-pixbuf-query-loaders --update-cache
134   ''
135   # Cross-compiled gdk-pixbuf doesn't support thumbnailers
136   + lib.optionalString (enablePlugins && stdenv.hostPlatform == stdenv.buildPlatform) ''
137     mkdir -p "$out/bin"
138     makeWrapper ${gdk-pixbuf}/bin/gdk-pixbuf-thumbnailer "$out/libexec/gdk-pixbuf-thumbnailer-jxl" \
139       --set GDK_PIXBUF_MODULE_FILE "$out/${loadersPath}"
140   '';
142   CXXFLAGS = lib.optionalString stdenv.hostPlatform.isAarch32 "-mfp16-format=ieee";
144   # FIXME x86_64-darwin:
145   # https://github.com/NixOS/nixpkgs/pull/204030#issuecomment-1352768690
146   doCheck = with stdenv; !(hostPlatform.isi686 || isDarwin && isx86_64);
148   meta = with lib; {
149     homepage = "https://github.com/libjxl/libjxl";
150     description = "JPEG XL image format reference implementation";
151     license = licenses.bsd3;
152     maintainers = with maintainers; [ nh2 ];
153     platforms = platforms.all;
154   };