diff --git a/ext/wasm/GNUmakefile b/ext/wasm/GNUmakefile index cf0e8b1081..c4c2886da3 100644 --- a/ext/wasm/GNUmakefile +++ b/ext/wasm/GNUmakefile @@ -49,6 +49,7 @@ dir.fiddle := fiddle CLEAN_FILES := *~ $(dir.jacc)/*~ $(dir.api)/*~ $(dir.common)/*~ emcc_enable_bigint ?= 1 sqlite3.c := $(dir.top)/sqlite3.c +sqlite3.h := $(dir.top)/sqlite3.h SQLITE_OPT = \ -DSQLITE_ENABLE_FTS4 \ -DSQLITE_ENABLE_RTREE \ @@ -109,7 +110,7 @@ emcc_opt_full := $(emcc_opt) -g3 ######################################################################## -$(sqlite3.c): +$(sqlite3.c) $(sqlite3.h): $(MAKE) -C $(dir.top) sqlite3.c clean: @@ -130,7 +131,10 @@ EXPORTED_FUNCTIONS.api: $(EXPORTED_FUNCTIONS.api.in) $(MAKEFILE) cat $(EXPORTED_FUNCTIONS.api.in) > $@ CLEAN_FILES += EXPORTED_FUNCTIONS.api -sqlite3-api.jses := $(dir.api)/sqlite3-api-prologue.js +sqlite3-license-version.js := sqlite3-license-version.js +sqlite3-license-version-header.js := $(dir.api)/sqlite3-license-version-header.js +sqlite3-api.jses := $(sqlite3-license-version.js) +sqlite3-api.jses += $(dir.api)/sqlite3-api-prologue.js sqlite3-api.jses += $(dir.common)/whwasmutil.js sqlite3-api.jses += $(dir.jacc)/jaccwabyt.js sqlite3-api.jses += $(dir.api)/sqlite3-api-glue.js @@ -141,6 +145,7 @@ sqlite3-api.jses += $(dir.api)/sqlite3-api-cleanup.js sqlite3-api.js := sqlite3-api.js CLEAN_FILES += $(sqlite3-api.js) +CLEAN_FILES += $(sqlite3-license-version.js) $(sqlite3-api.js): $(sqlite3-api.jses) $(MAKEFILE) @echo "Making $@..." @for i in $(sqlite3-api.jses); do \ @@ -171,9 +176,20 @@ extern-pre-js.js := $(dir.api)/extern-pre-js.js pre-post-common.flags := \ --post-js=$(post-js.js) \ --extern-post-js=$(extern-post-js.js) \ - --extern-pre-js=$(extern-pre-js.js) + --extern-pre-js=$(dir.wasm)/$(sqlite3-license-version.js) pre-post-jses.deps := $(post-js.js) \ - $(extern-post-js.js) $(extern-pre-js.js) + $(extern-post-js.js) $(extern-pre-js.js) $(sqlite3-license-version.js) +$(sqlite3-license-version.js): $(sqlite3.h) $(sqlite3-license-version-header.js) $(MAKEFILE) + @echo "Making $@..."; { \ + cat $(sqlite3-license-version-header.js); \ + echo '/*'; \ + echo '** This code was built from sqlite3 version...'; \ + echo "** "; \ + awk -e '/define SQLITE_VERSION/{$$1=""; print "**" $$0}' \ + -e '/define SQLITE_SOURCE_ID/{$$1=""; print "**" $$0}' $(sqlite3.h); \ + echo '*/'; \ + } > $@ + ######################################################################## # call-make-pre-js creates rules for pre-js-$(1).js. $1 = the base # name of the JS file on whose behalf this pre-js is for. diff --git a/ext/wasm/api/extern-post-js.js b/ext/wasm/api/extern-post-js.js index 5ebb5a31e7..51e8d12b2b 100644 --- a/ext/wasm/api/extern-post-js.js +++ b/ext/wasm/api/extern-post-js.js @@ -1,5 +1,6 @@ /* extern-post-js.js must be appended to the resulting sqlite3.js - file. */ + file. It gets its name from being used as the value for + the --extern-post-js=... Emscripten flag. */ (function(){ /** In order to hide the sqlite3InitModule()'s resulting Emscripten diff --git a/ext/wasm/api/extern-pre-js.js b/ext/wasm/api/extern-pre-js.js index 26d066d2ee..7d47d33e33 100644 --- a/ext/wasm/api/extern-pre-js.js +++ b/ext/wasm/api/extern-pre-js.js @@ -1,4 +1,7 @@ /* extern-pre-js.js must be prepended to the resulting sqlite3.js file. This file is currently only used for holding snippets during test and development. + + It gets its name from being used as the value for the + --extern-pre-js=... Emscripten flag. */ diff --git a/ext/wasm/api/post-js-footer.js b/ext/wasm/api/post-js-footer.js index ee470928ba..58882cbd9c 100644 --- a/ext/wasm/api/post-js-footer.js +++ b/ext/wasm/api/post-js-footer.js @@ -1,3 +1,4 @@ /* The current function scope was opened via post-js-header.js, which - gets prepended to this at build-time. */ + gets prepended to this at build-time. This file closes that + scope. */ })/*postRun.push(...)*/; diff --git a/ext/wasm/api/pre-js.js b/ext/wasm/api/pre-js.js index 502ecf348f..b6630416dd 100644 --- a/ext/wasm/api/pre-js.js +++ b/ext/wasm/api/pre-js.js @@ -1,3 +1,9 @@ +/** + BEGIN FILE: api/pre-js.js + + This file is intended to be prepended to the sqlite3.js build using + Emscripten's --pre-js=THIS_FILE flag (or equivalent). +*/ Module['locateFile'] = function(path, prefix) { return prefix + path; }; @@ -39,3 +45,4 @@ Module[xInstantiateWasm] = function callee(imports,onSuccess){ scripts. */ Module[xInstantiateWasm].uri = 'sqlite3.wasm'; +/* END FILE: api/pre-js.js */ diff --git a/ext/wasm/api/sqlite3-api-cleanup.js b/ext/wasm/api/sqlite3-api-cleanup.js index c2a3425891..555e5d31c5 100644 --- a/ext/wasm/api/sqlite3-api-cleanup.js +++ b/ext/wasm/api/sqlite3-api-cleanup.js @@ -20,17 +20,15 @@ if('undefined' !== typeof Module){ // presumably an Emscripten build /** Install a suitable default configuration for sqlite3ApiBootstrap(). */ - const SABC = self.sqlite3ApiConfig || Object.create(null); - if(undefined===SABC.Module){ - SABC.Module = Module /* ==> Currently needs to be exposed here for - test code. NOT part of the public API. */; - } - if(undefined===SABC.exports){ - SABC.exports = Module['asm']; - } - if(undefined===SABC.memory){ - SABC.memory = Module.wasmMemory /* gets set if built with -sIMPORT_MEMORY */; - } + const SABC = Object.assign( + Object.create(null), { + Module: Module /* ==> Currently needs to be exposed here for + test code. NOT part of the public API. */, + exports: Module['asm'], + memory: Module.wasmMemory /* gets set if built with -sIMPORT_MEMORY */ + }, + self.sqlite3ApiConfig || Object.create(null) + ); /** For current (2022-08-22) purposes, automatically call @@ -38,10 +36,11 @@ if('undefined' !== typeof Module){ // presumably an Emscripten build point, as we really want client code to be able to call this to configure certain parts. Clients may modify self.sqlite3ApiBootstrap.defaultConfig to tweak the default - configuration used by a no-args call to sqlite3ApiBootstrap(). + configuration used by a no-args call to sqlite3ApiBootstrap(), + but must have first loaded their WASM module in order to be + able to provide the necessary configuration state. */ //console.warn("self.sqlite3ApiConfig = ",self.sqlite3ApiConfig); - const rmApiConfig = (SABC !== self.sqlite3ApiConfig); self.sqlite3ApiConfig = SABC; let sqlite3; try{ @@ -51,7 +50,7 @@ if('undefined' !== typeof Module){ // presumably an Emscripten build throw e; }finally{ delete self.sqlite3ApiBootstrap; - if(rmApiConfig) delete self.sqlite3ApiConfig; + delete self.sqlite3ApiConfig; } if(self.location && +self.location.port > 1024){ diff --git a/ext/wasm/api/sqlite3-license-version-header.js b/ext/wasm/api/sqlite3-license-version-header.js new file mode 100644 index 0000000000..f8b3eddc5f --- /dev/null +++ b/ext/wasm/api/sqlite3-license-version-header.js @@ -0,0 +1,25 @@ +/* +** LICENSE for the sqlite3 WebAssembly/JavaScript APIs. +** +** This bundle (typically released as sqlite3.js or sqlite3-wasmfs.js) +** is an amalgamation of JavaScript source code from two projects: +** +** 1) https://emscripten.org: the Emscripten "glue code" is covered by +** the terms of the MIT license and University of Illinois/NCSA +** Open Source License, as described at: +** +** https://emscripten.org/docs/introducing_emscripten/emscripten_license.html +** +** 2) https://sqlite.org: all code and documentation labeled as being +** from this source are released under the same terms as the sqlite3 +** C library: +** +** 2022-10-16 +** +** The author disclaims copyright to this source code. In place of a +** legal notice, here is a blessing: +** +** * May you do good and not evil. +** * May you find forgiveness for yourself and forgive others. +** * May you share freely, never taking more than you give. +*/ diff --git a/ext/wasm/index.html b/ext/wasm/index.html index 01d178bb7a..a7f0974fbe 100644 --- a/ext/wasm/index.html +++ b/ext/wasm/index.html @@ -46,7 +46,7 @@