Name js140
Description JavaScript interpreter and libraries - Version 140
Version 140.7.1-1
Package Base js140
Homepage https://spidermonkey.dev/
Maintainers ['Jan Alexander Steffens (heftig) <heftig@archlinux.org>']
Contributors []
Distro-repo https://gitlab.archlinux.org/archlinux/packaging/packages/js140
Sources ['0001-Bug-1973994-mozjs-140.pc-does-not-contain-DXP_UNIX-o.patch', '0002-Bug-1969769-Change-uses-of-ast.Str-with-ast.Constant.patch', '0003-Bug-1983713-Use-non-deprecated-ast-value.-r-firefox-.patch', '0004-Bug-1983736-Patch-jsonschema-to-work-with-Python-3.1.patch', '0005-Bug-1993797-Fix-AST-parsing-in-DecoratorVisitor-for-.patch', 'https://archive.mozilla.org/pub/firefox/releases/140.7.1esr/source/firefox-140.7.1esr.source.tar.xz', 'https://archive.mozilla.org/pub/firefox/releases/140.7.1esr/source/firefox-140.7.1esr.source.tar.xz.asc']
Dependencies ['glibc', 'libgcc', 'libstdc++', 'readline', 'sh', 'zlib']
Optional-Dependencies []
Build-Dependencies ['cbindgen', 'clang', 'lld', 'llvm', 'python', 'rust', 'zip']
Provides []
Builddate 16-02-2026 15:05:14
Architecture x86_64
Distro-Version
Licenses ['MPL-2.0']
Hash bd995826a72d50888d39bd244397082b05ed7ac6b40febf5b6d1fbfc98cddabb
# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>

pkgname=js140
pkgver=140.7.1
pkgrel=1
pkgdesc="JavaScript interpreter and libraries - Version 140"
url="https://spidermonkey.dev/"
arch=(x86_64)
license=(MPL-2.0)
depends=(
  glibc
  libgcc
  libstdc++
  readline
  sh
  zlib
)
makedepends=(
  cbindgen
  clang
  lld
  llvm
  python
  rust
  zip
)
checkdepends=(
  git
  mercurial
)
options=(
  !lto
)
_relver=${pkgver}esr
source=(
  https://archive.mozilla.org/pub/firefox/releases/$_relver/source/firefox-$_relver.source.tar.xz{,.asc}
  0001-Bug-1973994-mozjs-140.pc-does-not-contain-DXP_UNIX-o.patch
  0002-Bug-1969769-Change-uses-of-ast.Str-with-ast.Constant.patch
  0003-Bug-1983713-Use-non-deprecated-ast-value.-r-firefox-.patch
  0004-Bug-1983736-Patch-jsonschema-to-work-with-Python-3.1.patch
  0005-Bug-1993797-Fix-AST-parsing-in-DecoratorVisitor-for-.patch
)
validpgpkeys=(
  # Mozilla Software Releases <release@mozilla.com>
  # https://blog.mozilla.org/security/2025/04/01/updated-gpg-key-for-signing-firefox-releases-2/
  14F26682D0916CDD81E37B6D61B7B526D98F0353
)
sha256sums=('e42d26aeabd17ab1e642656c7b1bc8cadf705ce2ac6751b103dd407f5af32827'
            'SKIP'
            'b5178a7b8a603b645cbae61467f3fa1fef6e9f34c90e4a22faf4ea2152a50fba'
            '941db682a37888582eb1608b936d57c73d7ce4377f4831c73cabb56745734013'
            'a8ed1bf4a0e17118fe6e11b33840d9a2ab7023deb377c44d23a51f9daad06d1e'
            '5173051257f4fd8ed7c0811f01126a6a0f17c9ab6e561b4e0a89cc67509ccdc5'
            'ab43fa4fc086926e03bb0fcd2e7a0fac16a9f498461661951d043dc2ba41ca33')
