at 23.11-beta 199 lines 6.3 kB view raw
1{ version, hash }: 2 3{ callPackage 4, lib 5, stdenv 6, fetchurl 7, fetchpatch 8 9# build time 10, buildPackages 11, cargo 12, m4 13, perl 14, pkg-config 15, python3 16, python39 17, rustc 18, which 19, zip 20, autoconf213 21, yasm 22, xcbuild 23 24# runtime 25, icu 26, icu67 27, nspr 28, readline 29, zlib 30, libobjc 31, libiconv 32}: 33 34stdenv.mkDerivation (finalAttrs: rec { 35 pname = "spidermonkey"; 36 inherit version; 37 38 outputs = [ "out" "dev" ]; 39 40 src = fetchurl { 41 url = "mirror://mozilla/firefox/releases/${version}esr/source/firefox-${version}esr.source.tar.xz"; 42 inherit hash; 43 }; 44 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 48 (fetchpatch { 49 url = "https://salsa.debian.org/mozilla-team/firefox/commit/fd6847c9416f9eebde636e21d794d25d1be8791d.patch"; 50 hash = "sha512-K8U3Qyo7g4si2r/8kJdXyRoTrDHAY48x/YJ7YL+YBwlpfNQcHxX+EZvhRzW8FHYW+f7kOnJu9QykhE8PhSQ9zQ=="; 51 }) 52 53 # Remove this when updating to 79 - The patches are already applied upstream 54 # https://bugzilla.mozilla.org/show_bug.cgi?id=1318905 55 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 70 (fetchpatch { 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="; 73 }) 74 ]; 75 76 nativeBuildInputs = [ 77 cargo 78 m4 79 perl 80 pkg-config 81 # 78 requires python up to 3.9 82 (if lib.versionOlder version "91" then python39 else python3) 83 rustc 84 rustc.llvmPackages.llvm # for llvm-objdump 85 which 86 zip 87 ] ++ lib.optionals (lib.versionOlder version "91") [ 88 autoconf213 89 yasm # to buid icu? seems weird 90 ] ++ lib.optionals stdenv.isDarwin [ 91 xcbuild 92 ]; 93 94 buildInputs = [ 95 (if lib.versionOlder version "91" then icu67 else icu) 96 nspr 97 readline 98 zlib 99 ] ++ lib.optionals stdenv.isDarwin [ 100 libobjc 101 libiconv 102 ]; 103 104 depsBuildBuild = [ 105 buildPackages.stdenv.cc 106 ]; 107 108 setOutputFlags = false; # Configure script only understands --includedir 109 110 configureFlags = [ 111 "--with-intl-api" 112 "--with-system-icu" 113 "--with-system-nspr" 114 "--with-system-zlib" 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 118 "--enable-optimize" 119 "--enable-readline" 120 "--enable-release" 121 "--enable-shared-js" 122 ] ++ lib.optionals (lib.versionAtLeast version "91") [ 123 "--disable-debug" 124 ] ++ [ 125 "--disable-jemalloc" 126 "--disable-strip" 127 "--disable-tests" 128 ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ 129 # Spidermonkey seems to use different host/build terminology for cross 130 # compilation here. 131 "--host=${stdenv.buildPlatform.config}" 132 "--target=${stdenv.hostPlatform.config}" 133 ]; 134 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 = [ ]; 138 139 enableParallelBuilding = true; 140 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"; 144 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 {" 153 ''; 154 155 preConfigure = lib.optionalString (lib.versionOlder version "91") '' 156 export CXXFLAGS="-fpermissive" 157 '' + '' 158 export LIBXUL_DIST=$out 159 export PYTHON="${buildPackages.python3.interpreter}" 160 '' + lib.optionalString (lib.versionAtLeast version "91") '' 161 export M4=m4 162 export AWK=awk 163 export AS=$CC 164 export AC_MACRODIR=$PWD/build/autoconf/ 165 166 '' + lib.optionalString (lib.versionAtLeast version "91" && lib.versionOlder version "115") '' 167 pushd js/src 168 sh ../../build/autoconf/autoconf.sh --localdir=$PWD configure.in > configure 169 chmod +x configure 170 popd 171 '' + lib.optionalString (lib.versionAtLeast version "115") '' 172 patchShebangs build/cargo-linker 173 '' + '' 174 # We can't build in js/src/, so create a build dir 175 mkdir obj 176 cd obj/ 177 configureScript=../js/src/configure 178 ''; 179 180 # Remove unnecessary static lib 181 preFixup = '' 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 185 ''; 186 187 passthru.tests.run = callPackage ./test.nix { 188 spidermonkey = finalAttrs.finalPackage; 189 }; 190 191 meta = with lib; { 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; 198 }; 199})