mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-06 18:18:53 +08:00
* Proof-of-concept pre-built custom sql.js * Rewrite Makefile as a couple of comprehensible Python scripts * Add link to a blog post about transitive closure in SQLite * Remove eval extension -- no much point as it only returns a string * Consistently use existing Path objects * Add basic tests scalar functions from extension-functions.c * Test presence of functions from the rest of built extensions * Use the same sqlite.com domain * Add a couple SQLite compile flags that may make it a bit faster * Add regexpi function test * Add node about regexpi and REGEXP operator * Workaround first build failure, rebuild lock file and minor fixes
84 lines
2.2 KiB
Python
84 lines
2.2 KiB
Python
import logging
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
|
|
cflags = (
|
|
'-O2',
|
|
'-DSQLITE_OMIT_LOAD_EXTENSION',
|
|
'-DSQLITE_DISABLE_LFS',
|
|
'-DSQLITE_ENABLE_FTS3',
|
|
'-DSQLITE_ENABLE_FTS3_PARENTHESIS',
|
|
'-DSQLITE_ENABLE_FTS5',
|
|
'-DSQLITE_ENABLE_JSON1',
|
|
'-DSQLITE_THREADSAFE=0',
|
|
'-DSQLITE_ENABLE_NORMALIZE',
|
|
'-DSQLITE_EXTRA_INIT=extra_init',
|
|
'-DSQLITE_DEFAULT_MEMSTATUS=0',
|
|
'-DSQLITE_USE_ALLOCA',
|
|
)
|
|
emflags = (
|
|
# Base
|
|
'--memory-init-file', '0',
|
|
'-s', 'RESERVED_FUNCTION_POINTERS=64',
|
|
'-s', 'ALLOW_TABLE_GROWTH=1',
|
|
'-s', 'SINGLE_FILE=0',
|
|
# WASM
|
|
'-s', 'WASM=1',
|
|
'-s', 'ALLOW_MEMORY_GROWTH=1',
|
|
# Optimisation
|
|
'-s', 'INLINING_LIMIT=50',
|
|
'-O3',
|
|
'-flto',
|
|
'--closure', '1',
|
|
# sql.js
|
|
'-s', 'EXPORTED_FUNCTIONS=@src/sqljs/exported_functions.json',
|
|
'-s', 'EXPORTED_RUNTIME_METHODS=@src/sqljs/exported_runtime_methods.json',
|
|
'--pre-js', 'src/sqljs/api.js',
|
|
)
|
|
|
|
|
|
def build(src: Path, dst: Path):
|
|
out = Path('out')
|
|
out.mkdir()
|
|
|
|
logging.info('Building LLVM bitcode for sqlite3.c')
|
|
subprocess.check_call([
|
|
'emcc',
|
|
*cflags,
|
|
'-c', src / 'sqlite3.c',
|
|
'-o', out / 'sqlite3.bc',
|
|
])
|
|
logging.info('Building LLVM bitcode for extension-functions.c')
|
|
subprocess.check_call([
|
|
'emcc',
|
|
*cflags,
|
|
'-c', src / 'extension-functions.c',
|
|
'-o', out / 'extension-functions.bc',
|
|
])
|
|
|
|
logging.info('Building WASM from bitcode')
|
|
subprocess.check_call([
|
|
'emcc',
|
|
*emflags,
|
|
out / 'sqlite3.bc',
|
|
out / 'extension-functions.bc',
|
|
'-o', out / 'sql-wasm.js',
|
|
])
|
|
|
|
logging.info('Post-processing build and copying to dist')
|
|
(out / 'sql-wasm.wasm').rename(dst / 'sql-wasm.wasm')
|
|
with (dst / 'sql-wasm.js').open('w') as f:
|
|
f.write((src / 'sqljs' / 'shell-pre.js').read_text())
|
|
f.write((out / 'sql-wasm.js').read_text())
|
|
f.write((src / 'sqljs' / 'shell-post.js').read_text())
|
|
|
|
|
|
if __name__ == '__main__':
|
|
logging.basicConfig(level='INFO', format='%(asctime)s %(levelname)s %(name)s %(message)s')
|
|
|
|
src = Path('src')
|
|
dst = Path('dist')
|
|
dst.mkdir()
|
|
build(src, dst)
|