forked from fastly/spidermonkey-wasi-embedding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-engine.sh
executable file
·147 lines (122 loc) · 3.8 KB
/
build-engine.sh
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env bash
set -euo pipefail
set -x
working_dir="$(pwd)"
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
mode="${1:-release}"
weval=""
if [[ $# > 1 ]] && [[ "$2" == "weval" ]]; then
weval=-weval
fi
mozconfig="${working_dir}/mozconfig-${mode}${weval}"
objdir="obj-$mode${weval}"
outdir="$mode${weval}"
rebuild="${REBUILD_ENGINE:-0}"
cat << EOF > "$mozconfig"
ac_add_options --enable-project=js
ac_add_options --enable-application=js
ac_add_options --target=wasm32-unknown-wasi
ac_add_options --without-system-zlib
ac_add_options --without-intl-api
ac_add_options --disable-jit
ac_add_options --disable-shared-js
ac_add_options --disable-shared-memory
ac_add_options --disable-tests
ac_add_options --disable-clang-plugin
ac_add_options --enable-jitspew
ac_add_options --enable-optimize=-O3
ac_add_options --enable-js-streams
ac_add_options --enable-portable-baseline-interp
ac_add_options --prefix=${working_dir}/${objdir}/dist
mk_add_options MOZ_OBJDIR=${working_dir}/${objdir}
mk_add_options AUTOCLOBBER=1
EOF
target="$(uname)"
case "$target" in
Linux)
echo "ac_add_options --disable-stdcxx-compat" >> "$mozconfig"
;;
Darwin)
echo "ac_add_options --host=aarch64-apple-darwin" >> "$mozconfig"
;;
*)
echo "Unsupported build target: $target"
exit 1
;;
esac
case "$mode" in
release)
echo "ac_add_options --disable-debug" >> "$mozconfig"
;;
debug)
echo "ac_add_options --enable-debug" >> "$mozconfig"
;;
*)
echo "Unknown build type: $mode"
exit 1
;;
esac
case "$weval" in
-weval)
echo "ac_add_options --enable-portable-baseline-interp-force" >> "$mozconfig"
echo "ac_add_options --enable-aot-ics" >> "$mozconfig"
echo "ac_add_options --enable-aot-ics-force" >> "$mozconfig"
echo "ac_add_options --enable-pbl-weval" >> "$mozconfig"
;;
esac
# For a full build (not a rebuild), we need to clone the repo and do some setup work.
# `rebuild.sh` invokes this script with REBUILD_ENGINE=1 which sets rebuild=1
# and skips this setup.
if [[ $rebuild == 0 ]]; then
# Ensure the Rust version matches that used by Gecko, and can compile to WASI
rustup target add wasm32-wasi
fetch_commits=
if [[ ! -a gecko-dev ]]; then
# Clone Gecko repository at the required revision
mkdir gecko-dev
git -C gecko-dev init
git -C gecko-dev remote add --no-tags -t wasi-embedding \
origin "$(cat "$script_dir/gecko-repository")"
fetch_commits=1
fi
target_rev="$(cat "$script_dir/gecko-revision")"
if [[ -n "$fetch_commits" ]] || \
[[ "$(git -C gecko-dev rev-parse HEAD)" != "$target_rev" ]]; then
git -C gecko-dev fetch --depth 1 origin "$target_rev"
git -C gecko-dev checkout FETCH_HEAD
fi
# Use Gecko's build system bootstrapping to ensure all dependencies are
# installed
cd gecko-dev
./mach --no-interactive bootstrap --application-choice=js --no-system-changes
# ... except, that doesn't install the wasi-sysroot, which we need, so we do
# that manually.
cd ~/.mozbuild
python3 \
"${working_dir}/gecko-dev/mach" \
--no-interactive \
artifact \
toolchain \
--bootstrap \
--from-build \
sysroot-wasm32-wasi
fi
cd "$working_dir"
# Build SpiderMonkey for WASI
MOZCONFIG="${mozconfig}" \
MOZ_FETCHES_DIR=~/.mozbuild \
CC=~/.mozbuild/clang/bin/clang \
CXX=~/.mozbuild/clang/bin/clang++ \
AR=~/.mozbuild/clang/bin/llvm-ar \
python3 "${working_dir}/gecko-dev/mach" \
--no-interactive \
build
# Copy header, object, and static lib files
rm -rf "$outdir"
mkdir -p "$outdir/lib"
cd "$objdir"
cp -Lr dist/include "../$outdir"
while read -r file; do
cp "$file" "../$outdir/lib"
done < "$script_dir/object-files.list"
cp js/src/build/libjs_static.a "wasm32-wasi/${mode}/libjsrust.a" "../$outdir/lib"