Skip to content

Commit 71d3faa

Browse files
authored
Merge pull request #10 from davidmartos96/update_from_upstream
Update from upstream
2 parents 5a0d208 + 661eb26 commit 71d3faa

File tree

29 files changed

+353
-147
lines changed

29 files changed

+353
-147
lines changed

.github/actions/build-wasm/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ runs:
4343
working-directory: sqlite3
4444
shell: bash
4545
run: |
46-
cmake -Dwasi_sysroot=/opt/wasi-sysroot -Dclang=/opt/homebrew/opt/llvm@18/bin/clang -S assets/wasm -B .dart_tool/sqlite3_build --toolchain toolchain.cmake
46+
cmake -Dwasi_sysroot=/opt/wasi-sysroot -Dclang=/opt/homebrew/opt/llvm@18/bin/clang -S assets/wasm -B .dart_tool/sqlite3_build
4747
cmake --build .dart_tool/sqlite3_build/ -t output -j

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ jobs:
176176

177177
- name: Web tests
178178
run: |
179-
curl https://storage.googleapis.com/simon-public-euw3/assets/sqlite3/wasm/2.4.3/sqlite3.wasm -o example/web/sqlite3.wasm
179+
curl https://storage.googleapis.com/simon-public-euw3/assets/sqlite3/wasm/2.4.6/sqlite3.wasm -o example/web/sqlite3.wasm
180180
dart test -P web -r expanded
181181
# If browsers behave differently on different platforms, surely that's not our fault...
182182
# So, only run browser tests on Linux to be faster.

integration_tests/sqlcipher_flutter/android/app/build.gradle

+11-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,17 @@ apply plugin: 'kotlin-android'
2626
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
2727

2828
android {
29-
compileSdkVersion 31
29+
compileSdkVersion 34
30+
namespace "com.example.sqlcipher_flutter"
31+
32+
compileOptions {
33+
sourceCompatibility = 1.8
34+
targetCompatibility = 1.8
35+
}
36+
37+
kotlinOptions {
38+
jvmTarget = "1.8"
39+
}
3040

3141
sourceSets {
3242
main.java.srcDirs += 'src/main/kotlin'

integration_tests/sqlcipher_flutter/android/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
buildscript {
2-
ext.kotlin_version = '1.6.10'
2+
ext.kotlin_version = '2.0.10'
33
repositories {
44
google()
55
jcenter()
66
}
77

88
dependencies {
9-
classpath 'com.android.tools.build:gradle:7.0.0'
9+
classpath 'com.android.tools.build:gradle:8.5.0'
1010
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1111
}
1212
}

integration_tests/sqlcipher_flutter/android/gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip

sqlcipher_flutter_libs/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.6.4
2+
3+
- Fix compilation on Android by upgrading `compileSdk` version.
4+
15
## 0.6.3
26

37
- Enable extension loading on Windows and Linux to match the compile options

sqlcipher_flutter_libs/android/build.gradle

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88
}
99

1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:8.0.1'
11+
classpath 'com.android.tools.build:gradle:8.5.1'
1212
}
1313
}
1414

