Skip to content

Commit a71e596

Browse files
authored
install gecko-dev as submodule and add scripts to compile to wasm (#636)
1 parent 3c0bf24 commit a71e596

File tree

9 files changed

+251
-9
lines changed

9 files changed

+251
-9
lines changed

.github/workflows/main.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ jobs:
6161
with:
6262
path: runtime
6363

64+
- name: gecko-dev hash
65+
id: gecko-dev-hash
66+
run: cd runtime/spidermonkey/gecko-dev && echo "GECKO_DEV_HASH=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
67+
shell: bash
68+
69+
6470
- name: Cache SpiderMonkey object files
6571
uses: actions/cache@v3
6672
id: sm-cache
@@ -69,10 +75,8 @@ jobs:
6975
runtime/spidermonkey/${{ matrix.profile }}
7076
key: cache-${{ hashFiles(
7177
'runtime/spidermonkey/build-engine.sh',
72-
'runtime/spidermonkey/gecko-revision',
73-
'runtime/spidermonkey/object-files.list',
74-
'runtime/rust-toolchain.toml'
75-
) }}-${{ matrix.profile }}
78+
'runtime/spidermonkey/object-files.list'
79+
) }}-${{ matrix.profile }}-${{ steps.gecko-dev-hash.outputs.GECKO_DEV_HASH }}
7680
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
7781

7882
- name: "Build SpiderMonkey"

.gitmodules

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
[submodule "runtime/spidermonkey"]
2-
path = runtime/spidermonkey
3-
url = https://github.com/fastly/spidermonkey-wasi-embedding.git
4-
shallow = true
51
[submodule "tests/wpt-harness/wpt"]
62
path = tests/wpt-harness/wpt
73
url = https://github.com/web-platform-tests/wpt.git
84
shallow = true
5+
[submodule "runtime/spidermonkey/gecko-dev"]
6+
path = runtime/spidermonkey/gecko-dev
7+
url = https://github.com/bytecodealliance/gecko-dev.git

runtime/spidermonkey

Lines changed: 0 additions & 1 deletion
This file was deleted.

runtime/spidermonkey/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/obj-release
2+
/obj-debug
3+
/release
4+
/debug
5+
/dist
6+
/mozconfig-*
7+
.DS_Store
8+
.vscode

runtime/spidermonkey/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Scripts for building SpiderMonkey, compiled to wasm32-wasi as a static library.
2+
3+
## Building from upstream source
4+
The `build-engine.sh` script can be used to build either release or debug builds. It's recommended that this script only be used in CI environments, as it bootstraps a build environment for SpiderMonkey on each invokation.
5+
6+
7+
### Building for release or debug
8+
The script can compile both release and debug builds, with `release` being the default. To compile a debug build, pass `debug` as the first argument:
9+
```sh
10+
sh build-engine.sh debug
11+
```
12+
13+
### Build output
14+
Running the build script will result in three different subdirectories in the current directory:
15+
- `include`, containing the public header files
16+
- `lib`, containing the object files and static libraries needed to statically link SpiderMonkey
17+
- `obj`, the output directory the SpiderMonkey build system creates. This can be ignored or deleted
18+

runtime/spidermonkey/build-engine.sh

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
set -x
5+
6+
working_dir="$(pwd)"
7+
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
8+
9+
mode="${1:-release}"
10+
mozconfig="${working_dir}/mozconfig-${mode}"
11+
objdir="obj-$mode"
12+
outdir="$mode"
13+
14+
cat << EOF > "$mozconfig"
15+
ac_add_options --enable-project=js
16+
ac_add_options --enable-application=js
17+
ac_add_options --target=wasm32-unknown-wasi
18+
ac_add_options --without-system-zlib
19+
ac_add_options --without-intl-api
20+
ac_add_options --disable-jit
21+
ac_add_options --disable-shared-js
22+
ac_add_options --disable-shared-memory
23+
ac_add_options --disable-tests
24+
ac_add_options --disable-clang-plugin
25+
ac_add_options --enable-jitspew
26+
ac_add_options --enable-optimize=-O3
27+
ac_add_options --enable-js-streams
28+
ac_add_options --enable-portable-baseline-interp
29+
ac_add_options --prefix=${working_dir}/${objdir}/dist
30+
mk_add_options MOZ_OBJDIR=${working_dir}/${objdir}
31+
mk_add_options AUTOCLOBBER=1
32+
EOF
33+
34+
target="$(uname)"
35+
case "$target" in
36+
Linux)
37+
echo "ac_add_options --disable-stdcxx-compat" >> "$mozconfig"
38+
;;
39+
40+
Darwin)
41+
echo "ac_add_options --host=aarch64-apple-darwin" >> "$mozconfig"
42+
;;
43+
44+
*)
45+
echo "Unsupported build target: $target"
46+
exit 1
47+
;;
48+
esac
49+
50+
case "$mode" in
51+
release)
52+
echo "ac_add_options --disable-debug" >> "$mozconfig"
53+
;;
54+
55+
debug)
56+
echo "ac_add_options --enable-debug" >> "$mozconfig"
57+
;;
58+
59+
*)
60+
echo "Unknown build type: $mode"
61+
exit 1
62+
;;
63+
esac
64+
65+
66+
# Ensure the Rust version matches that used by Gecko, and can compile to WASI
67+
rustup target add wasm32-wasi
68+
69+
# Use Gecko's build system bootstrapping to ensure all dependencies are
70+
# installed
71+
cd gecko-dev
72+
./mach --no-interactive bootstrap --application-choice=js --no-system-changes
73+
74+
# ... except, that doesn't install the wasi-sysroot, which we need, so we do
75+
# that manually.
76+
cd ~/.mozbuild
77+
python3 \
78+
"${working_dir}/gecko-dev/mach" \
79+
--no-interactive \
80+
artifact \
81+
toolchain \
82+
--bootstrap \
83+
--from-build \
84+
sysroot-wasm32-wasi
85+
86+
cd "$working_dir"
87+
88+
# Build SpiderMonkey for WASI
89+
MOZCONFIG="${mozconfig}" \
90+
MOZ_FETCHES_DIR=~/.mozbuild \
91+
CC=~/.mozbuild/clang/bin/clang \
92+
CXX=~/.mozbuild/clang/bin/clang++ \
93+
AR=~/.mozbuild/clang/bin/llvm-ar \
94+
python3 "${working_dir}/gecko-dev/mach" \
95+
--no-interactive \
96+
build
97+
98+
# Copy header, object, and static lib files
99+
rm -rf "$outdir"
100+
mkdir -p "$outdir/lib"
101+
102+
cd "$objdir"
103+
cp -Lr dist/include "../$outdir"
104+
105+
while read -r file; do
106+
cp "$file" "../$outdir/lib"
107+
done < "$script_dir/object-files.list"
108+
109+
cp js/src/build/libjs_static.a "wasm32-wasi/${mode}/libjsrust.a" "../$outdir/lib"

