34 stdenv.mkDerivation (finalAttrs: rec {
35 pname = "spidermonkey";
38 outputs = [ "out" "dev" ];
41 url = "mirror://mozilla/firefox/releases/${version}esr/source/firefox-${version}esr.source.tar.xz";
45 patches = lib.optionals (lib.versionOlder version "91") [
46 # Fix build failure on armv7l using Debian patch
47 # Upstream bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1526653
49 url = "https://salsa.debian.org/mozilla-team/firefox/commit/fd6847c9416f9eebde636e21d794d25d1be8791d.patch";
50 hash = "sha512-K8U3Qyo7g4si2r/8kJdXyRoTrDHAY48x/YJ7YL+YBwlpfNQcHxX+EZvhRzW8FHYW+f7kOnJu9QykhE8PhSQ9zQ==";
53 # Remove this when updating to 79 - The patches are already applied upstream
54 # https://bugzilla.mozilla.org/show_bug.cgi?id=1318905
56 # Combination of 3 changesets, modified to apply on 78:
57 # - https://hg.mozilla.org/mozilla-central/rev/06d7e1b6b7e7
58 # - https://hg.mozilla.org/mozilla-central/rev/ec48f15d085c
59 # - https://hg.mozilla.org/mozilla-central/rev/6803dda74d33
60 ./add-riscv64-support.patch
61 ] ++ lib.optionals (lib.versionAtLeast version "102") [
62 # use pkg-config at all systems
63 ./always-check-for-pkg-config.patch
64 ./allow-system-s-nspr-and-icu-on-bootstrapped-sysroot.patch
65 ] ++ lib.optionals (lib.versionAtLeast version "91" && stdenv.hostPlatform.system == "i686-linux") [
66 # Fixes i686 build, https://bugzilla.mozilla.org/show_bug.cgi?id=1729459
67 ./fix-float-i686.patch
68 ] ++ lib.optionals (lib.versionAtLeast version "91" && lib.versionOlder version "102") [
69 # Fix 91 compatibility with python311
71 url = "https://src.fedoraproject.org/rpms/mozjs91/raw/rawhide/f/0001-Python-Build-Use-r-instead-of-rU-file-read-modes.patch";
72 hash = "sha256-WgDIBidB9XNQ/+HacK7jxWnjOF8PEUt5eB0+Aubtl48=";
81 # 78 requires python up to 3.9
82 (if lib.versionOlder version "91" then python39 else python3)
84 rustc.llvmPackages.llvm # for llvm-objdump
87 ] ++ lib.optionals (lib.versionOlder version "91") [
89 yasm # to buid icu? seems weird
90 ] ++ lib.optionals stdenv.isDarwin [
95 (if lib.versionOlder version "91" then icu67 else icu)
99 ] ++ lib.optionals stdenv.isDarwin [
105 buildPackages.stdenv.cc
108 setOutputFlags = false; # Configure script only understands --includedir
115 # Fedora and Arch disable optimize, but it doesn't seme to be necessary
116 # It turns on -O3 which some gcc version had a problem with:
117 # https://src.fedoraproject.org/rpms/mozjs38/c/761399aba092bcb1299bb4fccfd60f370ab4216e
122 ] ++ lib.optionals (lib.versionAtLeast version "91") [
128 ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
129 # Spidermonkey seems to use different host/build terminology for cross
131 "--host=${stdenv.buildPlatform.config}"
132 "--target=${stdenv.hostPlatform.config}"
135 # mkDerivation by default appends --build/--host to configureFlags when cross compiling
136 # These defaults are bogus for Spidermonkey - avoid passing them by providing an empty list
137 configurePlatforms = [ ];
139 enableParallelBuilding = true;
141 # cc-rs insists on using -mabi=lp64 (soft-float) for riscv64,
142 # while we have a double-float toolchain
143 env.NIX_CFLAGS_COMPILE = lib.optionalString (with stdenv.hostPlatform; isRiscV && is64bit && lib.versionOlder version "91") "-mabi=lp64d";
145 postPatch = lib.optionalString (lib.versionOlder version "102") ''
146 # This patch is a manually applied fix of
147 # https://bugzilla.mozilla.org/show_bug.cgi?id=1644600
148 # Once that bug is fixed, this can be removed.
149 # This is needed in, for example, `zeroad`.
150 substituteInPlace js/public/StructuredClone.h \
151 --replace "class SharedArrayRawBufferRefs {" \
152 "class JS_PUBLIC_API SharedArrayRawBufferRefs {"
155 preConfigure = lib.optionalString (lib.versionOlder version "91") ''
156 export CXXFLAGS="-fpermissive"
158 export LIBXUL_DIST=$out
159 export PYTHON="${buildPackages.python3.interpreter}"
160 '' + lib.optionalString (lib.versionAtLeast version "91") ''
164 export AC_MACRODIR=$PWD/build/autoconf/
166 '' + lib.optionalString (lib.versionAtLeast version "91" && lib.versionOlder version "115") ''
168 sh ../../build/autoconf/autoconf.sh --localdir=$PWD configure.in > configure
171 '' + lib.optionalString (lib.versionAtLeast version "115") ''
172 patchShebangs build/cargo-linker
174 # We can't build in js/src/, so create a build dir
177 configureScript=../js/src/configure
180 # Remove unnecessary static lib
182 moveToOutput bin/js${lib.versions.major version}-config "$dev"
183 rm $out/lib/libjs_static.ajs
184 ln -s $out/bin/js${lib.versions.major version} $out/bin/js
187 passthru.tests.run = callPackage ./test.nix {
188 spidermonkey = finalAttrs.finalPackage;
192 description = "Mozilla's JavaScript engine written in C/C++";
193 homepage = "https://spidermonkey.dev/";
194 license = licenses.mpl20; # TODO: MPL/GPL/LGPL tri-license for 78.
195 maintainers = with maintainers; [ abbradar lostnet catap ];
196 broken = stdenv.isDarwin && versionAtLeast version "115"; # Requires SDK 13.3 (see #242666).
197 platforms = platforms.unix;