@@ -7,6 +7,13 @@ OUT_DIR="${OUT_DIR:-/out}"
77SRC_DIR=" ${WORKDIR:-/ build/ sqlite-src} "
88HOST_UID=" ${HOST_UID:- } "
99HOST_GID=" ${HOST_GID:- } "
10+ DEFAULT_OMIT_API_BUILDS=" core=kvvfs OPFS vtab worker1;core-vtab=kvvfs OPFS worker1;core-kvvfs=OPFS vtab worker1;core-opfs=kvvfs opfs-wl opfs-sahpool vtab worker1;core-opfs-wl=kvvfs opfs opfs-sahpool vtab worker1;core-opfs-sahpool=kvvfs opfs opfs-wl vtab worker1"
11+
12+ if [ " ${SQLITE_WASM_OMIT_API_BUILDS+x} " = " x" ]; then
13+ OMIT_API_BUILDS=" $SQLITE_WASM_OMIT_API_BUILDS "
14+ elif [ " ${OMIT_API_BUILDS+x} " != " x" ]; then
15+ OMIT_API_BUILDS=" $DEFAULT_OMIT_API_BUILDS "
16+ fi
1017
1118# Ensure out exists and is writable
1219mkdir -p " $OUT_DIR "
@@ -34,6 +41,84 @@ check_mounts() {
3441# Helper: log
3542log () { printf ' \033[1;34m[build]\033[0m %s\n' " $* " ; }
3643
44+ trim () {
45+ local value=" $* "
46+ value=" ${value# " ${value%% [![:space:]]* } " } "
47+ value=" ${value% " ${value##* [![:space:]]} " } "
48+ printf ' %s' " $value "
49+ }
50+
51+ extract_npm_bundle () {
52+ local zip_file=" $1 "
53+ local target_dir=" $2 "
54+
55+ mkdir -p " $target_dir "
56+ find " $target_dir " -mindepth 1 -maxdepth 1 -exec rm -rf {} +
57+ unzip -q -o " $zip_file " -d " $target_dir "
58+
59+ shopt -s nullglob
60+ local entries=(" $target_dir " /* )
61+ if [ " ${# entries[@]} " -eq 1 ] && [ -d " ${entries[0]} " ]; then
62+ log " Zip contained top-level dir: moving contents up"
63+ mv " ${entries[0]} " /* " $target_dir " / || true
64+ rmdir " ${entries[0]} " || true
65+ fi
66+ shopt -u nullglob
67+ }
68+
69+ copy_if_exists () {
70+ local source_file=" $1 "
71+ local target_file=" $2 "
72+
73+ if [ -f " $source_file " ]; then
74+ cp -f " $source_file " " $target_file "
75+ fi
76+ }
77+
78+ install_variant_artifacts () {
79+ local variant=" $1 "
80+ local extracted_dir=" $2 "
81+
82+ log " Installing bundler-friendly variant artifacts for: $variant "
83+ copy_if_exists " $extracted_dir /sqlite3-bundler-friendly.mjs" " /src/bin/sqlite3-${variant} -bundler-friendly.mjs"
84+ }
85+
86+ create_variant_zip () {
87+ local variant=" $1 "
88+ local zip_file=" $2 "
89+ local staging_dir=" /tmp/sqlite-wasm-variant-${variant} "
90+
91+ rm -rf " $staging_dir "
92+ mkdir -p " $staging_dir "
93+ cp -f " /src/bin/sqlite3-${variant} -bundler-friendly.mjs" " $staging_dir /"
94+
95+ rm -f " $zip_file "
96+ (cd " $staging_dir " && zip -q -r " $zip_file " .)
97+ chmod a+r " $zip_file "
98+ }
99+
100+ build_npm_bundle () {
101+ local label=" $1 "
102+ local omit_apis=" $2 "
103+
104+ log " Running make clean for $label "
105+ make clean > /dev/null 2>&1 || true
106+ rm -f npm-bundle.zip
107+
108+ if [ -n " $omit_apis " ]; then
109+ log " Running make -j4 npm omit-api=\" $omit_apis \" (ext/wasm)"
110+ make -j4 npm omit-api=" $omit_apis "
111+ else
112+ log " Running make -j4 npm (ext/wasm)"
113+ make -j4 npm
114+ fi
115+
116+ if [ ! -f npm-bundle.zip ]; then
117+ log " ERROR: npm-bundle.zip not found in ext/wasm"
118+ exit 3
119+ fi
120+ }
121+
37122# Handle ownership fixup on exit
38123cleanup () {
39124 if [ -n " $HOST_UID " ] && [ -n " $HOST_GID " ]; then
@@ -58,6 +143,7 @@ log "Repo: $SQLITE_REPO"
58143log " Ref: $SQLITE_REF "
59144log " Out: $OUT_DIR "
60145log " Src dir: $SRC_DIR "
146+ log " Omit API builds: ${OMIT_API_BUILDS:- <none>} "
61147
62148# prepare source dir: clone shallow or fetch+reset if exists
63149if [ -d " $SRC_DIR /.git" ]; then
@@ -106,37 +192,54 @@ make sqlite3.c
106192
107193cd ext/wasm
108194
109- log " Running make -j4 npm (ext/wasm)"
110- make -j4 npm
111-
112- # ensure artifact exists
113- if [ ! -f npm-bundle.zip ]; then
114- log " ERROR: npm-bundle.zip not found in ext/wasm"
115- exit 3
195+ if [ -n " ${OMIT_API_BUILDS:- } " ] && ! grep -q ' omit-api' GNUmakefile; then
196+ log " ERROR: omit API builds were requested, but this SQLite ref does not support omit-api."
197+ log " Set SQLITE_WASM_OMIT_API_BUILDS= to build only the full bundle, or use a SQLite ref with omit-api support."
198+ exit 5
116199fi
117200
118- # copy zip into OUT_DIR
201+ build_npm_bundle " full" " "
202+
203+ # copy zip into OUT_DIR and extract the full build into /src/bin
119204log " Copying npm-bundle.zip to $OUT_DIR "
120205cp -f npm-bundle.zip " $OUT_DIR /npm-bundle.zip"
121206chmod a+r " $OUT_DIR /npm-bundle.zip"
122207
123208# extract into /src/bin (normalize single top-level dir)
124209log " Extracting npm-bundle.zip into /src/bin"
125- # Clear existing contents to ensure a clean overwrite
126- rm -rf /src/bin/*
127- mkdir -p /src/bin
128- unzip -q -o " $OUT_DIR /npm-bundle.zip" -d /src/bin
129- rm -f " $OUT_DIR /npm-bundle.zip"
130-
131- # If a single top-level directory exists, move its contents up
132- shopt -s nullglob
133- entries=(/src/bin/* )
134- if [ " ${# entries[@]} " -eq 1 ] && [ -d " ${entries[0]} " ]; then
135- log " Zip contained top-level dir: moving contents up"
136- mv " ${entries[0]} " /* /src/bin/ || true
137- rmdir " ${entries[0]} " || true
210+ extract_npm_bundle " $OUT_DIR /npm-bundle.zip" /src/bin
211+
212+ if [ -n " ${OMIT_API_BUILDS:- } " ]; then
213+ IFS=' ;' read -r -a omit_build_specs <<< " $OMIT_API_BUILDS"
214+ for spec in " ${omit_build_specs[@]} " ; do
215+ spec=" $( trim " $spec " ) "
216+ if [ -z " $spec " ]; then
217+ continue
218+ fi
219+
220+ if [[ " $spec " != * = * ]]; then
221+ log " ERROR: invalid omit API build spec '$spec '. Expected name=api api."
222+ exit 4
223+ fi
224+
225+ variant=" $( trim " ${spec%% =* } " ) "
226+ omit_apis=" $( trim " ${spec#* =} " ) "
227+ if [[ ! " $variant " =~ ^[a-z0-9][a-z0-9-]* $ ]]; then
228+ log " ERROR: invalid variant name '$variant '. Use lowercase letters, numbers, and hyphens."
229+ exit 4
230+ fi
231+
232+ build_npm_bundle " $variant " " $omit_apis "
233+
234+ variant_zip=" $OUT_DIR /npm-bundle-${variant} .zip"
235+ variant_dir=" /tmp/sqlite-wasm-npm-${variant} "
236+ log " Extracting variant bundle for artifact renaming"
237+ extract_npm_bundle npm-bundle.zip " $variant_dir "
238+ install_variant_artifacts " $variant " " $variant_dir "
239+ log " Writing bundler-friendly variant bundle to $variant_zip "
240+ create_variant_zip " $variant " " $variant_zip "
241+ done
138242fi
139- shopt -u nullglob
140243
141244log " Build complete. Extracted contents are in /src/bin"
142245exec /bin/ls -la /src/bin
0 commit comments