@@ -0,0 +1,95 @@
1+{ stdenv, fetchurl, fetchpatch, autoconf213, pkgconfig, perl, zip, which, readline, icu, zlib, nspr, buildPackages }:
2+
3+let
4+ version = "52.9.0";
5+in stdenv.mkDerivation {
6+ pname = "spidermonkey";
7+ inherit version;
8+
9+ src = fetchurl {
10+ url = "mirror://mozilla/firefox/releases/${version}esr/source/firefox-${version}esr.source.tar.xz";
11+ sha256 = "1mlx34fgh1kaqamrkl5isf0npch3mm6s4lz3jsjb7hakiijhj7f0";
12+ };
13+
14+ outputs = [ "out" "dev" ];
15+ setOutputFlags = false; # Configure script only understands --includedir
16+
17+ buildInputs = [ readline icu zlib nspr ];
18+ nativeBuildInputs = [ autoconf213 pkgconfig perl which buildPackages.python2 zip ];
19+
20+ # Apparently this package fails to build correctly with modern compilers, which at least
21+ # on ARMv6 causes polkit testsuite to break with an assertion failure in spidermonkey.
22+ # These flags were stolen from:
23+ # https://git.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/js52
24+ NIX_CFLAGS_COMPILE = "-fno-delete-null-pointer-checks -fno-strict-aliasing -fno-tree-vrp";
25+
26+ patches = [
27+ # needed to build gnome3.gjs
28+ (fetchpatch {
29+ name = "mozjs52-disable-mozglue.patch";
30+ url = https://git.archlinux.org/svntogit/packages.git/plain/trunk/mozjs52-disable-mozglue.patch?h=packages/js52&id=4279d2e18d9a44f6375f584911f63d13de7704be;
31+ sha256 = "18wkss0agdyff107p5lfflk72qiz350xqw2yqc353alkx4fsfpz0";
32+ })
33+ (fetchpatch {
34+ url = https://git.archlinux.org/svntogit/packages.git/plain/trunk/no-error.diff?h=packages/js52;
35+ sha256 = "1vsw6558lxiy0r1mg6y49cgddan1mfqvqlkyv734bgxyg6n3pb9i";
36+ })
37+ ./fix-werror.patch
38+ ];
39+
40+ configurePlatforms = [ ];
41+
42+ preConfigure = ''
43+ export CXXFLAGS="-fpermissive"
44+ export LIBXUL_DIST=$out
45+ export PYTHON="${buildPackages.python2.interpreter}"
46+ configureFlagsArray+=("--includedir=$dev/include")
47+
48+ cd js/src
49+
50+ autoconf
51+ '';
52+
53+ configureFlags = [
54+ "--with-nspr-prefix=${nspr}"
55+ "--with-system-zlib"
56+ "--with-system-icu"
57+ "--with-intl-api"
58+ "--enable-readline"
59+ "--enable-shared-js"
60+ ] ++ stdenv.lib.optional stdenv.hostPlatform.isMusl "--disable-jemalloc"
61+ ++ stdenv.lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
62+ "--host=${stdenv.buildPlatform.config}"
63+ "--target=${stdenv.hostPlatform.config}"
64+ ];
65+
66+ makeFlags = [
67+ "HOST_CC=${buildPackages.stdenv.cc}/bin/cc"
68+ ];
69+
70+ depsBuildBuild = [ buildPackages.stdenv.cc ];
71+
72+ enableParallelBuilding = true;
73+
74+ postInstall = ''
75+ moveToOutput bin/js52-config "$dev"
76+ # Nuke a static lib.
77+ rm $out/lib/libjs_static.ajs
78+ '';
79+
80+ meta = with stdenv.lib; {
81+ description = "Mozilla's JavaScript engine written in C/C++";
82+ homepage = https://developer.mozilla.org/en/SpiderMonkey;
83+ license = licenses.gpl2; # TODO: MPL/GPL/LGPL tri-license.
84+ maintainers = [ maintainers.abbradar ];
85+ platforms = platforms.linux;
86+
87+ # Commented out so hydra builds the package
88+ # (I know what you're thinking now, but cjs won't be pulling anything from the network
89+ # and modules are allowed to execute commands anyways, so an RCE is basically irrelevant)
90+ #
91+ # knownVulnerabilities = [
92+ # "The runtime was extracted from Firefox 52, which EOL’d on September 5, 2018."
93+ # ];
94+ };
95+}