Skip to content

Commit b2800e8

Browse files
Fix SQLite 3.51.3 libSQL compatibility targets
Restore libSQL Makefile targets on top of SQLite autosetup and carry forward reserved-byte, bundled artifact, Tcl harness, encrypted replication, vector VACUUM, FLOAT8 padding, integrity-check, WAL restart harness, and extension CI compatibility fixes.
1 parent e4ef854 commit b2800e8

21 files changed

Lines changed: 3154 additions & 56 deletions

File tree

libsql-ffi/bundled/SQLite3MultipleCiphers/src/sqlite3.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
** Makefile.in
2626
** Makefile.msc
2727
** README.md
28+
** auto.def
29+
** autosetup/sqlite-config.tcl
2830
** doc/trusted-schema.md
2931
** doc/vdbesort-memory.md
3032
** doc/wal-lock.md
@@ -72,8 +74,11 @@
7274
** src/where.c
7375
** src/wherecode.c
7476
** test/all.test
77+
** test/e_reindex.test
7578
** test/json/README.md
79+
** test/pragma.test
7680
** test/rowvaluevtab.test
81+
** test/walrestart.test
7782
** tool/mkkeywordhash.c
7883
** tool/mksqlite3c-noext.tcl
7984
** tool/mksqlite3c.tcl
@@ -76705,7 +76710,7 @@ SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve,
7670576710
BtShared *pBt = p->pBt;
7670676711
assert( nReserve>=0 && nReserve<=255 );
7670776712
sqlite3BtreeEnter(p);
76708-
pBt->nReserveWanted = (u8)nReserve;
76713+
pBt->nReserveWanted = nReserve;
7670976714
x = pBt->pageSize - pBt->usableSize;
7671076715
if( x==nReserve && (pageSize==0 || (u32)pageSize==pBt->pageSize) ){
7671176716
sqlite3BtreeLeave(p);
@@ -147068,6 +147073,10 @@ SQLITE_PRIVATE void sqlite3Pragma(
147068147073
}
147069147074
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
147070147075
if( pIdx->pPartIdxWhere==0 ){
147076+
if( IsVectorIndex(pIdx) ){
147077+
cnt++;
147078+
continue;
147079+
}
147071147080
addr = sqlite3VdbeAddOp3(v, OP_Eq, 8+cnt, 0, 8+iTab);
147072147081
VdbeCoverageNeverNull(v);
147073147082
sqlite3VdbeLoadString(v, 4, pIdx->zName);
@@ -162326,19 +162335,23 @@ SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3RunVacuum(
162326162335
// so we must skip them at this step
162327162336
if( sqlite3FindTable(db, VECTOR_INDEX_GLOBAL_META_TABLE, zDbMain) != NULL ){
162328162337
rc = execSqlF(db, pzErrMsg,
162329-
"SELECT'INSERT INTO vacuum_db.'||quote(name)"
162338+
"SELECT'INSERT INTO %s.'||quote(name)"
162330162339
"||' SELECT*FROM\"%w\".'||quote(name)"
162331-
"FROM vacuum_db.sqlite_schema "
162340+
"FROM %s.sqlite_schema "
162332162341
"WHERE type='table'AND coalesce(rootpage,1)>0 AND name NOT IN (SELECT name||'_shadow' FROM " VECTOR_INDEX_GLOBAL_META_TABLE ")",
162333-
zDbMain
162342+
zDbVacuum,
162343+
zDbMain,
162344+
zDbVacuum
162334162345
);
162335162346
}else{
162336162347
rc = execSqlF(db, pzErrMsg,
162337-
"SELECT'INSERT INTO vacuum_db.'||quote(name)"
162348+
"SELECT'INSERT INTO %s.'||quote(name)"
162338162349
"||' SELECT*FROM\"%w\".'||quote(name)"
162339-
"FROM vacuum_db.sqlite_schema "
162350+
"FROM %s.sqlite_schema "
162340162351
"WHERE type='table'AND coalesce(rootpage,1)>0",
162341-
zDbMain
162352+
zDbVacuum,
162353+
zDbMain,
162354+
zDbVacuum
162342162355
);
162343162356
}
162344162357
#else
@@ -219761,6 +219774,7 @@ static void vectorConvertToF8(const Vector *pFrom, Vector *pTo){
219761219774
assert( pTo->type == VECTOR_TYPE_FLOAT8 );
219762219775

219763219776
dst = pTo->data;
219777+
memset(dst, 0, ALIGN(pTo->dims, sizeof(float)));
219764219778
if( pFrom->type == VECTOR_TYPE_FLOAT32 ){
219765219779
srcF32 = pFrom->data;
219766219780
for(i = 0; i < pFrom->dims; i++){
@@ -222498,11 +222512,14 @@ void vectorF8SerializeToBlob(
222498222512
size_t nBlobSize
222499222513
){
222500222514
float alpha, shift;
222515+
size_t nPayload;
222501222516

222502222517
assert( pVector->type == VECTOR_TYPE_FLOAT8 );
222503222518
assert( pVector->dims <= MAX_VECTOR_SZ );
222504222519
assert( nBlobSize >= vectorDataSize(pVector->type, pVector->dims) );
222505222520

222521+
nPayload = ALIGN(pVector->dims, sizeof(float));
222522+
memset(pBlob, 0, nPayload);
222506222523
memcpy(pBlob, pVector->data, pVector->dims);
222507222524

222508222525
vectorF8GetParameters(pVector->data, pVector->dims, &alpha, &shift);

libsql-ffi/bundled/src/sqlite3.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
** Makefile.in
2626
** Makefile.msc
2727
** README.md
28+
** auto.def
29+
** autosetup/sqlite-config.tcl
2830
** doc/trusted-schema.md
2931
** doc/vdbesort-memory.md
3032
** doc/wal-lock.md
@@ -72,8 +74,11 @@
7274
** src/where.c
7375
** src/wherecode.c
7476
** test/all.test
77+
** test/e_reindex.test
7578
** test/json/README.md
79+
** test/pragma.test
7680
** test/rowvaluevtab.test
81+
** test/walrestart.test
7782
** tool/mkkeywordhash.c
7883
** tool/mksqlite3c-noext.tcl
7984
** tool/mksqlite3c.tcl
@@ -76705,7 +76710,7 @@ SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve,
7670576710
BtShared *pBt = p->pBt;
7670676711
assert( nReserve>=0 && nReserve<=255 );
7670776712
sqlite3BtreeEnter(p);
76708-
pBt->nReserveWanted = (u8)nReserve;
76713+
pBt->nReserveWanted = nReserve;
7670976714
x = pBt->pageSize - pBt->usableSize;
7671076715
if( x==nReserve && (pageSize==0 || (u32)pageSize==pBt->pageSize) ){
7671176716
sqlite3BtreeLeave(p);
@@ -147068,6 +147073,10 @@ SQLITE_PRIVATE void sqlite3Pragma(
147068147073
}
147069147074
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
147070147075
if( pIdx->pPartIdxWhere==0 ){
147076+
if( IsVectorIndex(pIdx) ){
147077+
cnt++;
147078+
continue;
147079+
}
147071147080
addr = sqlite3VdbeAddOp3(v, OP_Eq, 8+cnt, 0, 8+iTab);
147072147081
VdbeCoverageNeverNull(v);
147073147082
sqlite3VdbeLoadString(v, 4, pIdx->zName);
@@ -162326,19 +162335,23 @@ SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3RunVacuum(
162326162335
// so we must skip them at this step
162327162336
if( sqlite3FindTable(db, VECTOR_INDEX_GLOBAL_META_TABLE, zDbMain) != NULL ){
162328162337
rc = execSqlF(db, pzErrMsg,
162329-
"SELECT'INSERT INTO vacuum_db.'||quote(name)"
162338+
"SELECT'INSERT INTO %s.'||quote(name)"
162330162339
"||' SELECT*FROM\"%w\".'||quote(name)"
162331-
"FROM vacuum_db.sqlite_schema "
162340+
"FROM %s.sqlite_schema "
162332162341
"WHERE type='table'AND coalesce(rootpage,1)>0 AND name NOT IN (SELECT name||'_shadow' FROM " VECTOR_INDEX_GLOBAL_META_TABLE ")",
162333-
zDbMain
162342+
zDbVacuum,
162343+
zDbMain,
162344+
zDbVacuum
162334162345
);
162335162346
}else{
162336162347
rc = execSqlF(db, pzErrMsg,
162337-
"SELECT'INSERT INTO vacuum_db.'||quote(name)"
162348+
"SELECT'INSERT INTO %s.'||quote(name)"
162338162349
"||' SELECT*FROM\"%w\".'||quote(name)"
162339-
"FROM vacuum_db.sqlite_schema "
162350+
"FROM %s.sqlite_schema "
162340162351
"WHERE type='table'AND coalesce(rootpage,1)>0",
162341-
zDbMain
162352+
zDbVacuum,
162353+
zDbMain,
162354+
zDbVacuum
162342162355
);
162343162356
}
162344162357
#else
@@ -219761,6 +219774,7 @@ static void vectorConvertToF8(const Vector *pFrom, Vector *pTo){
219761219774
assert( pTo->type == VECTOR_TYPE_FLOAT8 );
219762219775

219763219776
dst = pTo->data;
219777+
memset(dst, 0, ALIGN(pTo->dims, sizeof(float)));
219764219778
if( pFrom->type == VECTOR_TYPE_FLOAT32 ){
219765219779
srcF32 = pFrom->data;
219766219780
for(i = 0; i < pFrom->dims; i++){
@@ -222498,11 +222512,14 @@ void vectorF8SerializeToBlob(
222498222512
size_t nBlobSize
222499222513
){
222500222514
float alpha, shift;
222515+
size_t nPayload;
222501222516

222502222517
assert( pVector->type == VECTOR_TYPE_FLOAT8 );
222503222518
assert( pVector->dims <= MAX_VECTOR_SZ );
222504222519
assert( nBlobSize >= vectorDataSize(pVector->type, pVector->dims) );
222505222520

222521+
nPayload = ALIGN(pVector->dims, sizeof(float));
222522+
memset(pBlob, 0, nPayload);
222506222523
memcpy(pBlob, pVector->data, pVector->dims);
222507222524

222508222525
vectorF8GetParameters(pVector->data, pVector->dims, &alpha, &shift);

libsql-replication/src/injector/sqlite_injector/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,4 +348,18 @@ mod test {
348348
conn.query_row("SELECT COUNT(*) FROM test", (), |_| Ok(()))
349349
.unwrap();
350350
}
351+
352+
#[cfg(feature = "encryption")]
353+
#[test]
354+
fn test_encrypted_injector_reopens_connection() {
355+
let temp = tempfile::tempdir().unwrap();
356+
let cfg = libsql_sys::EncryptionConfig::new(
357+
libsql_sys::Cipher::Aes256Cbc,
358+
"SuperSecretKey".into(),
359+
);
360+
let mut injector =
361+
SqliteInjectorInner::new(temp.path().join("data"), 10, 10000, Some(cfg)).unwrap();
362+
363+
injector.begin_txn().unwrap();
364+
}
351365
}

libsql-sqlite3/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ sqltclsh.c
5858
srcck1
5959
test-out.txt
6060
/test/rust_suite/target
61-
/test/rust_suite/Cargo.lock
6261
testfixture
6362
libsql
6463
/src-verify

libsql-sqlite3/Makefile.in

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ CFLAGS.fuzzcheck-asan.fsanitize = @CFLAGS_ASAN_FSANITIZE@
132132

133133
# Is the optional WebAssembly runtime library enabled?
134134
#
135-
OPT_WASM_RUNTIME ?= n
135+
OPT_WASM_RUNTIME ?= @OPT_WASM_RUNTIME@
136136
#
137137
# Intended to either be empty or be set to -g -DSQLITE_DEBUG=1.
138138
#
@@ -364,3 +364,93 @@ version-info$(T.exe): $(TOP)/tool/version-info.c Makefile sqlite3.h
364364
$(T.link) $(ST_OPT) -o $@ $(TOP)/tool/version-info.c
365365

366366
include $(TOP)/main.mk
367+
368+
########################################################################
369+
# libSQL compatibility targets. SQLite 3.48+ switched the canonical
370+
# build to autosetup and dropped the legacy libtool-based target names
371+
# that libSQL workflows still consume. Keep the old public make
372+
# surface as aliases around the new SQLite build products.
373+
374+
APITOP = $(TOP)/crates
375+
WBTOP = $(TOP)/crates/wasmtime-bindings
376+
377+
liblibsql.DLL = liblibsql$(T.dll)
378+
liblibsql.LIB = liblibsql$(T.lib)
379+
380+
ifeq ($(OPT_WASM_RUNTIME),y)
381+
OPT_WASM_RUNTIME_LIBRARY_TARGET = liblibsql_wasm
382+
OPT_WASM_RUNTIME_INSTALL_TARGET = liblibsql_wasm_install
383+
OPT_STATIC_LIBLIBSQL_WASM = $(TOP)/.libs/liblibsql_wasm.a
384+
else ifeq ($(OPT_WASM_RUNTIME),d)
385+
OPT_WASM_RUNTIME_LIBRARY_TARGET = liblibsql_wasm
386+
OPT_WASM_RUNTIME_INSTALL_TARGET = liblibsql_wasm_install
387+
OPT_STATIC_LIBLIBSQL_WASM =
388+
LDFLAGS.libsqlite3 += -L$(WBTOP)/../target/release -llibsql_wasm
389+
else ifeq ($(OPT_WASM_RUNTIME),wasmedge)
390+
OPT_WASM_RUNTIME_LIBRARY_TARGET =
391+
OPT_WASM_RUNTIME_INSTALL_TARGET =
392+
OPT_STATIC_LIBLIBSQL_WASM =
393+
LDFLAGS.libsqlite3 += -lwasmedge
394+
else
395+
OPT_WASM_RUNTIME_LIBRARY_TARGET =
396+
OPT_WASM_RUNTIME_INSTALL_TARGET =
397+
OPT_STATIC_LIBLIBSQL_WASM =
398+
endif
399+
400+
sqlite3$(T.exe): $(OPT_WASM_RUNTIME_LIBRARY_TARGET)
401+
$(libsqlite3.DLL) $(libsqlite3.LIB): $(OPT_WASM_RUNTIME_LIBRARY_TARGET)
402+
403+
libsql$(T.exe): sqlite3$(T.exe)
404+
cp sqlite3$(T.exe) libsql$(T.exe)
405+
406+
all: libsql$(T.exe)
407+
408+
$(liblibsql.LIB): $(libsqlite3.LIB)
409+
cp $(libsqlite3.LIB) $(liblibsql.LIB)
410+
mkdir -p .libs
411+
cp $(liblibsql.LIB) .libs/$(liblibsql.LIB)
412+
cp $(libsqlite3.LIB) .libs/$(libsqlite3.LIB)
413+
$(liblibsql.LIB)-1: $(liblibsql.LIB)
414+
$(liblibsql.LIB)-0 $(liblibsql.LIB)-:
415+
416+
$(liblibsql.DLL): $(libsqlite3.DLL)
417+
cp $(libsqlite3.DLL) $(liblibsql.DLL)
418+
mkdir -p .libs
419+
cp $(liblibsql.DLL) .libs/$(liblibsql.DLL)
420+
cp $(libsqlite3.DLL) .libs/$(libsqlite3.DLL)
421+
$(liblibsql.DLL)-1: $(liblibsql.DLL)
422+
$(liblibsql.DLL)-0 $(liblibsql.DLL)-:
423+
424+
liblibsql_wasm:
425+
cd $(WBTOP) && cargo build --release --lib
426+
mkdir -p $(TOP)/.libs
427+
cp $(WBTOP)/../target/release/liblibsql_wasm.* $(TOP)/.libs/
428+
429+
liblibsql_wasm_install: liblibsql_wasm $(install-dir.lib)
430+
if [ -f "$(WBTOP)/../target/release/liblibsql_wasm.so" ]; then \
431+
$(INSTALL.noexec) "$(WBTOP)/../target/release/liblibsql_wasm.so" "$(install-dir.lib)/liblibsql_wasm.so.0.0"; \
432+
ln -fs liblibsql_wasm.so.0.0 "$(install-dir.lib)/liblibsql_wasm.so.0"; \
433+
ln -fs liblibsql_wasm.so.0.0 "$(install-dir.lib)/liblibsql_wasm.so"; \
434+
fi
435+
if [ -f "$(WBTOP)/../target/release/liblibsql_wasm.a" ]; then \
436+
$(INSTALL.noexec) "$(WBTOP)/../target/release/liblibsql_wasm.a" "$(install-dir.lib)/liblibsql_wasm.a"; \
437+
fi
438+
439+
liblibsql_install: $(install-dir.lib) \
440+
$(liblibsql.LIB)-$(ENABLE_LIB_STATIC) \
441+
$(liblibsql.DLL)-$(ENABLE_LIB_SHARED) \
442+
$(OPT_WASM_RUNTIME_INSTALL_TARGET)
443+
if [ -f "$(liblibsql.LIB)" ]; then \
444+
$(INSTALL.noexec) "$(liblibsql.LIB)" "$(install-dir.lib)"; \
445+
fi
446+
if [ -f "$(liblibsql.DLL)" ]; then \
447+
$(INSTALL) "$(liblibsql.DLL)" "$(install-dir.lib)"; \
448+
fi
449+
450+
rusttest: sqlite3.h $(liblibsql.LIB)
451+
( cd test/rust_suite; SQLITE3_STATIC=1 SQLITE3_INCLUDE_DIR=$(TOP) \
452+
LD_LIBRARY_PATH=$(TOP):$(TOP)/.libs SQLITE3_LIB_DIR=$(TOP) cargo test )
453+
454+
rusttestwasm: sqlite3.h $(liblibsql.LIB) liblibsql_wasm
455+
( cd test/rust_suite; SQLITE3_STATIC=1 SQLITE3_INCLUDE_DIR=$(TOP) \
456+
LD_LIBRARY_PATH=$(TOP):$(TOP)/.libs SQLITE3_LIB_DIR=$(TOP) cargo test --features wasm,udf )

libsql-sqlite3/auto.def

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@ sqlite-configure canonical {
5858

5959
sqlite-handle-tcl
6060
sqlite-handle-emsdk
61+
define OPT_WASM_RUNTIME n
62+
if {
63+
[proj-opt-truthy wasm-runtime]
64+
|| [proj-opt-truthy wasm-runtime-dynamic]
65+
|| [proj-opt-truthy wasm-runtime-wasmedge]
66+
} {
67+
sqlite-add-feature-flag -DLIBSQL_ENABLE_WASM_RUNTIME
68+
if {[proj-opt-truthy wasm-runtime-dynamic]} {
69+
define OPT_WASM_RUNTIME d
70+
} elseif {[proj-opt-truthy wasm-runtime-wasmedge]} {
71+
sqlite-add-feature-flag -DLIBSQL_ENABLE_WASM_RUNTIME_WASMEDGE
72+
define OPT_WASM_RUNTIME wasmedge
73+
} else {
74+
define OPT_WASM_RUNTIME y
75+
}
76+
}
6177

6278
proj-if-opt-truthy static-shells {
6379
proj-opt-set static-tclsqlite3 1

libsql-sqlite3/autosetup/sqlite-config.tcl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ proc sqlite-configure {buildMode configScript} {
216216
fts3 => {Enable the FTS3 extension}
217217
fts4 => {Enable the FTS4 extension}
218218
fts5 => {Enable the FTS5 extension}
219+
wasm-runtime => {Enable libSQL WebAssembly runtime integration}
220+
wasm-runtime-dynamic => {Link libSQL WebAssembly runtime dynamically}
221+
wasm-runtime-wasmedge
222+
=> {Enable libSQL WebAssembly runtime integration using WasmEdge}
219223
update-limit => {Enable the UPDATE/DELETE LIMIT clause}
220224
geopoly => {Enable the GEOPOLY extension}
221225
rtree => {Enable the RTREE extension}

libsql-sqlite3/ext/crr/rs/integration_check/src/t/tableinfo.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,17 +328,16 @@ fn test_leak_condition() {
328328
// updating schemas prepares stements
329329
// re-pulling table infos should finalize those statements
330330
let c1w = crate::opendb_file("test_leak_condition").expect("Opened DB");
331-
let c2w = crate::opendb_file("test_leak_condition").expect("Opened DB");
332331

333332
let c1 = &c1w.db;
334-
let c2 = &c2w.db;
335333

336-
c1.exec_safe(
337-
"DROP TABLE IF EXISTS foo;
338-
DROP TABLE IF EXISTS bar;
339-
VACUUM;",
340-
)
341-
.expect("reset db");
334+
c1.exec_safe("DROP TABLE IF EXISTS foo")
335+
.expect("dropped foo");
336+
c1.exec_safe("DROP TABLE IF EXISTS bar")
337+
.expect("dropped bar");
338+
339+
let c2w = crate::opendb_file("test_leak_condition").expect("Opened DB");
340+
let c2 = &c2w.db;
342341

343342
c1.exec_safe("CREATE TABLE foo (a not null, b not null, primary key (a, b));")
344343
.expect("made foo");

libsql-sqlite3/src/btree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3073,7 +3073,7 @@ int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve, int iFix){
30733073
BtShared *pBt = p->pBt;
30743074
assert( nReserve>=0 && nReserve<=255 );
30753075
sqlite3BtreeEnter(p);
3076-
pBt->nReserveWanted = (u8)nReserve;
3076+
pBt->nReserveWanted = nReserve;
30773077
x = pBt->pageSize - pBt->usableSize;
30783078
if( x==nReserve && (pageSize==0 || (u32)pageSize==pBt->pageSize) ){
30793079
sqlite3BtreeLeave(p);

libsql-sqlite3/src/pragma.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,6 +1817,10 @@ void sqlite3Pragma(
18171817
}
18181818
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
18191819
if( pIdx->pPartIdxWhere==0 ){
1820+
if( IsVectorIndex(pIdx) ){
1821+
cnt++;
1822+
continue;
1823+
}
18201824
addr = sqlite3VdbeAddOp3(v, OP_Eq, 8+cnt, 0, 8+iTab);
18211825
VdbeCoverageNeverNull(v);
18221826
sqlite3VdbeLoadString(v, 4, pIdx->zName);

0 commit comments

Comments
 (0)