aboutsummarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 8915f023d4e6f12d99ea447b135fb99feb983d4a (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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
# Maintainer: Christian Heusel <gromit@archlinux.org>
# Maintainer: Jonathan Grotelüschen <tippfehlr@archlinux.org>
# Contributor: Sven-Hendrik Haase <svenstaro@archlinux.org>

# Note: This PKGBUILD and the chromium PKGBUILD are loosely kept in sync to ease maintenance.
# As such care should be taken to minimize the differences between these PKGBUILDs.
pkgname=cef-vaapi
# pkgver is updated automatically.
# To update this package, update the _cef_commit and _chromium_ver variables.
# For the CEF versioning scheme, see
# https://chromiumembedded.github.io/cef/branches_and_building#version-number-format
pkgver=150.0.11
# See https://github.com/chromiumembedded/cef/tree/<release branch>
# Also see https://chromiumembedded.github.io/cef/branches_and_building
_cef_commit=b88780525f76c1c1d67d30b87e3b16bb37955175
# the chromium version must match CHROMIUM_BUILD_COMPATIBILITY.txt in the CEF repo
_chromium_ver=150.0.7871.115
_system_clang=1
pkgrel=1
pkgdesc="Chromium Embedded Framework (CEF), simple framework for embedding Chromium-based browsers in other applications (VAAPI-enabled variant)"
provides=("cef=$pkgver")  # provides="cef=$pkgver"
conflicts=('cef')  # conflicts='cef'
arch=('x86_64')
url="https://chromiumembedded.github.io/cef"
license=('BSD-3-Clause')
depends=(
  'alsa-lib'
  'at-spi2-core'
  'dbus'
  'libdrm'
  'libffi'
  'libpulse'
  'libxcomposite'
  'libxdamage'
  'libxkbcommon'
  'libxrandr'
  'mesa'
  'nss'
  'pango'
  'systemd-libs'
  'libva'
)
optdepends=(
  'libva-mesa-driver: VAAPI driver for AMD GPUs'
  'intel-media-driver: VAAPI driver for modern Intel GPUs'
  'libva-utils: VAAPI diagnostics such as vainfo'
)

makedepends=(
  'clang'
  'compiler-rt'
  'git'
  'gn'
  'gperf'
  'java-runtime-headless'
  'lld'
  'ninja'
  'nodejs'
  'npm'
  'pipewire'
  'python'
  'python-httplib2'
  'python-pyparsing'
  'python-six'
  'rsync'
  'rust'
  'rust-bindgen'
  'libxtst'
)
options=('!lto') # Chromium adds its own flags for ThinLTO
source=("chromium-$_chromium_ver-lite.tar.xz::https://commondatastorage.googleapis.com/chromium-browser-official/chromium-$_chromium_ver-lite.tar.xz"
  "cef::git+https://github.com/chromiumembedded/cef.git#commit=${_cef_commit}"
  chromium-138-nodejs-version-check.patch
  chromium-145-fix-SYS_SECCOMP.patch
  chromium-147-revert-clang-no-lifetime-dse-flag.patch
  chromium-147-rust-1.95-bytemuck.patch
  chromium-149-drop-unknown-clang-flag.patch
  chromium-149-unbundle-minizip-undo-unicode.patch
  chromium-149-use-of-undeclared-identifier-ERROR.patch
  chromium-149-build-with-wasm-rollup.patch
  chromium-150-fix-ar-unbundle.patch
  chromium-150-fix-sysroot-path-error.patch
  chromium-150-revert-avx-flag-change.patch
  compiler-rt-adjust-paths.patch
  increase-fortify-level.patch
  glibc-2.42-baud-rate-fix.patch
  cef-no-sysroot.patch
  cef-no-libxml-visibility-patch.patch
  chromium-disable-font-tests.patch
  FindCEF.cmake
)
sha256sums=('59e1be0fcb8a35945c65a136849c9dd652fd86ec2c472d86a2a85f7b3295f743'
            '9ac7c45b70dfb238c44f15ce957dd1bf96dba9be5940460c19a9ce71d69a0ebf'
            '11a96ffa21448ec4c63dd5c8d6795a1998d8e5cd5a689d91aea4d2bdd13fb06e'
            '4fc040a0656a0a524dd8ad090cd129fc5b6cb21adcc66be82080165789e8c13e'
            'c382830318c5b37826ecf44f3ba9def6be8affdad1bce819ecb83f3222ff4b3a'
            'b9e6339221efe03540ffb360c161d93604a1fc93a5a1c53e5e9849066f987d05'
            '5ade4cdba7afebfcc09fa969f15bf27404579beac5b7bafb59a0214d407e4ad2'
            'c22338d13f12772cdbcb5cfc1ace94438b9f9c72353cdb165a3ff3ef3d677c78'
            '951514535be65f0e2f84e82305d96292be1da353c1427ba1048ea24be70003c4'
            'c4df27d25d298ac95d85e6f06b558b73bb67de5110a19a0228cb7f8519291ea5'
            'f056d12571823d06c2a938158734fb4c7eeccb5c6f68228634d0c73d75feaa78'
            '5c42260b11b87dd01c4ef11598033e9687bdf384af2e45adab2fd00964e977e8'
            '5f6ccb7b945c8a13c690493723bad816b36f2f25792d47e677b56f8200907e60'
            'ec8e49b7114e2fa2d359155c9ef722ff1ba5fe2c518fa48e30863d71d3b82863'
            'd634d2ce1fc63da7ac41f432b1e84c59b7cceabf19d510848a7cff40c8025342'
            '1c1898f263eaacbc069a8e1a3e732852350350d1dad4cb1a6bba430e3b796cd0'
            'cdc046c3da5a57dae8fba0de49cadbe65d4f8fbfffb172f7a768222232595faa'
            '6695d7bcac489f74b8290a05dac540c2b5c5fed997ee119ae05419d36509445d'
            '44dcc0da55a8c6c6af875addcfb9c552c722b56a31479eb7d99f16d0a27f4ebb'
            'e576250c4d0f3dd307bd22c6d4f9f7aba54fdf4d5899520c0bd1c3527aec65ed')

# Possible replacements are listed in build/linux/unbundle/replace_gn_files.py
# Keys are the names in the above script; values are the dependencies in Arch
declare -gA _system_libs=(
  [brotli]=brotli
  #[dav1d]=dav1d
  #[ffmpeg]=ffmpeg    # YouTube playback stopped working in Chromium 120
  [flac]=flac
  [fontconfig]=fontconfig
  [freetype]=freetype2
  [harfbuzz]=harfbuzz
  #[icu]=icu
  #[jsoncpp]=jsoncpp  # needs libstdc++
  #[libaom]=aom
  #[libavif]=libavif  # needs -DAVIF_ENABLE_EXPERIMENTAL_GAIN_MAP=ON
  [libdrm]=libdrm
  [libjpeg]=libjpeg-turbo
  # [libpng]=libpng
  #[libvpx]=libvpx
  [libwebp]=libwebp
  [libxml]=libxml2
  [libxslt]=libxslt
  [openh264]=openh264
  [opus]=opus
  #[re2]=re2          # needs libstdc++
  #[snappy]=snappy    # needs libstdc++
  #[woff2]=woff2      # needs libstdc++
  [zlib]=minizip
  [zstd]=zstd
)
_unwanted_bundled_libs=(
  $(printf "%s\n" ${!_system_libs[@]} | sed 's/^libjpeg$/&_turbo/')
)
depends+=(${_system_libs[@]})

_validate_cef_vaapi_invariants() {
  local _pkgbuild="${BASH_SOURCE[0]}"
  local _required_flags=(
    'ffmpeg_branding="Chrome"'
    'proprietary_codecs=true'
    'rtc_use_pipewire=true'
    'link_pulseaudio=true'
    'use_vaapi=true'
  )
  local _flag _actual _flag_ok
  for _flag in "${_required_flags[@]}"; do
    _flag_ok=0
    for _actual in "${_flags[@]}"; do
      if [[ "$_actual" == "$_flag" ]]; then
        _flag_ok=1
        break
      fi
    done
    if (( ! _flag_ok )); then
      echo "ERROR: required GN flag missing or changed: ${_flag}" >&2
      exit 1
    fi
  done

  if grep -Eq '^[[:space:]]*\[ffmpeg\]=' "$_pkgbuild"; then
    echo "ERROR: _system_libs[ffmpeg] must stay commented or absent" >&2
    exit 1
  fi

  local _source_ok=0 _s
  for _s in "${source[@]}"; do
    if [[ "$_s" == cef::git+https://github.com/chromiumembedded/cef.git* ]]; then
      _source_ok=1
      break
    fi
  done
  if (( ! _source_ok )); then
    echo "ERROR: source must use cef::git+https://github.com/chromiumembedded/cef.git" >&2
    exit 1
  fi

  local _provides_ok=0 _p
  for _p in "${provides[@]}"; do
    if [[ "$_p" == cef=* ]]; then
      _provides_ok=1
      break
    fi
  done
  if (( ! _provides_ok )); then
    echo "ERROR: provides must include cef=\$pkgver" >&2
    exit 1
  fi

  local _conflicts_ok=0 _c
  for _c in "${conflicts[@]}"; do
    if [[ "$_c" == cef ]]; then
      _conflicts_ok=1
      break
    fi
  done
  if (( ! _conflicts_ok )); then
    echo "ERROR: conflicts must include cef" >&2
    exit 1
  fi

  if declare -p replaces >/dev/null 2>&1 && (( ${#replaces[@]} > 0 )); then
    echo "ERROR: replaces must not be set" >&2
    exit 1
  fi

  local _libva_ok=0 _d
  for _d in "${depends[@]}"; do
    if [[ "$_d" == libva ]]; then
      _libva_ok=1
      break
    fi
  done
  if (( ! _libva_ok )); then
    echo "ERROR: depends must include libva" >&2
    exit 1
  fi
}

prepare() {
  cd chromium-$_chromium_ver

  # Move CEF into the chromium source tree
  mv "$srcdir/cef" cef

  # Allow building against system libraries in official builds
  sed -i 's/OFFICIAL_BUILD/GOOGLE_CHROME_BUILD/' \
    tools/generate_shim_headers/generate_shim_headers.py

  # https://crbug.com/893950
  sed -i -e 's/\<xmlMalloc\>/malloc/' -e 's/\<xmlFree\>/free/' \
    -e '1i #include <cstdlib>' \
    third_party/blink/renderer/core/xml/*.cc \
    third_party/blink/renderer/core/xml/parser/xml_document_parser.cc \
    third_party/libxml/chromium/*.cc

  # Fixes from Gentoo
  patch -Np1 -i ../chromium-138-nodejs-version-check.patch

  # Allow libclang_rt.builtins from compiler-rt >= 16 to be used
  patch -Np1 -i ../compiler-rt-adjust-paths.patch

  # Increase _FORTIFY_SOURCE level to match Arch's default flags
  patch -Np1 -i ../increase-fortify-level.patch

  # clang 22 lacks -fsanitize-ignore-for-ubsan-feature, which is needed to use
  # -fsanitize=array-bounds without triggering UBSan feature detection. Without
  # feature detection suppression, V8 compiles in __sanitizer_set_death_callback
  # calls that require the UBSan runtime, which is not linked in a trap-mode
  # build. Drop the entire sanitize_c_array_bounds cflags block.
  # Can be dropped when arch has LLVM 23.
  patch -Np1 -i ../chromium-149-drop-unknown-clang-flag.patch

  # Causes a build failure with our clang version
  patch -Np1 -i ../chromium-147-revert-clang-no-lifetime-dse-flag.patch

  # https://crbug.com/456218403
  patch -Np1 -i ../chromium-145-fix-SYS_SECCOMP.patch

  patch -Np1 -i ../chromium-149-build-with-wasm-rollup.patch

  patch -Np1 -i ../chromium-147-rust-1.95-bytemuck.patch

  patch -Np1 -i ../chromium-disable-font-tests.patch

  # https://crbug.com/456677057
  patch -Np1 -i ../glibc-2.42-baud-rate-fix.patch

  # Chromium bundles a patched minizip with extra features
  patch -Np1 -i ../chromium-149-unbundle-minizip-undo-unicode.patch

  patch -Np1 -i ../chromium-149-use-of-undeclared-identifier-ERROR.patch

  # Fix issue about missing AR file
  # Credit: https://github.com/ungoogled-software/ungoogled-chromium/pull/3837
  patch -Np1 -i ../chromium-150-fix-ar-unbundle.patch

  # Fix issue about missing sysroot path
  # Credit: https://github.com/ungoogled-software/ungoogled-chromium/pull/3837#issuecomment-4836756738
  patch -Np1 -i ../chromium-150-fix-sysroot-path-error.patch

  # Fix issue about missing AVX functions
  # Credit: https://github.com/ungoogled-software/ungoogled-chromium/pull/3837
  patch -Np1 -i ../chromium-150-revert-avx-flag-change.patch

  # CEF: Remove sysroot requirement for non-x64 builds
  patch -Np1 -i ../cef-no-sysroot.patch

  # CEF: Remove libxml_visibility patch (fails with system libxml2)
  patch -Np1 -i ../cef-no-libxml-visibility-patch.patch

  # CEF: Override clang_exe to use system clang
  echo 'clang_exe = "clang"' >>cef/tools/clang_util.py

  # Link to system tools required by the build
  mkdir -p third_party/node/linux/node-linux-x64/bin \
    third_party/jdk/current/bin \
    third_party/rust-toolchain/bin

  ln -s /usr/bin/node third_party/node/linux/node-linux-x64/bin/
  ln -s /usr/bin/java third_party/jdk/current/bin/

  # the build uses system rust, but CEF checks for it here.
  ln -s /usr/bin/rustc third_party/rust-toolchain/bin/

  # remove x86_64 binary and use our own
  rm -f third_party/gperf/cipd/bin/gperf
  ln -s /usr/bin/gperf third_party/gperf/cipd/bin/

  if ((!_system_clang)); then
    # Use prebuilt rust as system rust cannot be used due to the error:
    #   error: the option `Z` is only accepted on the nightly compiler
    ./tools/rust/update_rust.py

    # To link to rust libraries we need to compile with prebuilt clang
    ./tools/clang/scripts/update.py
  fi

  # Remove bundled libraries for which we will use the system copies; this
  # *should* do what the remove_bundled_libraries.py script does, with the
  # added benefit of not having to list all the remaining libraries
  local _lib
  for _lib in ${_unwanted_bundled_libs[@]}; do
    find "third_party/$_lib" -type f \
      \! -path "third_party/$_lib/chromium/*" \
      \! -path "third_party/$_lib/google/*" \
      \! -path "third_party/harfbuzz-ng/utils/hb_scoped.h" \
      \! -regex '.*\.\(gn\|gni\|isolate\)' \
      -delete
  done

  ./build/linux/unbundle/replace_gn_files.py \
    --system-libraries "${!_system_libs[@]}"

  # check if the right chromium version is available.
  local _expected_chromium_ver=$(grep -oP "refs/tags/\K[0-9.]+" cef/CHROMIUM_BUILD_COMPATIBILITY.txt)
  if [[ "$_expected_chromium_ver" != "$_chromium_ver" ]]; then
    echo "Error: CEF expects chromium $_expected_chromium_ver, but $_chromium_ver was set in PKGBUILD" >&2
    exit 1
  fi
}

pkgver() {
  cd chromium-$_chromium_ver

  # python tool to get the full CEF version. For the full output, look at
  # /usr/include/cef/include/cef_version.h in the built package.
  python cef/tools/make_version_header.py cef_version_header
  grep -oP 'CEF_VERSION "\K[^"]+' cef_version_header | sed -E 's/\+.*//'
}

build() {
  cd chromium-$_chromium_ver

  if ((_system_clang)); then
    export CC=clang
    export CXX=clang++
    export AR=ar
    export NM=nm
  else
    local _clang_path="$PWD/third_party/llvm-build/Release+Asserts/bin"
    export CC=$_clang_path/clang
    export CXX=$_clang_path/clang++
    export AR=$_clang_path/llvm-ar
    export NM=$_clang_path/llvm-nm
  fi

  # Add depot_tools to PATH (needed by CEF's gclient_hook.py)
  export PATH="$PATH:$PWD/third_party/depot_tools"

  # Use system ninja, remove the wrapper which only supports x86_64
  rm -f third_party/depot_tools/ninja

  # GN defines passed to CEF's gclient_hook.py via GN_DEFINES env var
  local _flags=(
    'custom_toolchain="//build/toolchain/linux/unbundle:default"'
    'host_toolchain="//build/toolchain/linux/unbundle:default"'
    'is_official_build=true' # implies is_cfi=true on x86_64
    'symbol_level=0'         # sufficient for backtraces on x86(_64)
    'treat_warnings_as_errors=false'
    'fatal_linker_warnings=false'
    'disable_fieldtrial_testing_config=true'
    'blink_enable_generated_code_formatting=false'
    'ffmpeg_branding="Chrome"'
    'proprietary_codecs=true'
    'rtc_use_pipewire=true'
    'link_pulseaudio=true'
    'use_custom_libcxx=true' # https://github.com/llvm/llvm-project/issues/61705
    'use_sysroot=false'
    'use_system_libffi=true'
    'use_qt5=false'
    'use_qt6=false'
    'use_gtk=false'
    'use_cups=false'
    'use_gio=false'
    'use_kerberos=false'
    'use_libpci=false'
    'use_udev=true'
    'cef_use_gtk=false'
    'enable_remoting=false'
    'use_vaapi=true'
    'use_clang_modules=false'
    'devtools_bundle=false'
  )

  if [[ -n ${_system_libs[icu]+set} ]]; then
    _flags+=('icu_use_data_file=false')
  fi

  if ((_system_clang)); then
    local _clang_version=$(
      clang --version | grep -m1 version | sed 's/.* \([0-9]\+\).*/\1/'
    )

    _flags+=(
      'clang_base_path="/usr"'
      'clang_use_chrome_plugins=false'
      "clang_version=\"$_clang_version\""
      'chrome_pgo_phase=0' # needs newer clang to read the bundled PGO profile
    )

    # Allow the use of nightly features with stable Rust compiler
    # https://github.com/ungoogled-software/ungoogled-chromium/pull/2696#issuecomment-1918173198
    export RUSTC_BOOTSTRAP=1

    _flags+=(
      'rust_sysroot_absolute="/usr"'
      'rust_bindgen_root="/usr"'
      "rustc_version=\"$(rustc --version | awk '{ print $2 ;}')\""
    )
  fi

  _validate_cef_vaapi_invariants

  export GN_DEFINES="${_flags[*]}"
  # Only build Release config
  export GN_OUT_CONFIGS="Release_GN_x64"

  # Facilitate deterministic builds (taken from build/config/compiler/BUILD.gn)
  CFLAGS+='   -Wno-builtin-macro-redefined'
  CXXFLAGS+=' -Wno-builtin-macro-redefined'
  CPPFLAGS+=' -D__DATE__=  -D__TIME__=  -D__TIMESTAMP__='

  # Do not warn about unknown warning options
  CFLAGS+='   -Wno-unknown-warning-option'
  CXXFLAGS+=' -Wno-unknown-warning-option'

  # Let Chromium set its own symbol level
  CFLAGS=${CFLAGS/-g /}
  CXXFLAGS=${CXXFLAGS/-g /}

  # https://github.com/ungoogled-software/ungoogled-chromium-archlinux/issues/123
  CFLAGS=${CFLAGS/-fexceptions/}
  CFLAGS=${CFLAGS/-fcf-protection/}
  CXXFLAGS=${CXXFLAGS/-fexceptions/}
  CXXFLAGS=${CXXFLAGS/-fcf-protection/}

  # This appears to cause random segfaults when combined with ThinLTO
  # https://bugs.archlinux.org/task/73518
  CFLAGS=${CFLAGS/-fstack-clash-protection/}
  CXXFLAGS=${CXXFLAGS/-fstack-clash-protection/}

  # https://crbug.com/957519#c122
  CXXFLAGS=${CXXFLAGS/-Wp,-D_GLIBCXX_ASSERTIONS/}

  python3 cef/tools/gclient_hook.py
  sed -i '/__sanitizer_set_death_callback/d' v8/src/sandbox/testing.cc
  ninja -C out/Release_GN_x64 libcef chrome_sandbox

  # Build the CEF binary distribution
  python3 cef/tools/make_distrib.py \
    --distrib-subdir=distrib \
    --output-dir=.. \
    --ninja-build \
    --x64-build \
    --minimal \
    --no-docs \
    --no-archive
}

package() {
  cd distrib_minimal

  install -d "$pkgdir/usr/lib/cef/"
  cp -r Release/* "$pkgdir/usr/lib/cef/"
  install -Dvm4755 Release/chrome-sandbox "$pkgdir/usr/lib/cef/chrome-sandbox"
  cp -r Resources/* "$pkgdir/usr/lib/cef/"

  # Headers
  install -d "$pkgdir/usr/include/cef"
  cp -a "include" "$pkgdir/usr/include/cef/"

  # libcef_dll wrapper source
  install -d "$pkgdir/usr/src/cef"
  cp -a "libcef_dll" "$pkgdir/usr/src/cef/"

  # Remove include file targets, since includes are in a different path
  sed -i -e '/\.\.\/include/d' "$pkgdir/usr/src/cef/libcef_dll/CMakeLists.txt"

  # The FindCEF.cmake from CEF expects one unified directory.
  # We provide a custom FindCEF.cmake that looks in the right places.
  # Copied from https://src.fedoraproject.org/rpms/cef/blob/rawhide/f/FindCEF.cmake (thanks Fedora!)
  install -Dm644 "$srcdir/FindCEF.cmake" -t "$pkgdir/usr/share/cmake/Modules/"

  install -Dm644 LICENSE.txt "$pkgdir/usr/share/licenses/$pkgname/LICENSE-CEF"
  install -Dm644 ../chromium-$_chromium_ver/LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE-CHROMIUM"
}

# vim:set ts=2 sw=2 et: