summaryrefslogtreecommitdiff
path: root/pkgs/development/libraries/qt-6/modules/qtwebengine/default.nix
blob: d58cb993f91276f8c2c3958594e378bcccdc1e0c (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
{
  qtModule,
  qtdeclarative,
  qtwebchannel,
  qtpositioning,
  qtwebsockets,
  buildPackages,
  bison,
  coreutils,
  flex,
  git,
  gperf,
  ninja,
  pkg-config,
  python3,
  which,
  nodejs,
  xorg,
  libXcursor,
  libXScrnSaver,
  libXrandr,
  libXtst,
  libxshmfence,
  libXi,
  cups,
  fontconfig,
  freetype,
  harfbuzz,
  icu,
  dbus,
  libdrm,
  zlib,
  minizip,
  libjpeg,
  libpng,
  libtiff,
  libwebp,
  libopus,
  jsoncpp,
  protobuf,
  libvpx,
  srtp,
  snappy,
  nss,
  libevent,
  openssl,
  alsa-lib,
  pulseaudio,
  libcap,
  pciutils,
  systemd,
  pipewire,
  gn,
  ffmpeg,
  lib,
  stdenv,
  glib,
  libxml2,
  libxslt,
  lcms2,
  libkrb5,
  libgbm,
  enableProprietaryCodecs ? true,
  # darwin
  bootstrap_cmds,
  cctools,
  xcbuild,
  fetchpatch,
}:

qtModule {
  pname = "qtwebengine";
  nativeBuildInputs =
    [
      bison
      coreutils
      flex
      git
      gperf
      ninja
      pkg-config
      (python3.withPackages (ps: with ps; [ html5lib ]))
      which
      gn
      nodejs
    ]
    ++ lib.optionals stdenv.hostPlatform.isDarwin [
      bootstrap_cmds
      cctools
      xcbuild
    ];
  doCheck = true;
  outputs = [
    "out"
    "dev"
  ];

  dontUseGnConfigure = true;

  # ninja builds some components with -Wno-format,
  # which cannot be set at the same time as -Wformat-security
  hardeningDisable = [ "format" ];

  patches = [
    # Don't assume /usr/share/X11, and also respect the XKB_CONFIG_ROOT
    # environment variable, since NixOS relies on it working.
    # See https://github.com/NixOS/nixpkgs/issues/226484 for more context.
    ./xkb-includes.patch

    ./link-pulseaudio.patch

    # Override locales install path so they go to QtWebEngine's $out
    ./locales-path.patch

    # Fix build of vendored xnnpack on aarch64/gcc14
    # FIXME: remove when upstream updates
    (fetchpatch {
      url = "https://github.com/google/XNNPACK/commit/1b11a8b0620afe8c047304273674c4c57c289755.patch";
      stripLen = 1;
      extraPrefix = "src/3rdparty/chromium/third_party/xnnpack/src/";
      hash = "sha256-GUESVNR88I1K2V5xr0e09ec4j2eselMhNN06+PCcINM=";
    })

    # The latest version of Clang changed what macros it predefines on Apple
    # targets, causing errors about predefined macros in zlib.
    (fetchpatch {
      url = "https://github.com/chromium/chromium/commit/2f39ac8d0a414dd65c0e1d5aae38c8f97aa06ae9.patch";
      stripLen = 1;
      extraPrefix = "src/3rdparty/chromium/";
      hash = "sha256-07hWANY9JGFmqvjdOD6SFmVI6sQRRyvW+7wxGZF5GVo=";
    })

    # The latest version of Clang changed what macros it predefines on Apple
    # targets, causing errors about predefined macros in libpng.
    (fetchpatch {
      url = "https://github.com/chromium/chromium/commit/66defc14abe47c0494da9faebebfa0a5b6efcf38.patch";
      stripLen = 1;
      extraPrefix = "src/3rdparty/chromium/";
      hash = "sha256-FWIi1VsBZFqOoPIkPxPkcfexPkx1458rB5ldtA7T2uE=";
    })
  ];

  postPatch =
    ''
      # Patch Chromium build tools
      (
        cd src/3rdparty/chromium;

        # Manually fix unsupported shebangs
        substituteInPlace third_party/harfbuzz-ng/src/src/update-unicode-tables.make \
          --replace "/usr/bin/env -S make -f" "/usr/bin/make -f" || true
        substituteInPlace third_party/webgpu-cts/src/tools/run_deno \
          --replace "/usr/bin/env -S deno" "/usr/bin/deno" || true
        patchShebangs .
      )

      substituteInPlace cmake/Functions.cmake \
        --replace "/bin/bash" "${buildPackages.bash}/bin/bash"

      # Patch library paths in sources
      substituteInPlace src/core/web_engine_library_info.cpp \
        --replace "QLibraryInfo::path(QLibraryInfo::DataPath)" "\"$out\"" \
        --replace "QLibraryInfo::path(QLibraryInfo::TranslationsPath)" "\"$out/translations\"" \
        --replace "QLibraryInfo::path(QLibraryInfo::LibraryExecutablesPath)" "\"$out/libexec\""

      substituteInPlace configure.cmake src/gn/CMakeLists.txt \
        --replace "AppleClang" "Clang"

      # Disable metal shader compilation, Xcode only
      substituteInPlace src/3rdparty/chromium/third_party/angle/src/libANGLE/renderer/metal/metal_backend.gni \
        --replace-fail 'angle_has_build && !is_ios && target_os == host_os' "false"
    ''
    + lib.optionalString stdenv.hostPlatform.isLinux ''
      sed -i -e '/lib_loader.*Load/s!"\(libudev\.so\)!"${lib.getLib systemd}/lib/\1!' \
        src/3rdparty/chromium/device/udev_linux/udev?_loader.cc

      sed -i -e '/libpci_loader.*Load/s!"\(libpci\.so\)!"${pciutils}/lib/\1!' \
        src/3rdparty/chromium/gpu/config/gpu_info_collector_linux.cc
    ''
    + lib.optionalString stdenv.hostPlatform.isDarwin ''
      substituteInPlace cmake/Functions.cmake \
        --replace "/usr/bin/xcrun" "${xcbuild}/bin/xcrun"
    '';

  cmakeFlags =
    [
      "-DQT_FEATURE_qtpdf_build=ON"
      "-DQT_FEATURE_qtpdf_widgets_build=ON"
      "-DQT_FEATURE_qtpdf_quick_build=ON"
      "-DQT_FEATURE_pdf_v8=ON"
      "-DQT_FEATURE_pdf_xfa=ON"
      "-DQT_FEATURE_pdf_xfa_bmp=ON"
      "-DQT_FEATURE_pdf_xfa_gif=ON"
      "-DQT_FEATURE_pdf_xfa_png=ON"
      "-DQT_FEATURE_pdf_xfa_tiff=ON"
      "-DQT_FEATURE_webengine_system_libevent=ON"
      "-DQT_FEATURE_webengine_system_ffmpeg=ON"
      # android only. https://bugreports.qt.io/browse/QTBUG-100293
      # "-DQT_FEATURE_webengine_native_spellchecker=ON"
      "-DQT_FEATURE_webengine_sanitizer=ON"
      "-DQT_FEATURE_webengine_kerberos=ON"
    ]
    ++ lib.optionals stdenv.hostPlatform.isLinux [
      "-DQT_FEATURE_webengine_system_libxml=ON"
      "-DQT_FEATURE_webengine_webrtc_pipewire=ON"

      # Appears not to work on some platforms
      # https://github.com/Homebrew/homebrew-core/issues/104008
      "-DQT_FEATURE_webengine_system_icu=ON"
    ]
    ++ lib.optionals enableProprietaryCodecs [
      "-DQT_FEATURE_webengine_proprietary_codecs=ON"
    ]
    ++ lib.optionals stdenv.hostPlatform.isDarwin [
      "-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0" # Per Qt 6’s deployment target (why doesn’t the hook work?)
    ];

  propagatedBuildInputs =
    [
      qtdeclarative
      qtwebchannel
      qtwebsockets
      qtpositioning

      # Image formats
      libjpeg
      libpng
      libtiff
      libwebp

      # Video formats
      srtp
      libvpx

      # Audio formats
      libopus

      # Text rendering
      harfbuzz

      openssl
      glib
      libxslt
      lcms2

      libevent
      ffmpeg
    ]
    ++ lib.optionals stdenv.hostPlatform.isLinux [
      dbus
      zlib
      minizip
      snappy
      nss
      protobuf
      jsoncpp

      icu
      libxml2

      # Audio formats
      alsa-lib
      pulseaudio

      # Text rendering
      fontconfig
      freetype

      libcap
      pciutils

      # X11 libs
      xorg.xrandr
      libXScrnSaver
      libXcursor
      libXrandr
      xorg.libpciaccess
      libXtst
      xorg.libXcomposite
      xorg.libXdamage
      libdrm
      xorg.libxkbfile
      libxshmfence
      libXi
      xorg.libXext

      # Pipewire
      pipewire

      libkrb5
      libgbm
    ];

  buildInputs = [
    cups
  ];

  requiredSystemFeatures = [ "big-parallel" ];

  preConfigure = ''
    export NINJAFLAGS="-j$NIX_BUILD_CORES"
  '';

  # Debug info is too big to link with LTO.
  separateDebugInfo = false;

  meta = with lib; {
    description = "Web engine based on the Chromium web browser";
    platforms = [
      "x86_64-darwin"
      "aarch64-darwin"
      "aarch64-linux"
      "armv7a-linux"
      "armv7l-linux"
      "x86_64-linux"
    ];
    # This build takes a long time; particularly on slow architectures
    # 1 hour on 32x3.6GHz -> maybe 12 hours on 4x2.4GHz
    timeout = 24 * 3600;
  };
}