@@ -25,53 +25,86 @@ ac_add_options --disable-clang-plugin
25
25
ac_add_options --enable-jitspew
26
26
ac_add_options --enable-optimize=-O3
27
27
ac_add_options --enable-js-streams
28
+ ac_add_options --disable-shared-memory
29
+ ac_add_options --wasm-no-experimental
30
+ ac_add_options --disable-wasm-extended-const
31
+ ac_add_options --disable-js-shell
28
32
ac_add_options --enable-portable-baseline-interp
33
+ ac_add_options --disable-cargo-incremental
29
34
ac_add_options --prefix=${working_dir} /${objdir} /dist
30
35
mk_add_options MOZ_OBJDIR=${working_dir} /${objdir}
31
36
mk_add_options AUTOCLOBBER=1
37
+
38
+ EOF
39
+
40
+ if [[ " $mode " == " release" ]]; then
41
+ cat << EOF >> "$mozconfig "
42
+ ac_add_options --enable-strip
43
+ ac_add_options --disable-debug
44
+ EOF
45
+ else
46
+ cat << EOF >> "$mozconfig "
47
+ ac_add_options --enable-debug
48
+ EOF
49
+ fi
50
+
51
+ cat << EOF >> "$mozconfig "
32
52
export RUSTFLAGS="-C relocation-model=pic"
33
- export RUSTC_BOOTSTRAP=1
53
+ export CARGOFLAGS="-Z build-std=panic_abort,std"
34
54
export CFLAGS="-fPIC"
35
55
export CXXFLAGS="-fPIC"
36
56
37
57
EOF
38
58
39
- target=" $( uname) "
40
- case " $target " in
41
- Linux)
59
+ # Note: the var name is chosen to not conflict with the one used by the toolchain
60
+ OS_NAME=" $( uname | tr ' [:upper:]' ' [:lower:]' ) "
61
+ export OS_NAME
62
+
63
+ case " $OS_NAME " in
64
+ linux)
42
65
echo " ac_add_options --disable-stdcxx-compat" >> " $mozconfig "
43
66
;;
44
67
45
- Darwin )
68
+ darwin )
46
69
echo " ac_add_options --host=aarch64-apple-darwin" >> " $mozconfig "
70
+ OS_NAME=" macos"
47
71
;;
48
72
49
73
* )
50
- echo " Unsupported build target: $target "
51
- exit 1
52
- ;;
53
- esac
54
-
55
- case " $mode " in
56
- release)
57
- echo " ac_add_options --disable-debug" >> " $mozconfig "
58
- ;;
59
-
60
- debug)
61
- echo " ac_add_options --enable-debug" >> " $mozconfig "
62
- ;;
63
-
64
- * )
65
- echo " Unknown build type: $mode "
74
+ echo " Can't build on OS $OS_NAME "
66
75
exit 1
67
76
;;
68
77
esac
69
78
70
79
71
80
# Ensure the Rust version matches that used by Gecko, and can compile to WASI
72
81
rustup target add wasm32-wasi
82
+ rustup component add rust-src
83
+
84
+ # Ensure that the expected WASI-SDK is installed
85
+ if [[ -z " ${WASI_SDK_PREFIX:- } " ]]; then
86
+ sdk_url=" $( sed " s/\$ OS_NAME/$OS_NAME /g" " $script_dir /wasi-sdk-url" ) "
87
+ echo " WASI_SDK_PREFIX not set, downloading SDK from ${sdk_url} ..."
88
+ mkdir -p wasi-sdk
89
+ cd wasi-sdk
90
+ curl -LO " $sdk_url "
91
+ sdk_file=" $( basename " $sdk_url " ) "
92
+ tar -xf " $sdk_file "
93
+ rm " $sdk_file "
94
+ WASI_SDK_PREFIX=$PWD /$( ls . | head -n 1)
95
+ export WASI_SDK_PREFIX
96
+ cd ..
97
+ echo " Downloaded and extracted. Using compiler and sysroot at ${WASI_SDK_PREFIX} for target compilation"
98
+ else
99
+ if [[ ! -d " ${WASI_SDK_PREFIX} " ]]; then
100
+ echo " WASI_SDK_PREFIX set, but directory does not exist: ${WASI_SDK_PREFIX} "
101
+ exit 1
102
+ fi
103
+ echo " WASI_SDK_PREFIX set, using compiler and sysroot at ${WASI_SDK_PREFIX} for target compilation"
104
+ fi
73
105
74
- fetch_commits=
106
+ # If the Gecko repository hasn't been cloned yet, do so now.
107
+ # Otherwise, assume it's in the right state already.
75
108
if [[ ! -a gecko-dev ]]; then
76
109
77
110
# Clone Gecko repository at the required revision
@@ -81,55 +114,59 @@ if [[ ! -a gecko-dev ]]; then
81
114
git -C gecko-dev remote add --no-tags -t wasi-embedding \
82
115
origin " $( cat " $script_dir /gecko-repository" ) "
83
116
84
- fetch_commits=1
117
+ target_rev=" $( cat " $script_dir /gecko-revision" ) "
118
+ if [[ " $( git -C gecko-dev rev-parse HEAD) " != " $target_rev " ]]; then
119
+ git -C gecko-dev fetch --depth 1 origin " $target_rev "
120
+ git -C gecko-dev checkout FETCH_HEAD
121
+ fi
85
122
fi
86
123
87
- target_rev=" $( cat " $script_dir /gecko-revision" ) "
88
- if [[ -n " $fetch_commits " ]] || \
89
- [[ " $( git -C gecko-dev rev-parse HEAD) " != " $target_rev " ]]; then
90
- git -C gecko-dev fetch --depth 1 origin " $target_rev "
91
- git -C gecko-dev checkout FETCH_HEAD
92
- fi
93
-
94
- # Use Gecko's build system bootstrapping to ensure all dependencies are
95
- # installed
124
+ # # Use Gecko's build system bootstrapping to ensure all dependencies are
125
+ # # installed
96
126
cd gecko-dev
97
127
./mach --no-interactive bootstrap --application-choice=js --no-system-changes
98
128
99
- # ... except, that doesn't install the wasi-sysroot, which we need, so we do
100
- # that manually.
101
- cd ~ /.mozbuild
102
- python3 \
103
- " ${working_dir} /gecko-dev/mach" \
104
- --no-interactive \
105
- artifact \
106
- toolchain \
107
- --bootstrap \
108
- --from-build \
109
- sysroot-wasm32-wasi
110
-
111
129
cd " $working_dir "
112
130
113
- if [[ -z " ${WASI_SDK_PREFIX} " ]]; then
114
- echo " WASI_SDK_PREFIX not set, using default compiler and sysroot"
115
- else
116
- mv ~ /.mozbuild/clang ~ /.mozbuild/clang.orig
117
- mv ~ /.mozbuild/sysroot-wasm32-wasi ~ /.mozbuild/sysroot-wasm32-wasi.orig
118
- ln -s " ${WASI_SDK_PREFIX} " ~ /.mozbuild/clang
119
- ln -s " ${WASI_SDK_PREFIX} /share/wasi-sysroot" ~ /.mozbuild/sysroot-wasm32-wasi
120
- fi
131
+ export CC=${WASI_SDK_PREFIX} /bin/clang
132
+ export CXX=${WASI_SDK_PREFIX} /bin/clang++
133
+ export AR=${WASI_SDK_PREFIX} /bin/llvm-ar
134
+ export HOST_CC=~ /.mozbuild/clang/bin/clang
135
+ export HOST_CXX=~ /.mozbuild/clang/bin/clang++
136
+ export HOST_AR=~ /.mozbuild/clang/bin/llvm-ar
121
137
122
138
# Build SpiderMonkey for WASI
123
139
MOZCONFIG=" ${mozconfig} " \
124
140
MOZ_FETCHES_DIR=~ /.mozbuild \
125
- CC=~ /.mozbuild/clang/bin/clang \
126
- CXX=~ /.mozbuild/clang/bin/clang++ \
127
- AR=~ /.mozbuild/clang/bin/llvm-ar \
128
141
python3 " ${working_dir} /gecko-dev/mach" \
129
142
--no-interactive \
130
- build
143
+ configure
144
+
145
+ # Always use our own WASI sysroot, not the one mozbuild might have downloaded.
146
+ rm -rf ~ /.mozbuild/sysroot-wasm32-wasi
147
+ ln -s " ${WASI_SDK_PREFIX} /share/wasi-sysroot" ~ /.mozbuild/sysroot-wasm32-wasi
148
+
149
+ MOZCONFIG=" ${mozconfig} " \
150
+ MOZ_FETCHES_DIR=~ /.mozbuild \
151
+ python3 " ${working_dir} /gecko-dev/mach" \
152
+ --no-interactive \
153
+ configure
154
+
155
+ cd " $objdir "
156
+ # Before actually building, we need to overwrite the .cargo/config file that mozbuild created,
157
+ # because otherwise we can't build the Rust stdlib with -fPIC.
158
+ # That file is created during the `pre-export` build step, so we run that now, then overwrite
159
+ # the file, then build.
160
+ make pre-export
161
+
162
+ if [[ -f .cargo/config ]]; then
163
+ echo " " > .cargo/config
164
+ fi
165
+
166
+ make -j$( nproc) -s
131
167
132
168
# Copy header, object, and static lib files
169
+ cd ..
133
170
rm -rf " $outdir "
134
171
mkdir -p " $outdir /lib"
135
172
@@ -140,4 +177,8 @@ while read -r file; do
140
177
cp " $file " " ../$outdir /lib"
141
178
done < " $script_dir /object-files.list"
142
179
143
- cp js/src/build/libjs_static.a " wasm32-wasi/${mode} /libjsrust.a" " ../$outdir /lib"
180
+ cp js/src/build/libjs_static.a " ../$outdir /lib"
181
+
182
+ if [[ -f " wasm32-wasi/${mode} /libjsrust.a" ]]; then
183
+ cp " wasm32-wasi/${mode} /libjsrust.a" " ../$outdir /lib"
184
+ fi
0 commit comments