@@ -22,15 +22,14 @@ rootProject.allprojects {
2222
apply plugin: 'com.android.library'
2323

2424
android {
25-
compileSdkVersion 28
26-
2725
// Conditional for compatibility with AGP <4.2.
2826
if (project.android.hasProperty("namespace")) {
2927
namespace 'eu.simonbinder.sqlite3_flutter_libs'
3028
}
3129

3230
defaultConfig {
33-
minSdkVersion 16
31+
minSdkVersion 21
32+
compileSdk 34
3433
}
3534
lintOptions {
3635
disable 'InvalidPackage'

sqlcipher_flutter_libs/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: sqlcipher_flutter_libs
22
description: Flutter plugin to include native SQLCipher libraries in your app
3-
version: 0.6.3
3+
version: 0.6.4
44
homepage: https://github.com/simolus3/sqlite3.dart/tree/main/sqlcipher_flutter_libs
55
issue_tracker: https://github.com/simolus3/sqlite3.dart/issues
66

sqlite3/CHANGELOG.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
## 2.4.6
22

3-
- Fix selecting large integers (being represented as a `BigInt` in Dart)
4-
not working when compiled with dartdevc.
3+
- WebAssembly: Call `_initialize` function of sqlite3 module if one is present.
4+
- Support version 1.0.0 of `package:web`.
55

66
## 2.4.5
77

88
- Fix a bug in the OPFS-locks implementation causing a deadlock when the `xSleep`
99
VFS call is issued.
10+
- Fix selecting large integers (being represented as a `BigInt` in Dart)
11+
not working when compiled with dartdevc.
1012

1113
## 2.4.4
1214

sqlite3/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ With wasi in `/usr/share/wasi-sysroot` and the default clang compiler having the
175175
required builtins, you can setup the build with:
176176

177177
```
178-
cmake -S assets/wasm -B .dart_tool/sqlite3_build --toolchain toolchain.cmake
178+
cmake -S assets/wasm -B .dart_tool/sqlite3_build
179179
```
180180

181181
##### macOS
@@ -196,7 +196,7 @@ Replace `clang/18` with the correct directory if you're using a different versio
196196
Then, set up the build with
197197

198198
```
199-
cmake -Dwasi_sysroot=/opt/wasi-sysroot -Dclang=/opt/homebrew/opt/llvm/bin/clang -S assets/wasm -B .dart_tool/sqlite3_build --toolchain toolchain.cmake
199+
cmake -Dwasi_sysroot=/opt/wasi-sysroot -Dclang=/opt/homebrew/opt/llvm/bin/clang -S assets/wasm -B .dart_tool/sqlite3_build
200200
```
201201

202202
#### Building

sqlite3/assets/wasm/CMakeLists.txt

+80-51
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
1-
cmake_minimum_required(VERSION 3.14)
1+
cmake_minimum_required(VERSION 3.24)
2+
23
set(PROJECT_NAME "sqlite3_web")
34
project(${PROJECT_NAME} LANGUAGES C)
45

6+
set(triple wasm32-unknown-wasi)
7+
set(wasi_sysroot "/usr/share/wasi-sysroot" CACHE PATH "Path to wasi sysroot")
8+
set(clang "clang" CACHE FILEPATH "Path to wasm-capable clang executable")
9+
510
include(FetchContent)
6-
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
7-
# cmake 3.24.0 added the `DOWNLOAD_EXTRACT_TIMESTAMP` and prints an ugly warning when
8-
# the default is used, so override it to the recommended behavior.
9-
# We can't really ask users to use a cmake that recent, so there's this if here.
10-
FetchContent_Declare(
11+
12+
FetchContent_Declare(
1113
sqlite3
12-
URL https://sqlite.org/2023/sqlite-autoconf-3440000.tar.gz
14+
URL https://sqlite.org/2024/sqlite-autoconf-3460000.tar.gz
1315
DOWNLOAD_EXTRACT_TIMESTAMP NEW
14-
)
15-
else()
16-
FetchContent_Declare(
17-
sqlite3
18-
URL https://sqlite.org/2023/sqlite-autoconf-3440000.tar.gz
19-
)
20-
endif()
16+
)
2117

2218
FetchContent_MakeAvailable(sqlite3)
2319

24-
set(wasm_visibility "__attribute__((visibility(\"default\")))")
20+
file(DOWNLOAD https://raw.githubusercontent.com/sqlite/sqlite/master/src/test_vfstrace.c "${CMAKE_BINARY_DIR}/vfstrace.c")
2521

2622
get_filename_component(RS_LIB_DIR "${CMAKE_BINARY_DIR}/../../powersync-sqlite-core/" ABSOLUTE)
2723
set(RS_LIB "powersync")
@@ -31,28 +27,74 @@ set(RS_WASM_TGT_DIR "${RS_LIB_DIR}/target/${RS_WASM_TGT}")
3127
set(RS_RELEASE_OUT "${RS_WASM_TGT_DIR}/wasm/")
3228
set(RS_RELEASE_OUT_DEPS "${RS_WASM_TGT_DIR}/wasm/deps")
3329
set(RS_RELEASE_EXTENSION_OUT "${RS_RELEASE_OUT}/powersync-extension.o")
34-
set(RS_DEBUG_BC "${RS_WASM_TGT_DIR}/debug/deps/${RS_LIB}.bc")
35-
set(RS_BUILD_COMMAND "cargo build -p powersync_loadable --profile wasm --no-default-features --features \"powersync_core/static powersync_core/omit_load_extension sqlite_nostd/static sqlite_nostd/omit_load_extension\" -Z build-std=panic_abort,core,alloc --target ${RS_WASM_TGT}")
3630

37-
file(GLOB BYTECODE_FILES "${RS_WASM_TGT_DIR}/wasm/deps/*.bc")
38-
file(GLOB OBJ_FILES "${RS_WASM_TGT_DIR}/wasm/deps/*.o" CONFIGURE_DEPENDS "*.o")
31+
# Generate symbols we need to export from the sqlite3.wasm build
32+
add_custom_command(
33+
OUTPUT required_symbols.txt
34+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../
35+
COMMAND dart run tool/wasm_symbols.dart ${CMAKE_CURRENT_BINARY_DIR}/required_symbols.txt
36+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../../tool/wasm_symbols.dart
37+
VERBATIM
38+
)
39+
add_custom_target(required_symbols DEPENDS required_symbols.txt)
3940

40-
macro(base_sqlite3_target name)
41-
add_executable(${name}
42-
"${sqlite3_SOURCE_DIR}/sqlite3.c"
43-
os_web.c
44-
helpers.c
45-
)
41+
macro(base_sqlite3_target name debug)
42+
set(clang_output ${name}.clang.wasm)
43+
set(init_output ${name}.init.wasm)
44+
set(output ${init_output})
4645

47-
target_link_libraries(${name} ${RS_RELEASE_EXTENSION_OUT})
48-
target_link_options(${name} PRIVATE -nostartfiles -Wl,--import-memory -Wl,--no-entry -Wl,--export-dynamic)
49-
target_include_directories(${name} PRIVATE "${PROJECT_SOURCE_DIR}/")
50-
target_include_directories(${name} PRIVATE ${sqlite3_SOURCE_DIR})
51-
target_compile_definitions(${name} PRIVATE
52-
_HAVE_SQLITE_CONFIG_H
53-
SQLITE_API=${wasm_visibility}
46+
set(sources
47+
${CMAKE_CURRENT_SOURCE_DIR}/os_web.c
48+
${CMAKE_CURRENT_SOURCE_DIR}/helpers.c
49+
${sqlite3_SOURCE_DIR}/sqlite3.c
50+
${RS_RELEASE_EXTENSION_OUT}
51+
)
52+
set(flags -Wall -Wextra -Wno-unused-parameter -Wno-unused-function)
53+
54+
if(${debug})
55+
list(APPEND sources "${CMAKE_BINARY_DIR}/vfstrace.c")
56+
list(APPEND flags "-g" "-DDEBUG")
57+
else()
58+
list(APPEND flags "-Oz" "-DNDEBUG" "-flto")
59+
endif()
60+
61+
add_custom_command(
62+
OUTPUT ${clang_output}
63+
COMMAND ${clang} --target=${triple} -std=c23
64+
${flags}
65+
-o ${clang_output}
66+
-I ${PROJECT_SOURCE_DIR} -I ${sqlite3_SOURCE_DIR}
67+
-D_HAVE_SQLITE_CONFIG_H
68+
-mcpu=generic
69+
-mexec-model=reactor
70+
-fno-stack-protector -fno-stack-clash-protection
71+
-Wl,--import-memory
72+
--sysroot ${wasi_sysroot}
73+
${sources}
74+
@${CMAKE_CURRENT_BINARY_DIR}/required_symbols.txt
75+
DEPENDS ${sources} required_symbols
76+
VERBATIM
77+
)
78+
79+
add_custom_command(
80+
OUTPUT ${init_output}
81+
COMMAND wasm-ctor-eval -c _initialize ${clang_output} -o ${init_output}
82+
VERBATIM
83+
DEPENDS ${clang_output}
84+
)
85+
86+
if(NOT ${debug})
87+
set(output ${name}.wasm)
88+
89+
add_custom_command(
90+
OUTPUT ${output}
91+
COMMAND wasm-opt --strip --strip-producers -c -O4 ${init_output} -o ${output}
92+
VERBATIM
93+
DEPENDS ${init_output}
5494
)
55-
set_property(TARGET ${name} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
95+
endif()
96+
97+
add_custom_target(${name} DEPENDS ${output})
5698
endmacro()
5799

58100
# Script to use llc to get object code from bytecode
@@ -73,26 +115,13 @@ add_custom_target(
73115
COMMAND sh ${objectcode_script}
74116
)
75117

76-
base_sqlite3_target(sqlite3_debug)
77-
file(DOWNLOAD https://raw.githubusercontent.com/sqlite/sqlite/version-3.44.0/src/test_vfstrace.c "${CMAKE_BINARY_DIR}/vfstrace.c")
78-
target_sources(sqlite3_debug PRIVATE "${CMAKE_BINARY_DIR}/vfstrace.c")
79-
target_compile_options(sqlite3_debug PRIVATE -g)
80-
target_compile_definitions(sqlite3_debug PRIVATE SQLITE_ENABLE_VFSTRACE SQLITE_ENABLE_API_ARMOR)
81-
set_target_properties(sqlite3_debug PROPERTIES OUTPUT_NAME "sqlite3" SUFFIX ".debug.wasm")
82-
83-
base_sqlite3_target(sqlite3_opt)
84-
target_compile_options(sqlite3_opt PRIVATE -Oz)
85-
set_target_properties(sqlite3_opt PROPERTIES OUTPUT_NAME "sqlite3" SUFFIX ".tmp.wasm")
86-
add_custom_command(TARGET sqlite3_opt POST_BUILD
87-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../
88-
COMMAND dart run tool/wasm_dce.dart ${CMAKE_CURRENT_BINARY_DIR}/sqlite3.tmp.wasm ${CMAKE_CURRENT_BINARY_DIR}/sqlite3.dce.wasm
89-
COMMAND wasm-opt ${CMAKE_CURRENT_BINARY_DIR}/sqlite3.dce.wasm -O4 -o ${CMAKE_CURRENT_BINARY_DIR}/sqlite3.wasm
90-
)
118+
base_sqlite3_target(sqlite3_debug true)
119+
base_sqlite3_target(sqlite3_opt false)
91120

92121
add_dependencies(sqlite3_opt powersync_core_bytecode)
93122
add_dependencies(sqlite3_debug powersync_core_bytecode)
94123

95124
add_custom_target(output)
96-
add_custom_command(TARGET output COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/sqlite3.wasm ${PROJECT_SOURCE_DIR}/../../example/web/sqlite3.wasm DEPENDS)
97-
add_custom_command(TARGET output COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/sqlite3.debug.wasm ${PROJECT_SOURCE_DIR}/../../example/web/sqlite3.debug.wasm)
98-
add_dependencies(output sqlite3_debug sqlite3_opt powersync_core_bytecode)
125+
add_custom_command(TARGET output COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/sqlite3_opt.wasm ${PROJECT_SOURCE_DIR}/../../example/web/sqlite3.wasm)
126+
add_custom_command(TARGET output COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/sqlite3_debug.init.wasm ${PROJECT_SOURCE_DIR}/../../example/web/sqlite3.debug.wasm)
127+
add_dependencies(output sqlite3_debug sqlite3_opt powersync_core_bytecode)

sqlite3/assets/wasm/toolchain.cmake

-10
This file was deleted.

sqlite3/example/custom_wasm_build/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ rustup target add wasm32-wasi
2727
```
2828

2929
Additionally, you need to download WASI compiler builtins and the associated libc
30-
as described in the [build instructions](https://github.com/simolus3/sqlite3.dart/tree/rust-wasm-build/sqlite3#compiling).
30+
as described in the [build instructions](https://github.com/simolus3/sqlite3.dart/tree/main/sqlite3#compiling).
3131

3232
## Building
3333

sqlite3/example/custom_wasm_build/build.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ fn main() {
77
env::var("WASI_SYSROOT").unwrap_or_else(|_| "/usr/share/wasi-sysroot".to_string());
88

99
let cmake_dir = Config::new("../../assets/wasm/")
10-
.configure_arg("--toolchain")
11-
.configure_arg(std::fs::canonicalize("../../assets/wasm/toolchain.cmake").unwrap())
1210
.define("wasi_sysroot", &sysroot)
11+
.define("CMAKE_C_COMPILER_WORKS", "1")
1312
.build_target("sqlite3_opt_lib")
1413
.build_target("help") // We only need the sources
1514
.build();

sqlite3/example/web/worker.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void main() {
2020

2121
if (data.equals('start'.toJS).toDart) {
2222
final options = WasmVfs.createOptions();
23-
final worker = web.Worker(''); // Clone this worker
23+
final worker = web.Worker(''.toJS); // Clone this worker
2424
worker.postMessage(options);
2525

2626
// Now, wait for the worker to report that it has been initialized.

sqlite3/lib/src/wasm/js_interop/wasm.dart

+8
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ class WasmInstance {
5454
});
5555

5656
final native = await _instantiateStreaming(response, importsJs).toDart;
57+
58+
// If the module has an `_initialize` export, it needs to be called to run
59+
// C constructors and set up memory.
60+
final exports = native.instance.exports;
61+
if (exports.has('_initialize')) {
62+
(exports['_initialize'] as JSFunction).callAsFunction();
63+
}
64+
5765
return WasmInstance._(native.instance);
5866
}
5967
}

sqlite3/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ dependencies:
2626
ffi: '>=1.2.1 <3.0.0'
2727
meta: ^1.3.0
2828
path: ^1.8.0
29-
web: ^0.5.0
29+
web: ^1.0.0
3030

3131
dev_dependencies:
3232
analyzer: ^6.4.1
3333
build_daemon: ^4.0.0
3434
build_runner: ^2.1.7
3535
build_web_compilers: ^4.0.3
36-
ffigen: ^12.0.0
36+
ffigen: ^13.0.0
3737
http: ^1.2.1
3838
lints: ^4.0.0
3939
shelf: ^1.4.0

sqlite3/test/wasm/sqlite3_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void main() {
9393
test(
9494
backend,
9595
() async {
96-
final worker = web.Worker(workerUri);
96+
final worker = web.Worker(workerUri.toJS);
9797

9898
web.EventStreamProviders.errorEvent
9999
.forTarget(worker)

sqlite3/test/wasm/worker.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Future<void> _startTest(String fsImplementation, Uri wasmUri) async {
6969
// server needed for synchronous access.
7070
final options = WasmVfs.createOptions();
7171

72-
final worker = web.Worker(scope.location.href);
72+
final worker = web.Worker(scope.location.href.toJS);
7373
worker.postMessage(options);
7474

7575
// Wait for the worker to acknowledge it being ready

0 commit comments

Comments
 (0)