nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ stdenv, lib, fetchFromGitHub
2, fetchpatch
3, asciidoc
4, brotli
5, cmake
6, graphviz
7, doxygen
8, giflib
9, gperftools
10, gtest
11, libhwy
12, libjpeg
13, libpng
14, libwebp
15, openexr
16, pkg-config
17, python3
18, zlib
19}:
20
21stdenv.mkDerivation rec {
22 pname = "libjxl";
23 version = "0.6.1";
24
25 src = fetchFromGitHub {
26 owner = "libjxl";
27 repo = "libjxl";
28 rev = "v${version}";
29 sha256 = "sha256-fTK5hyU9PZ6nigMsfzVugwviihgAXfEcLF+l+n5h+54=";
30 # There are various submodules in `third_party/`.
31 fetchSubmodules = true;
32 };
33
34 patches = [
35 # present in master, remove after 0.7?
36 (fetchpatch {
37 name = "fix-link-lld-macho.patch";
38 url = "https://github.com/libjxl/libjxl/commit/88fe3fff3dc70c72405f57c69feffd9823930034.patch";
39 sha256 = "1419fyiq4srpj72cynwyvqy8ldi7vn9asvkp5fsbmiqkyhb15jpk";
40 })
41
42 # "robust statistics" have been removed in upstream mainline as they are
43 # conidered to cause "interoperability problems". sure enough the tests
44 # fail with precision issues on aarch64.
45 (fetchpatch {
46 name = "remove-robust-and-descriptive-statistics.patch";
47 url = "https://github.com/libjxl/libjxl/commit/204f87a5e4d684544b13900109abf040dc0b402b.patch";
48 sha256 = "sha256-DoAaYWLmQ+R9GZbHMTYGe0gBL9ZesgtB+2WhmbARna8=";
49 })
50 ];
51
52 nativeBuildInputs = [
53 asciidoc # for docs
54 cmake
55 graphviz # for docs via doxygen component `dot`
56 doxygen # for docs
57 gtest
58 pkg-config
59 python3 # for docs
60 ];
61
62 # Functionality not currently provided by this package
63 # that the cmake build can apparently use:
64 # OpenGL/GLUT (for Examples -> comparison with sjpeg)
65 # viewer (see `cmakeFlags`)
66 # plugins like for GDK and GIMP (see `cmakeFlags`)
67
68 # Vendored libraries:
69 # `libjxl` currently vendors many libraries as git submodules that they
70 # might patch often (e.g. test/gmock, see
71 # https://github.com/NixOS/nixpkgs/pull/103160#discussion_r519487734).
72 # When it has stabilised in the future, we may want to tell the build
73 # to use use nixpkgs system libraries.
74
75 # As of writing, libjxl does not point out all its dependencies
76 # conclusively in its README or otherwise; they can best be determined
77 # by checking the CMake output for "Could NOT find".
78 buildInputs = [
79 brotli
80 giflib
81 gperftools # provides `libtcmalloc`
82 libhwy
83 libjpeg
84 libpng
85 libwebp
86 openexr
87 zlib
88 ];
89
90 cmakeFlags = [
91 # For C dependencies like brotli, which are dynamically linked,
92 # we want to use the system libraries, so that we don't have to care about
93 # installing their .so files generated by this build.
94 # The other C++ dependencies are statically linked in, so there
95 # using the vendorered ones is easier.
96 "-DJPEGXL_FORCE_SYSTEM_BROTLI=ON"
97
98 # Use our version of highway, though it is still statically linked in
99 "-DJPEGXL_FORCE_SYSTEM_HWY=ON"
100
101 # TODO: Update this package to enable this (overridably via an option):
102 # Viewer tools for evaluation.
103 # "-DJPEGXL_ENABLE_VIEWERS=ON"
104
105 # TODO: Update this package to enable this (overridably via an option):
106 # Enable plugins, such as:
107 # * the `gdk-pixbuf` one, which allows applications like `eog` to load jpeg-xl files
108 # * the `gimp` one, which allows GIMP to load jpeg-xl files
109 # "-DJPEGXL_ENABLE_PLUGINS=ON"
110 ];
111
112 LDFLAGS = lib.optionalString stdenv.hostPlatform.isRiscV "-latomic";
113
114 doCheck = !stdenv.hostPlatform.isi686;
115
116 # The test driver runs a test `LibraryCLinkageTest` which without
117 # LD_LIBRARY_PATH setting errors with:
118 # /build/source/build/tools/tests/libjxl_test: error while loading shared libraries: libjxl.so.0
119 # The required file is in the build directory (`$PWD`).
120 preCheck = if stdenv.isDarwin then ''
121 export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH''${DYLD_LIBRARY_PATH:+:}$PWD
122 '' else ''
123 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}$PWD
124 '';
125
126 meta = with lib; {
127 homepage = "https://github.com/libjxl/libjxl";
128 description = "JPEG XL image format reference implementation.";
129 license = licenses.bsd3;
130 maintainers = with maintainers; [ nh2 ];
131 platforms = platforms.all;
132 };
133}