1#!/usr/bin/env bash
2set -euo pipefail
3
4cd -P -- "$(dirname -- "$0")"
5
6ROOT=../
7BINARYEN="$ROOT/tools/binaryen/bin"
8WASI_SDK="$ROOT/tools/wasi-sdk/bin"
9
10trap 'rm -f sqlite3.tmp' EXIT
11
12"$WASI_SDK/clang" --target=wasm32-wasi -std=c23 -g0 -O2 \
13 -Wall -Wextra -Wno-unused-parameter -Wno-unused-function \
14 -o sqlite3.wasm "$ROOT/sqlite3/main.c" \
15 -I"$ROOT/sqlite3" \
16 -mexec-model=reactor \
17 -msimd128 -mmutable-globals -mmultivalue \
18 -mbulk-memory -mreference-types \
19 -mnontrapping-fptoint -msign-ext \
20 -fno-stack-protector -fno-stack-clash-protection \
21 -Wl,--stack-first \
22 -Wl,--import-undefined \
23 -Wl,--initial-memory=327680 \
24 -D_HAVE_SQLITE_CONFIG_H \
25 -DSQLITE_CUSTOM_INCLUDE=sqlite_opt.h \
26 $(awk '{print "-Wl,--export="$0}' exports.txt)
27
28"$BINARYEN/wasm-ctor-eval" -g -c _initialize sqlite3.wasm -o sqlite3.tmp
29"$BINARYEN/wasm-opt" -g --strip --strip-producers -c -O3 \
30 sqlite3.tmp -o sqlite3.wasm \
31 --enable-simd --enable-mutable-globals --enable-multivalue \
32 --enable-bulk-memory --enable-reference-types \
33 --enable-nontrapping-float-to-int --enable-sign-ext