tailscale: build derpprobe (#364918)
[NixPkgs.git] / pkgs / development / libraries / qt-5 / modules / qtwebengine.nix
blob48b343435d387b8fc7e9bb5054529c416184c26c
2   qtModule,
3   qtdeclarative,
4   qtquickcontrols,
5   qtlocation,
6   qtwebchannel,
7   fetchpatch,
8   fetchpatch2,
10   bison,
11   flex,
12   git,
13   gperf,
14   ninja,
15   pkg-config,
16   python,
17   which,
18   nodejs,
19   perl,
20   buildPackages,
21   pkgsBuildTarget,
22   pkgsBuildBuild,
24   xorg,
25   libXcursor,
26   libXScrnSaver,
27   libXrandr,
28   libXtst,
29   fontconfig,
30   freetype,
31   harfbuzz,
32   icu,
33   dbus,
34   libdrm,
35   zlib,
36   minizip,
37   libjpeg,
38   libpng,
39   libtiff,
40   libwebp,
41   libopus,
42   jsoncpp,
43   protobuf,
44   libvpx,
45   srtp,
46   snappy,
47   nss,
48   libevent,
49   alsa-lib,
50   pulseaudio,
51   libcap,
52   pciutils,
53   systemd,
54   enableProprietaryCodecs ? true,
55   gn,
56   cctools,
57   cups,
58   bootstrap_cmds,
59   xcbuild,
60   writeScriptBin,
61   ffmpeg ? null,
62   lib,
63   stdenv,
64   version ? null,
65   qtCompatVersion,
66   pipewireSupport ? stdenv.hostPlatform.isLinux,
67   pipewire,
68   postPatch ? "",
69   nspr,
70   lndir,
73 let
74   # qtwebengine expects to find an executable in $PATH which runs on
75   # the build platform yet knows about the host `.pc` files.  Most
76   # configury allows setting $PKG_CONFIG to point to an
77   # arbitrarily-named script which serves this purpose; however QT
78   # insists that it is named `pkg-config` with no target prefix.  So
79   # we re-wrap the host platform's pkg-config.
80   pkg-config-wrapped-without-prefix = stdenv.mkDerivation {
81     name = "pkg-config-wrapper-without-target-prefix";
82     dontUnpack = true;
83     dontBuild = true;
84     installPhase = ''
85       mkdir -p $out/bin
86       ln -s '${buildPackages.pkg-config}/bin/${buildPackages.pkg-config.targetPrefix}pkg-config' $out/bin/pkg-config
87     '';
88   };
92 qtModule (
93   {
94     pname = "qtwebengine";
95     nativeBuildInputs =
96       [
97         bison
98         flex
99         git
100         gperf
101         ninja
102         pkg-config
103         (python.withPackages (ps: [ ps.html5lib ]))
104         which
105         gn
106         nodejs
107       ]
108       ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
109         perl
110         lndir
111         (lib.getDev pkgsBuildTarget.targetPackages.qt5.qtbase)
112         pkgsBuildBuild.pkg-config
113         (lib.getDev pkgsBuildTarget.targetPackages.qt5.qtquickcontrols)
114         pkg-config-wrapped-without-prefix
115       ]
116       ++ lib.optional stdenv.hostPlatform.isDarwin [
117         bootstrap_cmds
118         xcbuild
119       ];
120     doCheck = true;
121     outputs = [
122       "bin"
123       "dev"
124       "out"
125     ];
127     enableParallelBuilding = true;
129     # Don’t use the gn setup hook
130     dontUseGnConfigure = true;
132     # ninja builds some components with -Wno-format,
133     # which cannot be set at the same time as -Wformat-security
134     hardeningDisable = [ "format" ];
136     patches = [
137       # Support FFmpeg 5
138       (fetchpatch2 {
139         url = "https://gitlab.archlinux.org/archlinux/packaging/packages/qt5-webengine/-/raw/14074e4d789167bd776939037fe6df8d4d7dc0b3/qt5-webengine-ffmpeg5.patch";
140         hash = "sha256-jTbJFXBPwRMzr8IeTxrv9dtS+/xDS/zR4dysV/bRg3I=";
141         stripLen = 1;
142         extraPrefix = "src/3rdparty/";
143       })
145       # Support FFmpeg 7
146       (fetchpatch2 {
147         url = "https://gitlab.archlinux.org/archlinux/packaging/packages/qt5-webengine/-/raw/e8fb4f86104243b90966b69cdfaa967273d834b6/qt5-webengine-ffmpeg7.patch";
148         hash = "sha256-YNeHmOVp0M5HB+b91AOxxJxl+ktBtLYVdHlq13F7xtY=";
149         stripLen = 1;
150         extraPrefix = "src/3rdparty/chromium/";
151       })
153       # Support PipeWire ≥ 0.3
154       (fetchpatch2 {
155         url = "https://gitlab.archlinux.org/archlinux/packaging/packages/qt5-webengine/-/raw/c9db2cd9e144bd7a5e9246f5f7a01fe52fd089ba/qt5-webengine-pipewire-0.3.patch";
156         hash = "sha256-mGexRfVDF3yjNzSi9BjavhzPtsXI0BooSr/rZ1z/BDo=";
157         stripLen = 1;
158         extraPrefix = "src/3rdparty/";
159       })
160     ];
162     postPatch =
163       ''
164         # Patch Chromium build tools
165         (
166           cd src/3rdparty/chromium;
168           patch -p2 < ${
169             (fetchpatch {
170               # support for building with python 3.12
171               name = "python312-imp.patch";
172               url = "https://codereview.qt-project.org/gitweb?p=qt/qtwebengine-chromium.git;a=patch;h=3664134f749f4851a14ab1953a9ee460a1fe0b68";
173               hash = "sha256-XY0dEdeuOTRMR7onmuNg1Axld8+pquKAzOfDAGSIzI4=";
174             })
175           }
176           patch -p1 < ${
177             (fetchpatch {
178               # support for building with python 3.12
179               name = "python312-six.patch";
180               url = "https://gitlab.archlinux.org/archlinux/packaging/packages/qt5-webengine/-/raw/6b0c0e76e0934db2f84be40cb5978cee47266e78/python3.12-six.patch";
181               hash = "sha256-YgP9Sq5+zTC+U7+0hQjZokwb+fytk0UEIJztUXFhTkI=";
182             })
183           }
185           # Manually fix unsupported shebangs
186           substituteInPlace third_party/harfbuzz-ng/src/src/update-unicode-tables.make \
187             --replace "/usr/bin/env -S make -f" "/usr/bin/make -f" || true
189           # TODO: be more precise
190           patchShebangs .
191         )
192       ''
193       # Prevent Chromium build script from making the path to `clang` relative to
194       # the build directory.  `clang_base_path` is the value of `QMAKE_CLANG_DIR`
195       # from `src/core/config/mac_osx.pri`.
196       + lib.optionalString stdenv.hostPlatform.isDarwin ''
197         substituteInPlace ./src/3rdparty/chromium/build/toolchain/mac/BUILD.gn \
198           --replace 'prefix = rebase_path("$clang_base_path/bin/", root_build_dir)' 'prefix = "$clang_base_path/bin/"'
199       ''
200       # Patch library paths in Qt sources
201       + ''
202         sed -i \
203           -e "s,QLibraryInfo::location(QLibraryInfo::DataPath),QLatin1String(\"$out\"),g" \
204           -e "s,QLibraryInfo::location(QLibraryInfo::TranslationsPath),QLatin1String(\"$out/translations\"),g" \
205           -e "s,QLibraryInfo::location(QLibraryInfo::LibraryExecutablesPath),QLatin1String(\"$out/libexec\"),g" \
206           src/core/web_engine_library_info.cpp
207       ''
208       # Patch library paths in Chromium sources
209       + lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
210         sed -i -e '/lib_loader.*Load/s!"\(libudev\.so\)!"${lib.getLib systemd}/lib/\1!' \
211           src/3rdparty/chromium/device/udev_linux/udev?_loader.cc
213         sed -i -e '/libpci_loader.*Load/s!"\(libpci\.so\)!"${pciutils}/lib/\1!' \
214           src/3rdparty/chromium/gpu/config/gpu_info_collector_linux.cc
215       ''
216       + lib.optionalString stdenv.hostPlatform.isDarwin (''
217         substituteInPlace src/buildtools/config/mac_osx.pri \
218           --replace 'QMAKE_CLANG_DIR = "/usr"' 'QMAKE_CLANG_DIR = "${stdenv.cc}"'
220         # Use system ffmpeg
221         echo "gn_args += use_system_ffmpeg=true" >> src/core/config/mac_osx.pri
222         echo "LIBS += -lavformat -lavcodec -lavutil" >> src/core/core_common.pri
223       '')
224       + postPatch;
226     env =
227       {
228         NIX_CFLAGS_COMPILE = toString (
229           lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
230             "-w "
231           ]
232           ++ lib.optionals stdenv.cc.isGNU [
233             # with gcc8, -Wclass-memaccess became part of -Wall and this exceeds the logging limit
234             "-Wno-class-memaccess"
235           ]
236           ++ lib.optionals (stdenv.hostPlatform.gcc.arch or "" == "sandybridge") [
237             # it fails when compiled with -march=sandybridge https://github.com/NixOS/nixpkgs/pull/59148#discussion_r276696940
238             # TODO: investigate and fix properly
239             "-march=westmere"
240           ]
241           ++ lib.optionals stdenv.cc.isClang [
242             "-Wno-elaborated-enum-base"
243           ]
244         );
245       }
246       // lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform) {
247         NIX_CFLAGS_LINK = "-Wl,--no-warn-search-mismatch";
248         "NIX_CFLAGS_LINK_${buildPackages.stdenv.cc.suffixSalt}" = "-Wl,--no-warn-search-mismatch";
249       };
251     preConfigure =
252       ''
253         export NINJAFLAGS=-j$NIX_BUILD_CORES
255         if [ -d "$PWD/tools/qmake" ]; then
256             QMAKEPATH="$PWD/tools/qmake''${QMAKEPATH:+:}$QMAKEPATH"
257         fi
258       ''
259       + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
260         export QMAKE_CC=$CC
261         export QMAKE_CXX=$CXX
262         export QMAKE_LINK=$CXX
263         export QMAKE_AR=$AR
264       '';
266     qmakeFlags =
267       [
268         "--"
269         "-system-ffmpeg"
270       ]
271       ++ lib.optional (
272         pipewireSupport && stdenv.buildPlatform == stdenv.hostPlatform
273       ) "-webengine-webrtc-pipewire"
274       ++ lib.optional enableProprietaryCodecs "-proprietary-codecs";
276     propagatedBuildInputs =
277       [
278         qtdeclarative
279         qtquickcontrols
280         qtlocation
281         qtwebchannel
283         # Image formats
284         libjpeg
285         libpng
286         libtiff
287         libwebp
289         # Video formats
290         srtp
291         libvpx
293         # Audio formats
294         libopus
296         # Text rendering
297         harfbuzz
298         icu
300         libevent
301         ffmpeg
302       ]
303       ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [
304         dbus
305         zlib
306         minizip
307         snappy
308         nss
309         protobuf
310         jsoncpp
312         # Audio formats
313         alsa-lib
314         pulseaudio
316         # Text rendering
317         fontconfig
318         freetype
320         libcap
321         pciutils
323         # X11 libs
324         xorg.xrandr
325         libXScrnSaver
326         libXcursor
327         libXrandr
328         xorg.libpciaccess
329         libXtst
330         xorg.libXcomposite
331         xorg.libXdamage
332         libdrm
333         xorg.libxkbfile
335       ]
336       ++ lib.optionals pipewireSupport [
337         # Pipewire
338         pipewire
339       ]
341       # FIXME These dependencies shouldn't be needed but can't find a way
342       # around it. Chromium pulls this in while bootstrapping GN.
343       ++ lib.optionals stdenv.hostPlatform.isDarwin [ cctools.libtool ];
345     buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [
346       cups
348       # `sw_vers` is used by `src/3rdparty/chromium/build/config/mac/sdk_info.py`
349       # to get some information about the host platform.
350       (writeScriptBin "sw_vers" ''
351         #!${stdenv.shell}
353         while [ $# -gt 0 ]; do
354           case "$1" in
355             -buildVersion) echo "17E199";;
356           *) break ;;
358           esac
359           shift
360         done
361       '')
362     ];
364     dontUseNinjaBuild = true;
365     dontUseNinjaInstall = true;
367     postInstall =
368       lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) ''
369         mkdir -p $out/libexec
370       ''
371       + lib.optionalString stdenv.hostPlatform.isLinux ''
372         cat > $out/libexec/qt.conf <<EOF
373         [Paths]
374         Prefix = ..
375         EOF
377       ''
378       + ''
379         # Fix for out-of-sync QtWebEngine and Qt releases (since 5.15.3)
380         sed 's/${lib.head (lib.splitString "-" version)} /${qtCompatVersion} /' -i "$out"/lib/cmake/*/*Config.cmake
381       '';
383     requiredSystemFeatures = [ "big-parallel" ];
385     meta = with lib; {
386       description = "Web engine based on the Chromium web browser";
387       mainProgram = "qwebengine_convert_dict";
388       maintainers = with maintainers; [ matthewbauer ];
390       # qtwebengine-5.15.8: "QtWebEngine can only be built for x86,
391       # x86-64, ARM, Aarch64, and MIPSel architectures."
392       platforms =
393         with lib.systems.inspect.patterns;
394         let
395           inherit (lib.systems.inspect) patternLogicalAnd;
396         in
397         concatMap (patternLogicalAnd isUnix) (
398           lib.concatMap lib.toList [
399             isx86_32
400             isx86_64
401             isAarch32
402             isAarch64
403             (patternLogicalAnd isMips isLittleEndian)
404           ]
405         );
407       # This build takes a long time; particularly on slow architectures
408       timeout = 24 * 3600;
409     };
411   }
412   // lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform) {
413     configurePlatforms = [ ];
414     # to get progress output in `nix-build` and `nix build -L`
415     preBuild = ''
416       export TERM=dumb
417     '';
418     depsBuildBuild = [
419       pkgsBuildBuild.stdenv
420       zlib
421       nss
422       nspr
423     ];
425   }