nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ version, hash }:
2
3{
4 callPackage,
5 lib,
6 stdenv,
7 fetchurl,
8 fetchpatch,
9
10 # build time
11 apple-sdk_14,
12 apple-sdk_15,
13 buildPackages,
14 cargo,
15 m4,
16 perl,
17 pkg-config,
18 python3,
19 rust-cbindgen,
20 rustPlatform,
21 rustc,
22 which,
23 zip,
24 xcbuild,
25
26 # runtime
27 icu75,
28 icu77,
29 nspr,
30 readline,
31 zlib,
32 libiconv,
33}:
34
35stdenv.mkDerivation (finalAttrs: {
36 pname = "spidermonkey";
37 inherit version;
38
39 outputs = [
40 "out"
41 "dev"
42 ];
43
44 src = fetchurl {
45 url = "mirror://mozilla/firefox/releases/${version}esr/source/firefox-${version}esr.source.tar.xz";
46 inherit hash;
47 };
48
49 patches =
50 lib.optionals (lib.versionOlder version "128") [
51 # use pkg-config at all systems
52 ./always-check-for-pkg-config.patch
53 ./allow-system-s-nspr-and-icu-on-bootstrapped-sysroot.patch
54 ]
55 ++ lib.optionals (lib.versionAtLeast version "128") [
56 # rebased version of the above 2 patches
57 ./always-check-for-pkg-config-128.patch
58 ./allow-system-s-nspr-and-icu-on-bootstrapped-sysroot-128.patch
59 ]
60 ++ lib.optionals (stdenv.hostPlatform.system == "i686-linux") [
61 # Fixes i686 build, https://bugzilla.mozilla.org/show_bug.cgi?id=1729459
62 ./fix-float-i686.patch
63 ]
64 ++ lib.optionals (lib.versionAtLeast version "140") [
65 # mozjs-140.pc does not contain -DXP_UNIX on Linux
66 # https://bugzilla.mozilla.org/show_bug.cgi?id=1973994
67 (fetchpatch {
68 url = "https://src.fedoraproject.org/rpms/mozjs140/raw/49492baa47bc1d7b7d5bc738c4c81b4661302f27/f/9aa8b4b051dd539e0fbd5e08040870b3c712a846.patch";
69 hash = "sha256-SsyO5g7wlrxE7y2+VTHfmUDamofeZVqge8fv2y0ZhuU=";
70 })
71 ];
72
73 nativeBuildInputs = [
74 cargo
75 m4
76 perl
77 pkg-config
78 python3
79 rustc
80 rustc.llvmPackages.llvm # for llvm-objdump
81 which
82 zip
83 ]
84 ++ lib.optionals (lib.versionAtLeast version "128") [
85 rust-cbindgen
86 rustPlatform.bindgenHook
87 ]
88 ++ lib.optionals stdenv.hostPlatform.isDarwin [
89 xcbuild
90 ];
91
92 buildInputs = [
93 (if (lib.versionAtLeast version "140") then icu77 else icu75)
94 nspr
95 readline
96 zlib
97 ]
98 ++ lib.optionals stdenv.hostPlatform.isDarwin [
99 libiconv
100 (if (lib.versionAtLeast version "140") then apple-sdk_15 else apple-sdk_14)
101 ];
102
103 depsBuildBuild = [
104 buildPackages.stdenv.cc
105 ];
106
107 setOutputFlags = false; # Configure script only understands --includedir
108
109 configureFlags = [
110 "--with-intl-api"
111 "--with-system-icu"
112 "--with-system-nspr"
113 "--with-system-zlib"
114 # Fedora and Arch disable optimize, but it doesn't seme to be necessary
115 # It turns on -O3 which some gcc version had a problem with:
116 # https://src.fedoraproject.org/rpms/mozjs38/c/761399aba092bcb1299bb4fccfd60f370ab4216e
117 "--enable-optimize"
118 "--enable-readline"
119 "--enable-release"
120 "--enable-shared-js"
121 "--disable-debug"
122 ]
123 ++ lib.optionals (lib.versionAtLeast version "140") [
124 # For pkgconfig file.
125 # https://bugzilla.mozilla.org/show_bug.cgi?id=1907030
126 # https://bugzilla.mozilla.org/show_bug.cgi?id=1957023
127 "--includedir=${placeholder "dev"}/include"
128 ]
129 ++ [
130 "--disable-jemalloc"
131 "--disable-strip"
132 "--disable-tests"
133 # Spidermonkey seems to use different host/build terminology for cross
134 # compilation here.
135 "--host=${stdenv.buildPlatform.config}"
136 "--target=${stdenv.hostPlatform.config}"
137 ];
138
139 # mkDerivation by default appends --build/--host to configureFlags when cross compiling
140 # These defaults are bogus for Spidermonkey - avoid passing them by providing an empty list
141 configurePlatforms = [ ];
142
143 enableParallelBuilding = true;
144
145 preConfigure =
146 lib.optionalString (lib.versionAtLeast version "128") ''
147 export MOZBUILD_STATE_PATH=$TMPDIR/mozbuild
148 ''
149 + ''
150 export LIBXUL_DIST=$out
151 export PYTHON="${buildPackages.python3.interpreter}"
152 export M4=m4
153 export AWK=awk
154 export AS=$CC
155 export AC_MACRODIR=$PWD/build/autoconf/
156 patchShebangs build/cargo-linker
157 # We can't build in js/src/, so create a build dir
158 mkdir obj
159 cd obj/
160 configureScript=../js/src/configure
161 '';
162
163 env = lib.optionalAttrs (lib.versionAtLeast version "140") {
164 # '-Wformat-security' ignored without '-Wformat'
165 NIX_CFLAGS_COMPILE = "-Wformat";
166 };
167
168 # Remove unnecessary static lib
169 preFixup = ''
170 moveToOutput bin/js${lib.versions.major version}-config "$dev"
171 rm $out/lib/libjs_static.ajs
172 ln -s $out/bin/js${lib.versions.major version} $out/bin/js
173 '';
174
175 passthru.tests.run = callPackage ./test.nix {
176 spidermonkey = finalAttrs.finalPackage;
177 };
178
179 meta = {
180 description = "Mozilla's JavaScript engine written in C/C++";
181 homepage = "https://spidermonkey.dev/";
182 license = lib.licenses.mpl20;
183 maintainers = with lib.maintainers; [
184 catap
185 bobby285271
186 ];
187 # ERROR: Failed to find an adequate linker
188 broken = lib.versionOlder version "128" && stdenv.hostPlatform.isDarwin;
189 platforms = lib.platforms.unix;
190 };
191})