runtime/spidermonkey/gecko-dev

Submodule gecko-dev added at 52c032c
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
memory/build/Unified_cpp_memory_build0.o
2+
memory/mozalloc/Unified_cpp_memory_mozalloc0.o
3+
mozglue/misc/AutoProfilerLabel.o
4+
mozglue/misc/ConditionVariable_noop.o
5+
mozglue/misc/MmapFaultHandler.o
6+
mozglue/misc/Mutex_noop.o
7+
mozglue/misc/Printf.o
8+
mozglue/misc/StackWalk.o
9+
mozglue/misc/TimeStamp.o
10+
mozglue/misc/TimeStamp_posix.o
11+
mozglue/misc/Uptime.o
12+
mozglue/misc/Decimal.o
13+
mfbt/lz4.o
14+
mfbt/lz4frame.o
15+
mfbt/lz4hc.o
16+
mfbt/xxhash.o
17+
mfbt/Unified_cpp_mfbt0.o
18+
mfbt/Unified_cpp_mfbt1.o

runtime/spidermonkey/rebuild.sh

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
set -x
5+
6+
working_dir="$(pwd)"
7+
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
8+
9+
mode="${1:-release}"
10+
mozconfig="${working_dir}/mozconfig-${mode}"
11+
objdir="obj-$mode"
12+
outdir="$mode"
13+
14+
cat << EOF > "$mozconfig"
15+
ac_add_options --enable-project=js
16+
ac_add_options --enable-application=js
17+
ac_add_options --target=wasm32-unknown-wasi
18+
ac_add_options --without-system-zlib
19+
ac_add_options --without-intl-api
20+
ac_add_options --disable-jit
21+
ac_add_options --disable-shared-js
22+
ac_add_options --disable-shared-memory
23+
ac_add_options --disable-tests
24+
ac_add_options --disable-clang-plugin
25+
ac_add_options --enable-jitspew
26+
ac_add_options --enable-optimize=-O3
27+
ac_add_options --enable-js-streams
28+
ac_add_options --enable-portable-baseline-interp
29+
ac_add_options --prefix=${working_dir}/${objdir}/dist
30+
mk_add_options MOZ_OBJDIR=${working_dir}/${objdir}
31+
mk_add_options AUTOCLOBBER=1
32+
EOF
33+
34+
target="$(uname)"
35+
case "$target" in
36+
Linux)
37+
echo "ac_add_options --disable-stdcxx-compat" >> "$mozconfig"
38+
;;
39+
40+
Darwin)
41+
echo "ac_add_options --host=aarch64-apple-darwin" >> "$mozconfig"
42+
;;
43+
44+
*)
45+
echo "Unsupported build target: $target"
46+
exit 1
47+
;;
48+
esac
49+
50+
case "$mode" in
51+
release)
52+
echo "ac_add_options --disable-debug" >> "$mozconfig"
53+
;;
54+
55+
debug)
56+
echo "ac_add_options --enable-debug" >> "$mozconfig"
57+
;;
58+
59+
*)
60+
echo "Unknown build type: $mode"
61+
exit 1
62+
;;
63+
esac
64+
65+
# Build SpiderMonkey for WASI
66+
MOZCONFIG="${mozconfig}" \
67+
MOZ_FETCHES_DIR=~/.mozbuild \
68+
CC=~/.mozbuild/clang/bin/clang \
69+
CXX=~/.mozbuild/clang/bin/clang++ \
70+
AR=~/.mozbuild/clang/bin/llvm-ar \
71+
python3 "${working_dir}/gecko-dev/mach" \
72+
--no-interactive \
73+
build
74+
75+
# Copy header, object, and static lib files
76+
rm -rf "$outdir"
77+
mkdir -p "$outdir/lib"
78+
79+
cd "$objdir"
80+
cp -Lr dist/include "../$outdir"
81+
82+
while read -r file; do
83+
cp "$file" "../$outdir/lib"
84+
done < "$script_dir/object-files.list"
85+
86+
cp js/src/build/libjs_static.a "wasm32-wasi/${mode}/libjsrust.a" "../$outdir/lib"

0 commit comments

Comments
 (0)