summaryrefslogtreecommitdiff
path: root/PKGBUILD
blob: eed6829cc9b51a4a40f04d90be79f7a78e1840c0 (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
# Maintainer: jc_gargma <jc_gargma@iserlohn-fortress.net>
# Maintainer (Artix): Dudemanguy <dudemanguy@artixlinux.org>
# Contributor (AUR): Luna Jernberg <droidbittin@gmail.com>
# Contributor (AUR): Figue <ffigue@gmail.com>
# Contributor: Aqua-sama <aqua@iserlohn-fortress.net>
# Contributor (AUR): Jonathon Fernyhough <jonathon+m2x+dev>
# Contributor (Arch): Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor (Arch): Ionut Biru <ibiru@archlinux.org>
# Contributor (Arch): Jakub Schmidtke <sjakub@gmail.com>

# # I maintain this because:
# Arch version uses eme
# Arch version uses git
# Arch version uses python2
# Arch version uses clang
# Arch version requires signed addons
# Arch version doesn't remove system addons
# Arch version enables debug symbols
# Arch version lacks privacy and security by default
# Arch version uses alternate name which breaks addon packages

_modpgo=0

_pkgname=firefox
pkgname=${_pkgname}-esr
pkgver=102.11.0
_pkgver=${pkgver}esr
pkgrel=1
pkgdesc="Standalone web browser from mozilla.org"
arch=(x86_64 aarch64)
license=(MPL GPL LGPL)
url="https://www.mozilla.org/en-US/firefox/enterprise/"
depends=(gtk3 libxt mime-types dbus-glib ffmpeg ttf-font libpulse alsa-lib
         libffi icu libjpeg-turbo libvpx nspr nss pixman libwebp zlib)
makedepends=(unzip zip diffutils yasm mesa imake inetutils xorg-server-xvfb
             autoconf2.13 rust clang llvm jack nodejs cbindgen nasm
             lld dump_syms
             wasi-compiler-rt wasi-libc wasi-libc++ wasi-libc++abi
# Use as many system python modules as possible
             python-aiohttp python-appdirs python-async-timeout python-attrs
             python-cbor2 python-certifi python-chardet python-click python-colorama python-cram
             python-ecdsa
             python-idna python-importlib-metadata
             python-iso8601
             python-jaraco.context python-jaraco.functools python-jsonschema
             python-markupsafe python-mohawk python-more-itertools python-multidict
             python-nspektr
             python-ordered-set
             python-packaging python-pathspec python-pip python-ply python-pyasn1 python-pyasn1-modules python-pyparsing python-pyrsistent python-pytoml
             python-requests python-requests-unixsocket python-responses python-rsa
             python-six
             python-tomli python-tqdm python-trove-classifiers
             python-urllib3
             python-validate-pyproject python-voluptuous
             python-wheel
             python-yaml python-yarl
             python-zipp
             )
# # Firefox explicitly requires these python modules be outdated:
# python-psutil python-zstandard

# # Firefox explicitly forces these modules from bundled regardless of set system modules:
# python-typing-extensions

# # As a result of typing-extension being force bundled, these must also be bundled:
# python-pydantic
# # And as pydantic must be bundled, so must all other modules that require pydantic:
# python-inflect <- python-jaraco.text <- python-setuptools <- python-distro

# # Arch lacks these python modules:
# python-blessings
# python-compare-locales python-cookies
# python-diskcache
# python-esprima
# python-fluent.migrate python-fluent.syntax
# python-idna_ssl
# python-Jinja2 python-jsmin python-json-e
# python-mozilla-version
# python-pip-tools
# python-redo
# python-sentry-sdk python-slugid
# python-taskcluster python-taskcluster-taskgraph python-taskcluster-urls
# python-yamllint
optdepends=('networkmanager: Location detection via available WiFi networks'
            'libnotify: Notification integration'
            'alsa-utils: ALSA support'
            'jack: Jack support'
            'pulseaudio: PulseAudio support'
            'speech-dispatcher: Text-to-Speech'
            'hunspell-en_CA: Spell checking, Canadian English'
            'xdg-desktop-portal: Screensharing with Wayland'
            'firefox-preferences: Custom vendor.js with security by default'
            'firefox-preferences-basic: Custom vendor.js with less breaking changes')
options=(!emptydirs !makeflags !lto !debug)
conflicts=(firefox)
provides=(firefox)
source=(
        "https://archive.mozilla.org/pub/$_pkgname/releases/$_pkgver/source/$_pkgname-$_pkgver.source.tar.xz"{,.asc}
        0001-Add-a-few-missing-cstdint-includes.patch
        zstandard-0.18.0.diff
        $pkgname.desktop
        identity-icons-brand.svg
        distribution.ini
        #mozconfig.in.gcc
        mozconfig.in.clang
        mozconfig.common.override
        #arc4_enable-lto-for-gcc.patch
        #firefox-gcc-build.patch
        #arc4_enable-pgo-for-gcc.patch
        #pgo.patch
        arc4_remove-health-reporting.patch
        arc4_remove-system-addons.patch
        )
sha512sums=('fdfed404c87f33001c0ab50f9899fa80c897fac645be8ed832e426f412aafbf1468b1c8301bad463b3f5535b6d6f2005a96a748b6e2d6bf5afbc3b5bc10983d6'
            'SKIP'
            '3e05c6c1c415f013c31c6ba90c593703a0017bc1057867bd3c8de308ded14f4c0a38808aae2365dda31f03cefcf10eeb3d20a9b75095bfcd698f786def348f32'
            'c949cf492bc93b6f3f1f827744e0f39e555c518434c8e73e27143a769b0d123fe4ba2cae07b7b7e7b594f8da43383d4fb4cd28b6b52e0d3e7a985afbadfb3d04'
            '46b76cc688099bbd4124c0b94eea45c1c43a95e1aab9ea8ff6b9c29cdefe383f7a4885f09ceef34e5e6ee2f1f589024b575352b26512feca703c68a48dc5818f'
            'b579b73176c72a5ecf36e3f63bba08fdb8041ae99d54e5cab906660fed6a9cf2311f7ca1ec1649e451cc6d5a4b1e6060b974b1d7befe9c8df3c5a89c50383c17'
            'b075df0ddbcbc5eed5ef9d02d859da8f104fe507808050e9a990c8f3aeb01645b77972a3af07bd2427680449104af623065d97fbbc40fc42aea0b5ba931e8324'
            '0250c7789519ca011b87238fbb9a5b7067ae0b5e9c3ac7a0c7700199e47d0d7ef11cdcc33444a5cf1f0b23aaeb59c84bf7fb11965b4d8cf518066a4e0b76d595'
            '6c933ebfd683b955a3deb2f47b13f582ccd40f57e1164a0c821a65c4bc6040a1e0baf3a4aab1354c3e0ceeb4f3fab53612e54dfd0f56d320cf0a64bf3c270526'
            '34b90b6033d8c6196600aa820f8d5038ef506f07a6c8b90bc1b5691c47172df8778757aa9db68116bef9ced2d5592320e6d7a47cfb20cf133ba5757739d9968d'
            'e3e095eaa6427d1f8a392b16789ba51c1f13ec8a26f9128eada7fbf190ca8a47c92453e6cfd89676138869e7fdac765ff83cde01cc8b02d1de914c7eb4b1b22e')
b2sums=('b19db1b35e6c652e2cd44ec5219bd5c42aacd55987962dbcaf50b5ec54d2ac5066290264f938ba3d45ef111779b9f27b06736ae7df11fa62478ab2179acfe723'
        'SKIP'
        '65bb23f1316b6ea93941ae68530ce4178b135bd4b502265e0cfa57262e00008837f279d2b943ec01745fc0bdb429d3efa351d7f9d84445a9f88e2a7f6f42040e'
        'b66218c1388f5cb549f4084273f56cca53311bff948c041ccb09745cf483a66973b5419950d9a9df7c9813005842300e05358f4004978f3bdabecc82b946809f'
        '1c3af4cc5199cf7b9f3aad9ceab98b3e8a3dc0d38f50896ed2f32ac648f1e904a1cdda5da559964885989edbfab4c4bf65448e9a0f71d946c77ec0ab5a6aff4c'
        '63a8dd9d8910f9efb353bed452d8b4b2a2da435857ccee083fc0c557f8c4c1339ca593b463db320f70387a1b63f1a79e709e9d12c69520993e26d85a3d742e34'
        '877eda442eb4730600dccf209a6e961ad3122ab456bbfda4ff041e8493ebaaf96224ac218360931259ff4214482f6bf65b3a3052f977ade1a274f38ffd859535'
        'e19354af8bfb4cce4c2e0dbddc6a9087aab97b2e77e9e5afefc8960c5dba0846d8a8e8061334dca50c0ab515f8114fcb36c9d8ba6e2cb31b00d3e8b70319db66'
        '0f8e203bda791428acf526481959978d26e988d34b5f0490c2f9ac3307feefaf7ec7511ba4647c3f254c86288a7265476df860dee38ae5a7aaba9e264b1fe4bc'
        '1dce1277c0c8b83089551057ed61c8794aa65242d0c19573dab96081f00b1042af73fbc0a40ba49dfa31eff46f4636ffd985cf8e6bd28db614a639ca6c11c74e'
        '379adf3726664668f6167eaeab35dec40342d9288ff081d22a8363f163ab0945b17ce69e7d4276a31e99e56f690afa070c410c51a5060ed835356fd216256e7b')
validpgpkeys=('14F26682D0916CDD81E37B6D61B7B526D98F0353')  # Mozilla Software Releases

prepare() {
  mkdir -p mozbuild
  cd ${_pkgname}-${pkgver}

  # Unbreak build with python-zstandard 0.18.0
  patch -Np1 -i ../zstandard-0.18.0.diff

  # Fixes building with gcc 13
  patch -Np1 -i ../0001-Add-a-few-missing-cstdint-includes.patch


  if [ "${_modpgo}" == "1" ]; then
    # Add the custom mozconfig for clang pgo
    cp $srcdir/mozconfig.in.clang $srcdir/${_pkgname}-${pkgver}/.mozconfig
  cat >>$srcdir/${_pkgname}-${pkgver}/.mozconfig - <<END
mk_add_options MOZ_OBJDIR=${PWD@Q}/obj
ac_add_options --enable-profile-generate=cross
END
  elif [ "${_modpgo}" == "0" ]; then
    # Add the custom mozconfig for clang
    cp $srcdir/mozconfig.in.clang $srcdir/${_pkgname}-${pkgver}/.mozconfig
  cat >>$srcdir/${_pkgname}-${pkgver}/.mozconfig - <<END
mk_add_options MOZ_OBJDIR=${PWD@Q}/obj
END
  fi

  # MOZ_TELEMETRY_REPORTING only applied correctly when set in this override file
  cp $srcdir/mozconfig.common.override $srcdir/${_pkgname}-${pkgver}/build/mozconfig.common.override


  # Disable various components at the source level
  sed -i 's|[;]1|;0|' $srcdir/${_pkgname}-${pkgver}/toolkit/components/telemetry/TelemetryStartup.manifest
  sed -i 's/;1/;0/' $srcdir/${_pkgname}-${pkgver}/toolkit/components/telemetry/components.conf

  # Patch out health reporting so that MOZ_DATA_REPORTING=0 can be applied.
  patch -Np1 -i ../arc4_remove-health-reporting.patch

  # Remove @RESPATH@/browser/features/* to prevent system addons from being part of the output package.
  patch -Np1 -i ../arc4_remove-system-addons.patch


  # Hide mobile promo
#  echo ".fxaMobilePromo {  display: none !important; }" >> browser/themes/shared/incontentprefs/preferences.inc.css
  # Hide plugindeprecation-notice
  echo "#plugindeprecation-notice {  display: none !important; }" >> toolkit/mozapps/extensions/content/extensions.css
  # Hide warnings on unsigned extensions
  echo ".warning{display: none!important; } .addon[notification=warning]{background-image: none!important;}" >> toolkit/mozapps/extensions/content/extensions.css
}

build() {
  cd ${_pkgname}-${pkgver}

  export MOZ_NOSPAM=1
  export MOZBUILD_STATE_PATH="$srcdir/mozbuild"
  export MACH_BUILD_PYTHON_NATIVE_PACKAGE_SOURCE=system

  # firefox is prone to OOM, use 1 thread per 2GB ram
  #export MOZ_MAKE_FLAGS="${MAKEFLAGS}"
  export MOZ_MAKE_FLAGS="-j32"

  # -flto breaks cargo
  # -fPIE and -pie break compiling
  export CFLAGS="$CFLAGS -O3 -fstack-protector-all -fPIC"
  export CXXFLAGS="$CXXFLAGS -O3 -fstack-protector-all -fPIC"

  # LTO needs more open files
  ulimit -n 4096


  if [ "${_modpgo}" == "1" ]; then
  # clang does not support -fstack-clash-protection, so remove it
  #export CFLAGS="$(echo $CFLAGS | sed 's/ -fstack-clash-protection//' - )"
  #export CXXFLAGS="$(echo $CXXFLAGS | sed 's/ -fstack-clash-protection//' - )"

  # Do 3-tier PGO
  echo "Building instrumented browser..."
  ./mach build

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

  stat -c "Profile data found (%s bytes)" merged.profdata
  test -s merged.profdata

  stat -c "Jar log found (%s bytes)" jarlog
  test -s jarlog

  echo "Removing instrumented browser..."
  ./mach clobber

  echo "Building optimized browser..."
  # Add the custom mozconfig
  cp $srcdir/mozconfig.in.clang $srcdir/${_pkgname}-${pkgver}/.mozconfig
  cat >>$srcdir/${_pkgname}-${pkgver}/.mozconfig - <<END
mk_add_options MOZ_OBJDIR=${PWD@Q}/obj
ac_add_options --enable-lto=cross
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
END
  ./mach build

  else
    echo "Building optimized browser..."
    xvfb-run -s "-screen 0 1920x1080x24 -nolisten local" ./mach build
  fi
}

package() {
  cd ${_pkgname}-${pkgver}
  DESTDIR="$pkgdir" ./mach install

  # Don't install in /usr/local
  #rm -rf "$pkgdir/usr/local/bin"
  #mkdir "$pkgdir/usr/lib"
  #mkdir "$pkgdir/usr/bin"
  #cp -r --reflink "$pkgdir/usr/local/lib/firefox" "$pkgdir/usr/lib/firefox"
  #rm -rf "$pkgdir/usr/local/lib/firefox"

  install -Dm644 $srcdir/distribution.ini \
  "$pkgdir/usr/lib/$_pkgname/distribution/distribution.ini"

  # use a symlink in /usr/bin instead
  ln -sf "/usr/lib/$_pkgname/firefox" "$pkgdir/usr/bin/firefox"


  # icons
  local i theme=official
  for i in 16 22 24 32 48 64 128 256; do
    install -Dvm644 browser/branding/$theme/default$i.png \
      "$pkgdir/usr/share/icons/hicolor/${i}x${i}/apps/$pkgname.png"
  done
  install -Dvm644 browser/branding/$theme/content/about-logo.png \
    "$pkgdir/usr/share/icons/hicolor/192x192/apps/$pkgname.png"
  install -Dvm644 browser/branding/$theme/content/about-logo@2x.png \
    "$pkgdir/usr/share/icons/hicolor/384x384/apps/$pkgname.png"
  install -Dvm644 browser/branding/$theme/content/about-logo.svg \
    "$pkgdir/usr/share/icons/hicolor/scalable/apps/$pkgname.svg"
  install -Dvm644 ../identity-icons-brand.svg \
    "$pkgdir/usr/share/icons/hicolor/symbolic/apps/$pkgname-symbolic.svg"

  # install desktop file
  install -Dvm644 ../$pkgname.desktop \
    "$pkgdir/usr/share/applications/$pkgname.desktop"

   # Use system certificates
  local nssckbi="$pkgdir/usr/lib/$_pkgname/libnssckbi.so"
  if [[ -e $nssckbi ]]; then
    ln -srfv "$pkgdir/usr/lib/libnssckbi.so" "$nssckbi"
  fi
}