1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

wasm minimal build: strip authorizers and JSON support (saves approx 35kb). Strip vtab support from the JS bits but cannot yet strip it from the C bits because that requires a custom-configured sqlite3.c.

FossilOrigin-Name: eb64d106551718467e0f6c6b53695410bf4c566901008e4cda8580d0f7efa7b0
This commit is contained in:
stephan
2024-07-24 23:58:28 +00:00
parent fe225745fc
commit b16c2980b3
10 changed files with 153 additions and 81 deletions

View File

@ -244,26 +244,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
}),
'*'
]],
["sqlite3_set_authorizer", "int", [
"sqlite3*",
new wasm.xWrap.FuncPtrAdapter({
name: "sqlite3_set_authorizer::xAuth",
signature: "i(pi"+"ssss)",
contextKey: (argv, argIndex)=>argv[0/*(sqlite3*)*/],
callProxy: (callback)=>{
return (pV, iCode, s0, s1, s2, s3)=>{
try{
s0 = s0 && wasm.cstrToJs(s0); s1 = s1 && wasm.cstrToJs(s1);
s2 = s2 && wasm.cstrToJs(s2); s3 = s3 && wasm.cstrToJs(s3);
return callback(pV, iCode, s0, s1, s2, s3) || 0;
}catch(e){
return e.resultCode || capi.SQLITE_ERROR;
}
}
}
}),
"*"/*pUserData*/
]],
["sqlite3_set_auxdata", undefined, [
"sqlite3_context*", "int", "*",
new wasm.xWrap.FuncPtrAdapter({
@ -278,8 +258,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
["sqlite3_status", "int", "int", "*", "*", "int"],
["sqlite3_step", "int", "sqlite3_stmt*"],
["sqlite3_stmt_busy", "int", "sqlite3_stmt*"],
["sqlite3_stmt_explain", "int", "sqlite3_stmt*", "int"],
["sqlite3_stmt_isexplain", "int", "sqlite3_stmt*"],
["sqlite3_stmt_readonly", "int", "sqlite3_stmt*"],
["sqlite3_stmt_status", "int", "sqlite3_stmt*", "int", "int"],
["sqlite3_strglob", "int", "string","string"],
@ -325,6 +303,38 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
["sqlite3_vfs_unregister", "int", "sqlite3_vfs*"]
]/*wasm.bindingSignatures*/;
if( !!wasm.exports.sqlite3_stmt_explain ){
wasm.bindingSignatures.push(
["sqlite3_stmt_explain", "int", "sqlite3_stmt*", "int"],
["sqlite3_stmt_isexplain", "int", "sqlite3_stmt*"]
);
}
if( !!wasm.exports.sqlite3_set_authorizer ){
wasm.bindingSignatures.push(
["sqlite3_set_authorizer", "int", [
"sqlite3*",
new wasm.xWrap.FuncPtrAdapter({
name: "sqlite3_set_authorizer::xAuth",
signature: "i(pi"+"ssss)",
contextKey: (argv, argIndex)=>argv[0/*(sqlite3*)*/],
callProxy: (callback)=>{
return (pV, iCode, s0, s1, s2, s3)=>{
try{
s0 = s0 && wasm.cstrToJs(s0); s1 = s1 && wasm.cstrToJs(s1);
s2 = s2 && wasm.cstrToJs(s2); s3 = s3 && wasm.cstrToJs(s3);
return callback(pV, iCode, s0, s1, s2, s3) || 0;
}catch(e){
return e.resultCode || capi.SQLITE_ERROR;
}
}
}
}),
"*"/*pUserData*/
]]
);
}/* sqlite3_set_authorizer() */
if(false && wasm.compileOptionUsed('SQLITE_ENABLE_NORMALIZE')){
/* ^^^ "the problem" is that this is an option feature and the
build-time function-export list does not currently take
@ -367,11 +377,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
["sqlite3_bind_int64","int", ["sqlite3_stmt*", "int", "i64"]],
["sqlite3_changes64","i64", ["sqlite3*"]],
["sqlite3_column_int64","i64", ["sqlite3_stmt*", "int"]],
["sqlite3_create_module", "int",
["sqlite3*","string","sqlite3_module*","*"]],
["sqlite3_create_module_v2", "int",
["sqlite3*","string","sqlite3_module*","*","*"]],
["sqlite3_declare_vtab", "int", ["sqlite3*", "string:flexible"]],
["sqlite3_deserialize", "int", "sqlite3*", "string", "*", "i64", "i64", "int"]
/* Careful! Short version: de/serialize() are problematic because they
might use a different allocator than the user for managing the
@ -407,19 +412,29 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
"*"
]],
["sqlite3_uri_int64", "i64", ["sqlite3_filename", "string", "i64"]],
["sqlite3_value_int64","i64", "sqlite3_value*"],
["sqlite3_vtab_collation","string","sqlite3_index_info*","int"],
["sqlite3_vtab_distinct","int", "sqlite3_index_info*"],
["sqlite3_vtab_in","int", "sqlite3_index_info*", "int", "int"],
["sqlite3_vtab_in_first", "int", "sqlite3_value*", "**"],
["sqlite3_vtab_in_next", "int", "sqlite3_value*", "**"],
/*["sqlite3_vtab_config" is variadic and requires a hand-written
proxy.] */
["sqlite3_vtab_nochange","int", "sqlite3_context*"],
["sqlite3_vtab_on_conflict","int", "sqlite3*"],
["sqlite3_vtab_rhs_value","int", "sqlite3_index_info*", "int", "**"]
["sqlite3_value_int64","i64", "sqlite3_value*"]
];
if( wasm.bigIntEnabled && !!wasm.exports.sqlite3_declare_vtab ){
wasm.bindingSignatures.int64.push(
["sqlite3_create_module", "int",
["sqlite3*","string","sqlite3_module*","*"]],
["sqlite3_create_module_v2", "int",
["sqlite3*","string","sqlite3_module*","*","*"]],
["sqlite3_declare_vtab", "int", ["sqlite3*", "string:flexible"]],
["sqlite3_vtab_collation","string","sqlite3_index_info*","int"],
["sqlite3_vtab_distinct","int", "sqlite3_index_info*"],
["sqlite3_vtab_in","int", "sqlite3_index_info*", "int", "int"],
["sqlite3_vtab_in_first", "int", "sqlite3_value*", "**"],
["sqlite3_vtab_in_next", "int", "sqlite3_value*", "**"],
/*["sqlite3_vtab_config" is variadic and requires a hand-written
proxy.] */
["sqlite3_vtab_nochange","int", "sqlite3_context*"],
["sqlite3_vtab_on_conflict","int", "sqlite3*"],
["sqlite3_vtab_rhs_value","int", "sqlite3_index_info*", "int", "**"]
);
}/* virtual table APIs */
if(wasm.bigIntEnabled && !!wasm.exports.sqlite3_preupdate_hook){
wasm.bindingSignatures.int64.push(
["sqlite3_preupdate_blobwrite", "int", "sqlite3*"],
@ -725,12 +740,6 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
('sqlite3*', (v)=>
__xArgPtr((v instanceof (sqlite3?.oo1?.DB || nilType))
? v.pointer : v))
('sqlite3_index_info*', (v)=>
__xArgPtr((v instanceof (capi.sqlite3_index_info || nilType))
? v.pointer : v))
('sqlite3_module*', (v)=>
__xArgPtr((v instanceof (capi.sqlite3_module || nilType))
? v.pointer : v))
/**
`sqlite3_vfs*`:
@ -753,6 +762,15 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
return __xArgPtr((v instanceof (capi.sqlite3_vfs || nilType))
? v.pointer : v);
});
if( wasm.exports.sqlite3_declare_vtab ){
wasm.xWrap.argAdapter('sqlite3_index_info*', (v)=>
__xArgPtr((v instanceof (capi.sqlite3_index_info || nilType))
? v.pointer : v))
('sqlite3_module*', (v)=>
__xArgPtr((v instanceof (capi.sqlite3_module || nilType))
? v.pointer : v)
);
}
const __xRcPtr = wasm.xWrap.resultAdapter('*');
wasm.xWrap.resultAdapter('sqlite3*', __xRcPtr)
@ -1031,12 +1049,16 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
'sqlite3_update_hook'
]) {
const x = wasm.exports[name];
if( !x ){
/* assume it was built without this API */
continue;
}
closeArgs.length = x.length/*==argument count*/
/* recall that undefined entries translate to 0 when passed to
WASM. */;
try{ capi[name](...closeArgs) }
catch(e){
console.warn("close-time call of",name+"(",closeArgs,") threw:",e);
sqlite3.config.warn("close-time call of",name+"(",closeArgs,") threw:",e);
}
}
const m = __dbCleanupMap(pDb, 0);