-
Notifications
You must be signed in to change notification settings - Fork 0
/
BUILDING.txt
126 lines (82 loc) · 4.63 KB
/
BUILDING.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
Building
Note when I say SM I mean Spidermonkey (I was getting bored of typing
Spidermonkey over and over).
Initial building is a slightly fiddly manual process right now. The plan it to
eventually turn this file in to a build script that will automate much of this
process.
Note there are 3 build variants for libmozjs-c.so
* mk-shared-shared : This creates a libmozjs-c.so that is dynamically linked to
libmozjs-52.so . This is the version that builds the fastest (about 3.5
seconds on my dog slow machine, if you have a decent machine it will be more
like 1s).
* mk-shared-static : This creates a libmozjs-c.so that is statically
linked to libjs_static.a (the static library vesion of SM). This takes about
20s to build on my machine, on a fast machine you are looking at about 5s.
* mk-shared-static-old : This does the same as mk-shared-static, but it uses
the same build commands as the offical jsshell binary (except the official
jsshell binary is not a shared library, it is an executable that is
statically linked to SM).
The reasons for 3 variants are as follows:
mk-shared-shared this version is good for development, but sometimes the SM
developers forget to expose some public JSAPI symbols to libmozjs-52.so . If
that occurs you must either fix the SM source to expose those symbols or
statically link to SM. This is what mk-shared-static is for. The next issue is
sometimes important APIs are not exposed to the public JSAPI. In that case you
can use mk-shared-static-old (which can access all the private SM APIs).
mk-shared-static is probably best for final deployment. That way you can
distribute a single shared library (libmozjs-c.so) that only exposes the C API.
Note you must also deploy nspr alongside libmozjs-c.so regardless of version.
Build steps:
I build the code on a Debian Wheezy root filesystem (both i386 and amd64 work).
First grab dependencies:
apt-get build-dep firefox-esr
This will install gcc-mozilla (we need that specific version of GCC to compile).
You will need to add it to your PATH:
export PATH=/usr/lib/gcc-mozilla/bin:$PATH
Grab the firefox-52.5.3esr source code and signatures from here:
https://archive.mozilla.org/pub/firefox/releases/52.5.3esr/source/firefox-52.5.3esr.source.tar.xz
https://archive.mozilla.org/pub/firefox/releases/52.5.3esr/SHA512SUMS
https://archive.mozilla.org/pub/firefox/releases/52.5.3esr/SHA512SUMS.asc
If you want, check the signatures (gpg --verify and then check the sha512sum
of the source code is correct)
Extract the tarball in to the directory /opt/ff52esr-src/ ie
tar xvf $wherever/firefox-52.5.3esr.source.tar.xz
mv firefox-52.5.3esr /opt/ff52esr-src/
So you now should have your source in /opt/ff52esr-src/
You can put the source wherever you want, but you will need to tweak my build
script if you put it anywhere other than the above location.
Next step is to build Spidermonkey:
cd /opt/ff52esr-src/js/src/
./configure --enable-release --enable-nspr-build --enable-stdcxx-compat --enable-ctypes --without-system-zlib --disable-jemalloc
make -j 2 # or however many cores you want to use
I want jsctypes (this will allow me to host a load of low level code in JS
rather than having to write a bunch of C/C++), which is why I have to also
enable the use of nspr.
Then install
make install DESTDIR=/opt/js52/ # again, you can set this to wherever, but you may need to tweak my build scripts
rename libjs_shared.ajs to libjs_shared.a
mv /opt/js52//usr/local/lib/libjs_static.ajs /opt/js52//usr/local/lib/libjs_static.a
copy over libmozglue.a
cp mozglue/build/libmozglue.a /opt/js52/usr/local/lib/
copy over nspr libs
cp dist/bin/libnspr4.so dist/bin/libplc4.so dist/bin/libplds4.so /opt/js52/usr/local/lib/
You should now have Spidermonkey built but libmozjs-52.so will segfault, we must link it with mozglue
sh $your-mozjs-c-dir/fix-libmozjs-so
cp dist/bin/libmozjs-52.so /opt/js52/usr/local/lib/
set up pkg-config
rm -r /opt/js52/usr/local/lib/pkgconfig/
cp -r /opt/mozjs-c-api/pkgconfig /opt/js52/usr/local/lib/
set up LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/opt/js52/usr/local/lib/:$LD_LIBRARY_PATH
We are now ready to build libmozjs-c.so . Go in to mozjs-c-api and run:
sh ./mk-shared-shared
If all is well you should now have a libmozjs-c.so binary in the current directory.
Add the current dir to your LD_LIBRARY_PATH
If you happen to build the version of libmozjs-c.so statically linked to
libmozjs-52.so (by using sh ./mk-shared-static) you'll notice that
libmozjs-c.so is huge (about 170MiB on x86). You can use 'strip' to bring it
down to about 24MiB.
Next run:
sh ./mk-example
You should now have an example program called example . All being well the
example program should work.