b2sums=('89699f1200a913205ef93aac5ce24aeed1be41f2befa7d5fcb4d5a7a0124ad8b42fb7075243ee09efb0de7e793df1e753bb8b275515d5b3efa690d49be28b249'
        'SKIP'
        '89f39bd3ef2ca4894d98f860c2296b2afa58e4fe8c68ddb816a0684cc0db3a8e0deec71af5d214fb3ae40f6ad963aefef02d6b71071c41b9b55752c7cf791a9c'
        'dac1b03aadcde42f9ebdfc91e2806a35a2ab78e0c7f1b15bbfb5970700f4d9db34ee1b561470baee4ac1cb3f42a946a01f5afabb53d8ce92a497382b90e21552'
        'ae4d401c7375737b394654ab6d7cb9e61e34013f583ef05c57e74c6f6e9700ed6787afb83fab88e826e0f086e5e079258f0c1cdddf89b3e792ff67611e781052'
        'e2421669901b4549700ec5abccd07a169fe0a3d2c5ddadecf55bc911f68df64ce6154431f01e1ad16c4af0299b029f6df787bf74b3070fece270cec9b74c907d'
        '3d51383d407f7d9c5da8df55899e2ff6a0fdbbf07583af0e06c8bcefda73b1fcecd89ffea52f822ae605a14d498f11b0e492b686ad711d0e3dc97a2c601fdaa0')

# Make sure the duplication between bin and lib is found
COMPRESSZST+=(--long)

prepare() {
  mkdir mozbuild
  cd firefox-$pkgver

  # https://discourse.gnome.org/t/gnome-49-to-depend-on-spidermonkey-140/30470
  patch -Np1 -i ../0001-Bug-1973994-mozjs-140.pc-does-not-contain-DXP_UNIX-o.patch

  # Fix build with Python 3.14
  patch -Np1 -i ../0002-Bug-1969769-Change-uses-of-ast.Str-with-ast.Constant.patch
  patch -Np1 -i ../0003-Bug-1983713-Use-non-deprecated-ast-value.-r-firefox-.patch
  patch -Np1 -i ../0004-Bug-1983736-Patch-jsonschema-to-work-with-Python-3.1.patch
  patch -Np1 -i ../0005-Bug-1993797-Fix-AST-parsing-in-DecoratorVisitor-for-.patch

  cat >../mozconfig <<END
ac_add_options --enable-application=js
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
ac_add_options --enable-rust-simd
ac_add_options --enable-linker=lld
ac_add_options --disable-bootstrap
ac_add_options --disable-debug
ac_add_options --disable-jemalloc
ac_add_options --disable-strip

# System libraries
ac_add_options --with-system-zlib
ac_add_options --without-system-icu

# Features
ac_add_options --enable-readline
ac_add_options --enable-shared-js
ac_add_options --enable-tests
ac_add_options --with-intl-api
END
}

build() {
  cd firefox-$pkgver

  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

  # malloc_usable_size is used in various parts of the codebase
  CFLAGS="${CFLAGS/_FORTIFY_SOURCE=3/_FORTIFY_SOURCE=2}"
  CXXFLAGS="${CXXFLAGS/_FORTIFY_SOURCE=3/_FORTIFY_SOURCE=2}"

  # Do 3-tier PGO
  echo "Building instrumented JS..."
  cat >.mozconfig ../mozconfig - <<END
ac_add_options --enable-profile-generate=cross
END
  ./mach build --priority normal

  echo "Profiling instrumented JS..."
  (
    local js="$PWD/obj/dist/bin/js"
    export LLVM_PROFILE_FILE="$PWD/js-%p-%m.profraw"

    cd js/src/octane
    "$js" run.js

    cd ../../../third_party/webkit/PerformanceTests/ARES-6
    "$js" cli.js

    cd ../SunSpider/sunspider-0.9.1
    "$js" sunspider-standalone-driver.js
  )

  llvm-profdata merge -o merged.profdata *.profraw

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

  echo "Removing instrumented JS..."
  ./mach clobber objdir

  echo "Building optimized JS..."
  cat >.mozconfig ../mozconfig - <<END
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
END
  ./mach build --priority normal
}

check() {
  local jstests_extra_args=(
    --format=none
    --exclude-random
    --wpt=disabled
  ) jittest_extra_args=(
    --format=none
    --timeout 300
  ) jittest_test_args=(
    basic
  )

  cd firefox-$pkgver/obj
  make -C js/src check-jstests check-jit-test \
    JSTESTS_EXTRA_ARGS="${jstests_extra_args[*]}" \
    JITTEST_EXTRA_ARGS="${jittest_extra_args[*]}" \
    JITTEST_TEST_ARGS="${jittest_test_args[*]}"
}

package() {
  cd firefox-$pkgver/obj
  make DESTDIR="$pkgdir" install
  rm "$pkgdir"/usr/lib/*.ajs
  find "$pkgdir"/usr/{lib/pkgconfig,include} -type f -exec chmod -c a-x {} +
}

# vim:set sw=2 sts=-1 et: