summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: c2fab8ef158612b5d6456f4aa8b6ad698e7c8e4e (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
# Maintainer: NourEddine Y.
# Contributor: Oskar Gerlciz Kowalczuk
# Contributor: StaticNullException <aurcontact@teto.party>

pkgname=zen-browser
pkgver=1.19.12b
pkgrel=2
pkgdesc='Firefox-based web browser built from upstream release source snapshot'
url='https://zen-browser.app'
arch=('x86_64')
license=('MPL-2.0')
depends=(
  alsa-lib
  at-spi2-core
  bash
  cairo
  dbus
  ffmpeg
  fontconfig
  freetype2
  gdk-pixbuf2
  glib2
  glibc
  gtk3
  hicolor-icon-theme
  libgcc
  libpulse
  libstdc++
  libx11
  libxcb
  libxcomposite
  libxdamage
  libxext
  libxfixes
  libxrandr
  libxss
  libxt
  mime-types
  nspr
  nss
  pango
  ttf-font
)
makedepends=(
  cbindgen
  clang
  diffutils
  imake
  jack
  lld
  llvm
  mesa
  nasm
  nodejs
  onnxruntime
  python
  rust
  unzip
  wasi-compiler-rt
  wasi-libc
  wasi-libc++
  wasi-libc++abi
  xorg-server-xvfb
  yasm
  zip
)
optdepends=(
  'libnotify: Notification integration'
  'networkmanager: Location detection via available WiFi networks'
  'onnxruntime: Local machine learning features such as smart tab groups'
  'speech-dispatcher: Text-to-Speech'
  'xdg-desktop-portal: Screensharing with Wayland'
)
conflicts=('zen-browser-bin')
options=(
  !emptydirs
  !lto
  !makeflags
)

_srcroot='zen-source'
# Keep versioned GitHub release URLs here. Do not switch this to /latest/ in an
# AUR package; use .nvchecker.toml or update-zen-browser-release.sh to refresh
# pkgver and checksums deterministically.
source=(
  "$_srcroot-$pkgver.tar.zst::https://github.com/zen-browser/desktop/releases/download/$pkgver/zen.source.tar.zst"
  "$pkgname.desktop"
  #'https://gitlab.archlinux.org/archlinux/packaging/packages/firefox/-/raw/150.0.2-1/0003-Patch-glsl-optimizer-to-build-with-glibc-2.43.patch'
  #'https://gitlab.archlinux.org/archlinux/packaging/packages/firefox/-/raw/149.0.2-1/0003-Bug-2016618-Fix-Linux-sandbox-build-breakage-on-glib.patch' # Commented out until figured out
  'https://gitlab.archlinux.org/archlinux/packaging/packages/firefox/-/raw/149.0.2-1/0004-Use-wasm32-wasip1-target.patch'
)
sha256sums=('c18cfced452f4e4edf4c47872f086297d29f40ca0f6f5bc01e3f32d2e730432a'
            'af16fec9a88cbfffee34a6a4eb5b3074931477fcefee252840d77cf146568851'
            '28b086f5492d8e6731fe0dfe34a2e4c6d4d502a9eefa15a31e44b5788cf4df89')
noextract=("$_srcroot-$pkgver.tar.zst")

prepare() {
  rm -rf "$srcdir/$_srcroot"
  mkdir -p "$srcdir/$_srcroot" "$srcdir/mozbuild"
  bsdtar -xf "$srcdir/$_srcroot-$pkgver.tar.zst" -C "$srcdir/$_srcroot"

  cd "$srcdir/$_srcroot"

  #patch -Np1 -i "$srcdir/0003-Patch-glsl-optimizer-to-build-with-glibc-2.43.patch" # Commented out until figured out
  #patch -Np1 -i "$srcdir/0003-Bug-2016618-Fix-Linux-sandbox-build-breakage-on-glib.patch" # Commented out until figured out
  patch -Np1 -i "$srcdir/0004-Use-wasm32-wasip1-target.patch"

  cat >"$srcdir/mozconfig" <<EOF
ac_add_options --enable-application=browser
mk_add_options MOZ_OBJDIR=${PWD@Q}/obj

ac_add_options --prefix=/usr
ac_add_options --enable-release
ac_add_options --enable-hardening
ac_add_options --enable-optimize
# encoding_rs simd-accel opts out of Rust's stable compatibility story and
# has started breaking with newer stable compilers in release snapshots.
ac_add_options --enable-linker=lld
ac_add_options --disable-install-strip
ac_add_options --disable-bootstrap
ac_add_options --with-wasi-sysroot=/usr/share/wasi-sysroot

# Branding
ac_add_options --enable-official-branding
ac_add_options --enable-update-channel=release
ac_add_options --with-distribution-id=org.archlinux
ac_add_options --with-unsigned-addon-scopes=app,system
ac_add_options --allow-addon-sideload
export MOZILLA_OFFICIAL=1
export MOZ_APP_REMOTINGNAME=zen-browser

# System libraries
ac_add_options --with-system-nspr
ac_add_options --with-system-nss

# Features
ac_add_options --enable-alsa
ac_add_options --enable-jack
ac_add_options --enable-crashreporter
ac_add_options --disable-updater
ac_add_options --disable-tests
EOF
}

build() {
  cd "$srcdir/$_srcroot"

  export MACH_BUILD_PYTHON_NATIVE_PACKAGE_SOURCE=pip
  export MOZBUILD_STATE_PATH="$srcdir/mozbuild"
  export MOZ_BUILD_DATE="$(date -u${SOURCE_DATE_EPOCH:+d @$SOURCE_DATE_EPOCH} +%Y%m%d%H%M%S)"
  export MOZ_NOSPAM=1

  CFLAGS="${CFLAGS/_FORTIFY_SOURCE=3/_FORTIFY_SOURCE=2}"
  CXXFLAGS="${CXXFLAGS/_FORTIFY_SOURCE=3/_FORTIFY_SOURCE=2}"
  CFLAGS="${CFLAGS/-fexceptions/}"
  CXXFLAGS="${CXXFLAGS/-fexceptions/}"

  ulimit -n 4096

  echo 'Building instrumented browser...'
  cat >.mozconfig "$srcdir/mozconfig" - <<'EOF'
ac_add_options --enable-profile-generate=cross
EOF
  ./mach build --priority normal

  echo 'Profiling instrumented browser...'
  ./mach package
  LLVM_PROFDATA=llvm-profdata JARLOG_FILE="$PWD/jarlog" \
    dbus-run-session \
    xvfb-run -s '-screen 0 1920x1080x24 -nolisten local' \
    ./mach python build/pgo/profileserver.py

  test -s merged.profdata
  test -s jarlog

  echo 'Removing instrumented browser...'
  ./mach clobber objdir

  echo 'Building optimized browser...'
  cat >.mozconfig "$srcdir/mozconfig" - <<EOF
ac_add_options --enable-lto=cross,full
ac_add_options --enable-profile-use=cross
ac_add_options --with-pgo-profile-path=${PWD@Q}/merged.profdata
ac_add_options --with-pgo-jarlog=${PWD@Q}/jarlog
EOF
  ./mach build --priority normal
}

package() {
  cd "$srcdir/$_srcroot"

  DESTDIR="$pkgdir" ./mach install

  local _launcher='zen-browser'
  local _appdir="$pkgdir/usr/lib/$_launcher"
  local _size

  if [[ -d "$pkgdir/usr/lib/zen" && ! -d "$_appdir" ]]; then
    mv "$pkgdir/usr/lib/zen" "$_appdir"
  fi

  install -Dm755 /dev/stdin "$pkgdir/usr/bin/$_launcher" <<'EOF'
#!/bin/sh
exec /usr/lib/zen-browser/zen "$@"
EOF
  ln -s "$_launcher" "$pkgdir/usr/bin/zen"

  ln -srv "$pkgdir/usr/lib/libonnxruntime.so" -t "$_appdir"

  install -Dm644 "$srcdir/$pkgname.desktop" \
    "$pkgdir/usr/share/applications/$pkgname.desktop"

  for _size in 16 32 48 64 128; do
    install -Dm644 \
      "$_appdir/browser/chrome/icons/default/default${_size}.png" \
      "$pkgdir/usr/share/icons/hicolor/${_size}x${_size}/apps/$_launcher.png"
  done

  install -Dm644 /dev/stdin \
    "$_appdir/browser/defaults/preferences/vendor.js" <<'EOF'
// Use LANG environment variable to choose locale.
pref("intl.locale.requested", "");

// Use system-provided dictionaries.
pref("spellchecker.dictionary_path", "/usr/share/hunspell");

// Avoid first-run default browser noise on managed systems.
pref("browser.shell.checkDefaultBrowser", false);

// Don't disable extensions shipped in application directories.
pref("extensions.autoDisableScopes", 11);
EOF

  install -Dm644 /dev/stdin "$_appdir/distribution/distribution.ini" <<EOF
[Global]
id=archlinux
version=1.0
about=Zen Browser for Arch Linux

[Preferences]
app.distributor=archlinux
app.distributor.channel=$_launcher
app.partner.archlinux=archlinux
EOF

  install -Dm644 /dev/stdin "$_appdir/distribution/policies.json" <<'EOF'
{
  "policies": {
    "DisableAppUpdate": true
  }
}
EOF

  rm -f \
    "$_appdir/updater" \
    "$_appdir/updater.ini" \
    "$_appdir/update-settings.ini"

  if [[ -e "$_appdir/libnssckbi.so" ]]; then
    ln -sf ../libnssckbi.so "$_appdir/libnssckbi.so"
  fi
}