### Installation Configuration Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/CMakeLists.txt Configures installation paths for runtime components, ensuring support files are placed correctly next to the executable. This setup facilitates running the application directly from the build directory. ```cmake set(BUILD_BUNDLE_DIR "$") set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") ``` -------------------------------- ### Install Executable Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/CMakeLists.txt Installs the main executable target to the runtime destination. This makes the application executable available in the specified installation directory. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) ``` -------------------------------- ### Vite Setup for sqlite3-web Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_web/extra/js-package/README.md Demonstrates how to import worker and WASM module URLs using Vite's explicit URL imports for setup. ```TypeScript import workerUrl from "sqlite3-web/worker.js?url"; // Or, if you need encryption support, `sqlite3-web/sqlite3mc.wasm?url` import sqliteWasm from "sqlite3-web/sqlite3.wasm?url"; import { defaultWorkerConnector, openWebSqlite } from "sqlite3-web"; const sqlite3 = openWebSqlite({ workers: defaultWorkerConnector(workerUrl), wasmUri: sqliteWasm, }); ``` -------------------------------- ### Install Dependencies on macOS Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_wasm_build/README.md Install necessary tools like cmake, llvm, binaryen, wasi-libc, and wasi-runtimes using Homebrew on macOS. ```bash brew install cmake llvm binaryen wasi-libc wasi-runtimes ``` -------------------------------- ### Setup Build on Linux Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_wasm_build/README.md Use this CMake command to set up the build environment on Linux when WASI is in the default sysroot location and the clang compiler has the required builtins. ```bash cmake -S src -B .dart_tool/sqlite3_build ``` -------------------------------- ### Install Application Bundle Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/linux/CMakeLists.txt Configures the installation of the application bundle, including the executable, ICU data, Flutter library, bundled plugin libraries, native assets, and Flutter assets. It ensures a clean build bundle directory and handles AOT library installation for non-Debug builds. ```cmake set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Install Flutter Library Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/CMakeLists.txt Installs the main Flutter library file to the bundle's library directory. This makes the core Flutter runtime available. ```cmake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Setup Build on macOS Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_wasm_build/README.md Configure the build environment on macOS using CMake, specifying the WASI sysroot path and the clang compiler path. ```bash cmake -Dwasi_sysroot=/opt/homebrew/share/wasi-sysroot -Dclang=/opt/homebrew/opt/llvm/bin/clang -S src -B .dart_tool/sqlite3_build ``` -------------------------------- ### Web Database Implementation Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3/doc/common.md This example demonstrates opening a SQLite database on the web using WASM. It utilizes `WasmSqlite3.loadFromUrlString` and `IndexedDbFileSystem` for storage. ```dart // database_web.dart import 'package:sqlite3/wasm.dart'; Future openDatabase() async { final sqlite = await WasmSqlite3.loadFromUrlString('sqlite3.wasm'); final fs = await IndexedDbFileSystem.open(dbName: 'app.db'); sqlite.registerVirtualFileSystem(fs, makeDefault: true); return sqlite.open('/app.db'); } ``` -------------------------------- ### Install AOT Library Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compilation library on Profile and Release builds only. This optimizes performance for non-debug configurations. ```cmake install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Install Bundled Plugin Libraries Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/CMakeLists.txt Installs any bundled plugin libraries to the bundle's library directory. This ensures that plugins with native libraries are correctly deployed. ```cmake if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/CMakeLists.txt Installs Flutter assets, ensuring the assets directory is completely re-copied on each build to prevent stale files. This guarantees that the latest assets are always deployed. ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Execute SQL on SQLite Database Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_web/example/index.html After opening a database, use the `execute` function to run SQL commands. This example demonstrates creating a table named 'foo' with a column 'bar'. ```dart let db = await open('test', 'opfsWithExternalLocks'); await execute(db, 'create table foo (bar);') ``` -------------------------------- ### Web Encryption Setup with SQLite Multiple Ciphers Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3/README.md Loads a WASM build of SQLite Multiple Ciphers for web encryption and registers an in-memory file system. Note that this is experimental. ```dart final sqlite3 = await WasmSqlite3.loadFromUrlString('sqlite3mc.wasm'); sqlite3.registerVirtualFileSystem(InMemoryFileSystem(), makeDefault: true); final database = sqlite3.open('/database') ..execute("pragma key = 'test';"); // TODO: Replace key ``` -------------------------------- ### Install ICU Data Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/CMakeLists.txt Installs the ICU data file to the data directory within the bundle. This is necessary for internationalization and localization features. ```cmake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Native Assets Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/CMakeLists.txt Copies native assets provided by build.dart from all packages to the bundle's library directory. This ensures that native assets required by plugins are included. ```cmake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Load WASM SQLite and Register File System Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3/README.md Loads the WASM version of SQLite from a URL and registers an IndexedDB file system. This is the primary setup for web usage. ```dart import 'package:http/http.dart' as http; import 'package:sqlite3/common.dart'; import 'package:sqlite3/wasm.dart'; Future loadSqlite() async { final sqlite = await WasmSqlite3.loadFromUrlString('sqlite3.wasm'); final fileSystem = await IndexedDbFileSystem.open(dbName: 'my_app'); sqlite.registerVirtualFileSystem(fileSystem, makeDefault: true); return sqlite; } ``` -------------------------------- ### SQLite3 Multiple Ciphers Encryption Setup Source: https://github.com/simolus3/sqlite3.dart/blob/main/UPGRADING_TO_V3.md These statements should be run from SQLite3MultipleCiphers to ensure compatibility with existing SQLCipher databases. ```sql pragma cipher = 'sqlcipher'; pragma legacy = 4; pragma key = '...your key...'; ``` -------------------------------- ### Customizing SQLite Library Name Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3/doc/hook.md Allows customization of the SQLite library name for specific operating systems when using 'source: system'. This example sets a default name and a specific name for Windows. ```yaml hooks: user_defines: sqlite3: source: system # Use winsqlite3.dll on Windows, libsqlite3.{so,dylib} on Linux and macOS name_windows: winsqlite3 name: sqlite3 ``` -------------------------------- ### Asynchronous sqlite3 Connection on the Web Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_web/README.md Establishes an asynchronous connection to an sqlite3 database hosted in a web worker. It automatically handles worker setup, WASM module loading, and feature detection. ```dart Future connectToDatabase() async { final sqlite = await WebSqlite.open( workers: WorkerConnector.defaultWorkers('worker.dart.js'), wasmModule: 'sqlite3.wasm', ); final features = await sqlite.runFeatureDetection(); print('got features: $features'); final connection = await sqlite.connectToRecommended('my_database'); print(await connection.database.select('select sqlite_version()')); } ``` -------------------------------- ### Add sqlite3 Dependency Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3/README.md Add the sqlite3 package to your Dart project using the dart pub add command. This is the initial step to start using the library. ```shell dart pub add sqlite3 ``` -------------------------------- ### Opening and Querying a Database Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_web/extra/js-package/README.md Shows how to connect to a recommended database and execute SQL queries, including CREATE TABLE and SELECT with parameters. ```TypeScript const db = await sqlite3.connectToRecommended("my_database"); await db.execute("CREATE TABLE users (name TEXT) STRICT"); const result = await db.select( "SELECT * FROM users LIMIT ?", { parameters: [10] } ); ``` -------------------------------- ### Native Database Implementation Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3/doc/common.md This snippet shows how to open a SQLite database on native platforms using `sqlite3.open()`. It assumes a function `pickDatabasePath` is available to determine the database file location. ```dart // database_native.dart import 'package:sqlite3/sqlite3.dart'; Future openDatabase() async { final path = await pickDatabasePath(); // e.g. with package:path_provider return sqlite3.open(path); } ``` -------------------------------- ### Project-Level CMake Configuration Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/linux/CMakeLists.txt Sets up the minimum CMake version, project name, and executable name. It also defines the application ID and opts into modern CMake behaviors. ```cmake cmake_minimum_required(VERSION 3.13) project(runner LANGUAGES CXX) set(BINARY_NAME "flutter_integration_tests") set(APPLICATION_ID "com.example.flutter_integration_tests") cmake_policy(SET CMP0063 NEW) ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/runner/CMakeLists.txt Applies a standard set of build settings to the executable. This can be removed if custom build settings are required. ```cmake # Apply the standard set of build settings. This can be removed for applications # that need different build settings. apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Open SQLite Database in Web Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_web/example/index.html Use the `open` function to initialize a SQLite database with a specified name and storage implementation. Supported implementations include in-memory, IndexedDB, and OPFS with different worker configurations. ```dart await open('name', 'implementation') ``` -------------------------------- ### Export Flutter Library and ICU Data Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/flutter/CMakeLists.txt Exports the Flutter library path and the Flutter ICU data file to the parent scope. This makes them available for installation and other build steps. ```cmake set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) ``` -------------------------------- ### Fetch SQLite3 Source Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_wasm_build/src/CMakeLists.txt Fetches the SQLite3 source code using FetchContent. Ensure the URL and version match the desired SQLite release. ```cmake FetchContent_Declare( sqlite3 # NOTE: When changing this, also update `test/wasm/sqlite3_test.dart` URL https://sqlite.org/2026/sqlite-autoconf-3530200.tar.gz DOWNLOAD_EXTRACT_TIMESTAMP NEW ) FetchContent_MakeAvailable(sqlite3) ``` -------------------------------- ### Project Configuration Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/CMakeLists.txt Sets the minimum CMake version and project name. Ensure your CMake version meets the minimum requirement. ```cmake cmake_minimum_required(VERSION 3.14) project(flutter_integration_tests LANGUAGES CXX) ``` -------------------------------- ### Find PkgConfig modules for GTK, GLIB, and GIO Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/linux/flutter/CMakeLists.txt This section uses PkgConfig to find and import targets for GTK, GLIB, and GIO libraries, which are system-level dependencies for the Flutter Linux backend. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) ``` -------------------------------- ### Build SQLite with Custom WASM Module (Release) Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3/example/custom_wasm_build/README.md Compile the SQLite library and custom extensions into WASM object files using Cargo for a release build, optimized for size. Ensure WASI_SYSROOT and CC environment variables are set correctly. ```bash WASI_SYSROOT=/path/to/wasi/ CC=/path/to/clang cargo build --target wasm32-unknown-unknown --release ``` -------------------------------- ### Database Stub Implementation Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3/doc/common.md This file serves as a placeholder for the database implementation, throwing an UnsupportedError for unknown platforms. It's used in cross-platform development to ensure code compiles. ```dart // database_stub.dart import 'package:sqlite3/common.dart'; Future openDatabase() async { throw UnsupportedError('Unknown platform'); } ``` -------------------------------- ### Configure Cross-Building Sysroot Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/linux/CMakeLists.txt Sets up the sysroot and find root path for cross-compilation based on the FLUTTER_TARGET_PLATFORM_SYSROOT variable. ```cmake if(FLUTTER_TARGET_PLATFORM_SYSROOT) set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) endif() ``` -------------------------------- ### Link Libraries and Include Directories Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/runner/CMakeLists.txt Links necessary libraries (flutter, flutter_wrapper_app, dwmapi.lib) and adds the source directory to include paths. Add any other application-specific dependencies here. ```cmake # Add dependency libraries and include directories. Add any application-specific # dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Configure Flutter library and headers Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/linux/flutter/CMakeLists.txt Sets up the Flutter library path, ICU data file, project build directory, and AOT library path. It also defines a list of Flutter library headers and prepends a directory to them. ```cmake set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) list(APPEND FLUTTER_LIBRARY_HEADERS "fl_basic_message_channel.h" "fl_binary_codec.h" "fl_binary_messenger.h" "fl_dart_project.h" "fl_engine.h" "fl_json_message_codec.h" "fl_json_method_codec.h" "fl_message_codec.h" "fl_method_call.h" "fl_method_channel.h" "fl_method_codec.h" "fl_method_response.h" "fl_plugin_registrar.h" "fl_plugin_registry.h" "fl_standard_message_codec.h" "fl_standard_method_codec.h" "fl_string_codec.h" "fl_value.h" "fl_view.h" "flutter_linux.h" ) list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") ``` -------------------------------- ### Create Static Library for Application Wrapper Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/flutter/CMakeLists.txt Creates a static library named 'flutter_wrapper_app' using core and application-specific C++ wrapper sources. It applies standard build settings and links against the Flutter library. ```cmake add_library(flutter_wrapper_app STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_APP} ) apply_standard_settings(flutter_wrapper_app) target_link_libraries(flutter_wrapper_app PUBLIC flutter) target_include_directories(flutter_wrapper_app PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_app flutter_assemble) ``` -------------------------------- ### Integrate TestSqliteFileSystem in Dart Tests Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_test/README.md Set up and tear down `TestSqliteFileSystem` for SQLite databases in your Dart tests. This VFS allows database time to reflect `package:clock` and integrates with `package:file`. ```dart import 'package:fake_async/fake_async.dart'; import 'package:sqlite3/sqlite3.dart'; import 'package:sqlite3_test/sqlite3_test.dart'; import 'package:file/local.dart'; import 'package:test/test.dart'; void main() { late TestSqliteFileSystem vfs; setUpAll(() { vfs = TestSqliteFileSystem(fs: const LocalFileSystem()); sqlite3.registerVirtualFileSystem(vfs); }); tearDownAll(() => sqlite3.unregisterVirtualFileSystem(vfs)); test('my test depending on database time', () { final database = sqlite3.openInMemory(vfs: vfs.name); addTearDown(database.dispose); // The VFS uses package:clock to get the current time, which can be // overridden for tests: final moonLanding = DateTime.utc(1969, 7, 20, 20, 18, 04); FakeAsync(initialTime: moonLanding).run((_) { final row = database.select('SELECT unixepoch(current_timestamp)').first; expect(row.columnAt(0), -14182916); }); }); } ``` -------------------------------- ### Open a SQLite Connection Pool Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_connection_pool/README.md Call `SqliteConnectionPool.open` to create a connection pool. It takes a name (typically the database path) and a callback to initialize connections. Opening pools is synchronized to prevent race conditions. ```dart final pool = SqliteConnectionPool.open( name: '/path/to/database.db', openConnections: () { // Open one write and multiple read connections. return PoolConnections( openDatabase(true), [for (var i = 0; i < 4; i++) openDatabase(false)] ); }, ); ``` -------------------------------- ### Initialize SQLite Database Connections Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_connection_pool/README.md The `openDatabase` function configures SQLite connections. It sets the journal mode to WAL and optionally enables query-only mode for read connections. ```dart Database openDatabase(bool writer) { final db = sqlite3.open('/path/to/database.db'); db.execute('pragma journal_mode = wal;'); if (!writer) { db.execute('pragma query_only = true'); } } ``` -------------------------------- ### Configure System SQLite with User Defines Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3/doc/hook.md Instructs the Dart embedder to look up SQLite from the operating system. Use this when you want to rely on the system's SQLite version. ```yaml hooks: user_defines: sqlite3: source: system # or "process", or "excutable" ``` -------------------------------- ### Configure User Defines for SQLite Build Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3/doc/hook.md Use this section in your pubspec.yaml to specify a custom SQLite source file and define compilation flags. This allows for tailored SQLite builds with package:sqlite3. ```yaml hooks: user_defines: sqlite3: source: source path: path/to/sqlite3.c # relative to your workspace root defines: # optional default_options: false # optional, to disable default compile-time options used by package:sqlite3 defines: - SQLITE_THREADSAFE=1 - SQLITE_LIKE_DOESNT_MATCH_BLOBS ``` -------------------------------- ### Load Bundled Libraries Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/linux/CMakeLists.txt Sets the runtime path for bundled libraries to be relative to the binary's location. ```cmake set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Custom command to build Flutter library using tool_backend.sh Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/linux/flutter/CMakeLists.txt This custom command executes the Flutter tool backend script to build the Flutter library and its headers. A phony target is used to ensure the command runs on every build. ```cmake add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/_phony_ COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} VERBATIM ) add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ) ``` -------------------------------- ### Profile Build Mode Settings Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/CMakeLists.txt Sets linker and compiler flags for the Profile build mode to match Release settings. This ensures performance characteristics are consistent between Profile and Release builds. ```cmake set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") ``` -------------------------------- ### Web Worker Entrypoint for sqlite3 Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_web/README.md Defines the entrypoint for a web worker that manages sqlite3 database access. This code should be compiled with `dart compile js`. ```dart import 'package:sqlite3_web/sqlite3_web.dart'; import 'controller.dart'; void main() { WebSqlite.workerEntrypoint(controller: ExampleController()); } ``` -------------------------------- ### Create Static Library for Plugin Wrapper Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/flutter/CMakeLists.txt Creates a static library named 'flutter_wrapper_plugin' using core and plugin-specific C++ wrapper sources. It applies standard build settings and configures position-independent code and hidden visibility. ```cmake add_library(flutter_wrapper_plugin STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ) apply_standard_settings(flutter_wrapper_plugin) set_target_properties(flutter_wrapper_plugin PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(flutter_wrapper_plugin PROPERTIES CXX_VISIBILITY_PRESET hidden) target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) target_include_directories(flutter_wrapper_plugin PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_plugin flutter_assemble) ``` -------------------------------- ### Add sqlite3_test as a Dev Dependency Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_test/README.md Add the `sqlite3_test` package as a development dependency to your project using the Dart pub command. ```bash dart pub add --dev sqlite3_test ``` -------------------------------- ### Build SQLite with Custom WASM Module (Debug) Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3/example/custom_wasm_build/README.md Compile the SQLite library and custom extensions into WASM object files using Cargo. Ensure WASI_SYSROOT and CC environment variables are set correctly. This command builds a debug version. ```bash WASI_SYSROOT=/path/to/wasi/ CC=/path/to/clang cargo build --target wasm32-unknown-unknown ``` -------------------------------- ### Define Output Target Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_wasm_build/src/CMakeLists.txt Defines a custom target named 'output' that copies the built WebAssembly files to the project's output directory. ```cmake add_custom_target(output) add_custom_command(TARGET output COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/sqlite3_opt.wasm ${PROJECT_SOURCE_DIR}/../out/sqlite3.wasm) add_custom_command(TARGET output COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/sqlite3_debug.clang.wasm ${PROJECT_SOURCE_DIR}/../out/sqlite3.debug.wasm) add_custom_command(TARGET output COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/sqlite3mc.wasm ${PROJECT_SOURCE_DIR}/../out/sqlite3mc.wasm) add_dependencies(output sqlite3_debug sqlite3_opt sqlite3mc) add_dependencies(output sqlite3_debug) ``` -------------------------------- ### Set Wrapper Root Directory Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/flutter/CMakeLists.txt Defines the root directory for the C++ client wrapper sources. This path is used to locate wrapper implementation files. ```cmake set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") ``` -------------------------------- ### Build WASM Module Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_wasm_build/README.md Build the WebAssembly module using CMake, targeting the 'output' target which copies the WASM files to the 'out/' directory. The '-j' flag allows for parallel building. ```bash cmake --build .dart_tool/sqlite3_build/ -t output -j ``` -------------------------------- ### Include Flutter Build Rules Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/CMakeLists.txt Includes the build rules for the Flutter managed directory. This is essential for integrating Flutter's build system into the project. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) ``` -------------------------------- ### Fetch SQLite3 Multiple Ciphers Source Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_wasm_build/src/CMakeLists.txt Fetches the SQLite3 Multiple Ciphers amalgamation using FetchContent. This is used for cryptographic extensions. ```cmake FetchContent_Declare( sqlite3mc URL https://github.com/utelle/SQLite3MultipleCiphers/releases/download/v2.3.5/sqlite3mc-2.3.5-sqlite-3.53.2-amalgamation.zip DOWNLOAD_EXTRACT_TIMESTAMP NEW ) FetchContent_MakeAvailable(sqlite3mc) ``` -------------------------------- ### Include Generated Configuration Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/flutter/CMakeLists.txt Includes a generated configuration file provided by the Flutter tool. This file contains project-specific build settings. ```cmake include(${EPHEMERAL_DIR}/generated_config.cmake) ``` -------------------------------- ### Include Runner Build Rules Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/CMakeLists.txt Includes the build rules for the application runner. This directs CMake to process the build configuration for the application's entry point. ```cmake add_subdirectory("runner") ``` -------------------------------- ### Enable SQLite3 Multiple Ciphers with Hooks Source: https://github.com/simolus3/sqlite3.dart/blob/main/UPGRADING_TO_V3.md Add this to your pubspec.yaml to enable SQLite3 Multiple Ciphers, which is compatible with web. This replaces the need for `sqlcipher_flutter_libs`. ```yaml hooks: user_defines: sqlite3: source: sqlite3mc ``` -------------------------------- ### Link WASM Object Files into sqlite3.wasm (Release) Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3/example/custom_wasm_build/README.md Use the provided Dart script to link the compiled WASM object files into a final sqlite3.wasm module for release builds. Ensure the CC environment variable is set. ```bash CC=/path/to/clang dart run link.dart target/wasm32-unknown-unknown/release ``` -------------------------------- ### Include Generated Plugin Rules Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/CMakeLists.txt Includes the CMake rules for generated plugins, which manage their building and integration into the application. This ensures all necessary plugins are compiled and linked. ```cmake include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Apply Standard Compilation Settings Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/CMakeLists.txt Defines a function to apply standard compilation settings to a target, including C++17 standard, warning levels, and exception handling. Use this function for consistent compilation across targets. ```cmake function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_17) target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") target_compile_options(${TARGET} PRIVATE /EHsc) target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") endfunction() ``` -------------------------------- ### Define Flutter interface library target Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/linux/flutter/CMakeLists.txt Creates an interface library target named 'flutter' and configures its include directories and link libraries, including system dependencies found via PkgConfig. ```cmake add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") target_link_libraries(flutter INTERFACE PkgConfig::GTK PkgConfig::GLIB PkgConfig::GIO ) add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Conditional Imports for Cross-Platform Support Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3/doc/common.md This code demonstrates how to use conditional imports in Dart to support both web and native platforms. It imports the appropriate database implementation based on the target environment. ```dart import 'database_stub.dart' if (dart.library.io) 'database_native.dart' if (dart.library.js_interop) 'database_web.dart'; ``` -------------------------------- ### Set Executable Runtime Output Directory Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/linux/CMakeLists.txt Configures the runtime output directory for the application's executable. This is set to a subdirectory within the build directory to prevent users from running the unbundled copy. ```cmake set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### List Plugin Wrapper Sources Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/flutter/CMakeLists.txt Appends C++ wrapper source files specific to plugins to the CPP_WRAPPER_SOURCES_PLUGIN list. These are used for plugin registration. ```cmake list(APPEND CPP_WRAPPER_SOURCES_PLUGIN "plugin_registrar.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") ``` -------------------------------- ### Link Libraries in CMake Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/linux/runner/CMakeLists.txt Links necessary libraries to the application target. This includes the 'flutter' library and 'PkgConfig::GTK' for GTK integration. Add any other application-specific dependencies here. ```cmake # Add dependency libraries. Add any application-specific dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) ``` -------------------------------- ### List Core Wrapper Sources Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/flutter/CMakeLists.txt Appends core C++ wrapper source files to the CPP_WRAPPER_SOURCES_CORE list. These files contain fundamental implementations for the Flutter C++ wrapper. ```cmake list(APPEND CPP_WRAPPER_SOURCES_CORE "core_implementations.cc" "standard_codec.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") ``` -------------------------------- ### Unicode Support Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/CMakeLists.txt Enables Unicode support for all projects by defining UNICODE and _UNICODE preprocessor macros. This is crucial for handling international characters correctly. ```cmake add_definitions(-DUNICODE -D_UNICODE) ``` -------------------------------- ### Flutter Tool Backend Custom Command Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/flutter/CMakeLists.txt Defines a custom command to execute the Flutter tool backend script. This command generates various build artifacts, including the Flutter library, headers, and wrapper sources. It's configured to run every time due to the phony output. ```cmake add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ${PHONY_OUTPUT} COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" ${FLUTTER_TARGET_PLATFORM} $ VERBATIM ) ``` -------------------------------- ### Find GTK+ 3.0 Package Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/linux/CMakeLists.txt Finds the PkgConfig module for GTK+ 3.0, making its imported target available for use. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) ``` -------------------------------- ### Define Native SQLite Extension Initialization Function Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3/example/custom_extension/README.md Declare the native function signature for initializing a SQLite extension. This function is expected by the SQLite C API. ```dart @Native, Pointer, Pointer)>() external int sqlite3_vec_init( Pointer db, Pointer pzErrMsg, Pointer pApi, ); ``` -------------------------------- ### Apply Standard Compilation Settings Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/linux/CMakeLists.txt Applies standard C++ compilation features and options to a target. It enables C++14, sets Wall and Werror flags, and applies O3 optimization and NDEBUG definition for non-Debug builds. ```cmake function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_14) target_compile_options(${TARGET} PRIVATE -Wall -Werror) target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") endfunction() ``` -------------------------------- ### List App Wrapper Sources Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/flutter/CMakeLists.txt Appends C++ wrapper source files specific to the application runner to the CPP_WRAPPER_SOURCES_APP list. These are used for managing the Flutter engine and view. ```cmake list(APPEND CPP_WRAPPER_SOURCES_APP "flutter_engine.cc" "flutter_view_controller.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") ``` -------------------------------- ### Build SQLite3 with Cryptography Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_wasm_build/src/CMakeLists.txt Builds the SQLite3 WebAssembly target with cryptographic extensions enabled. This uses the SQLite3MultipleCiphers library. ```cmake base_sqlite3_target(sqlite3mc false true) ``` -------------------------------- ### Add Preprocessor Definitions for Build Version Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/runner/CMakeLists.txt Adds preprocessor definitions to include Flutter version information directly into the build. This allows access to version constants within the C++ code. ```cmake # Add preprocessor definitions for the build version. target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") ``` -------------------------------- ### Enable SQLCipher Encryption with Hooks Source: https://github.com/simolus3/sqlite3.dart/blob/main/UPGRADING_TO_V3.md Add this to your pubspec.yaml to enable SQLCipher encryption. The `sqlcipher_flutter_libs` dependency is no longer functional. ```yaml hooks: user_defines: sqlite3: source: sqlcipher ``` -------------------------------- ### Define Executable Target in CMake Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/linux/runner/CMakeLists.txt Defines the main executable for the application. Ensure BINARY_NAME is consistent with the top-level CMakeLists.txt for `flutter run` compatibility. Add any new source files to this list. ```cmake cmake_minimum_required(VERSION 3.13) project(runner LANGUAGES CXX) # Define the application target. To change its name, change BINARY_NAME in the # top-level CMakeLists.txt, not the value here, or `flutter run` will no longer # work. # # Any new source files that you add to the application should be added here. add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) ``` -------------------------------- ### Executable Name Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/CMakeLists.txt Defines the on-disk name for the application executable. Change this value to modify the executable's filename. ```cmake set(BINARY_NAME "flutter_integration_tests") ``` -------------------------------- ### Build Optimized SQLite3 Target Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_wasm_build/src/CMakeLists.txt Builds the optimized version of the SQLite3 WebAssembly target. This excludes debugging symbols and applies optimizations for size and speed. ```cmake base_sqlite3_target(sqlite3_opt false false) ``` -------------------------------- ### Build Configuration Types Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/CMakeLists.txt Configures the available build types (Debug, Profile, Release) for multi-configuration generators or sets the default build type if not specified. This ensures consistent build modes. ```cmake get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(IS_MULTICONFIG) set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" CACHE STRING "" FORCE) else() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() endif() ``` -------------------------------- ### Configure SQLite3 Multiple Ciphers in pubspec.yaml Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3/doc/hook.md Specify SQLite3MultipleCiphers as the source for the sqlite3 hook in your pubspec.yaml file. This is useful for enabling encryption support. ```yaml hooks: user_defines: sqlite3: source: sqlite3mc # for SQLite3MultipleCiphers, default is sqlite3. sqlcipher is also available. ``` -------------------------------- ### Link WASM Object Files into sqlite3.wasm (Debug) Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3/example/custom_wasm_build/README.md Use the provided Dart script to link the compiled WASM object files into a final sqlite3.wasm module for debug builds. Ensure the CC environment variable is set. ```bash CC=/path/to/clang dart run link.dart target/wasm32-unknown-unknown/debug ``` -------------------------------- ### CMake Policy Opt-in Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/CMakeLists.txt Explicitly opts into modern CMake behaviors to prevent warnings with recent CMake versions. This ensures compatibility and avoids potential issues with newer CMake features. ```cmake cmake_policy(VERSION 3.14...3.25) ``` -------------------------------- ### Define Phony Output for Custom Command Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/flutter/CMakeLists.txt Defines a phony output file that does not exist. This is used to force a custom command to run every time, as CMake's dependency tracking cannot determine the output of the Flutter tool backend directly. ```cmake set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) ``` -------------------------------- ### Define Executable Target Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/runner/CMakeLists.txt Defines the main executable target for the application, including all necessary source files and generated files. Ensure BINARY_NAME is consistent with the top-level CMakeLists.txt for `flutter run` compatibility. ```cmake cmake_minimum_required(VERSION 3.14) project(runner LANGUAGES CXX) # Define the application target. To change its name, change BINARY_NAME in the # top-level CMakeLists.txt, not the value here, or `flutter run` will no longer # work. # # Any new source files that you add to the application should be added here. add_executable(${BINARY_NAME} WIN32 "flutter_window.cpp" "main.cpp" "utils.cpp" "win32_window.cpp" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" "Runner.rc" "runner.exe.manifest" ) ``` -------------------------------- ### Base SQLite3 Target Macro Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_wasm_build/src/CMakeLists.txt Defines a macro to configure and build a SQLite3 WebAssembly target. It handles source files, compiler flags, and build options for debug or optimized builds. ```cmake macro(base_sqlite3_target name debug crypto) set(clang_output ${name}.clang.wasm) set(output ${clang_output}) set(sources ${CMAKE_CURRENT_SOURCE_DIR}/os_web.c ${CMAKE_CURRENT_SOURCE_DIR}/helpers.c ${CMAKE_CURRENT_SOURCE_DIR}/external_objects.c ) set(flags -Wall -Wextra -Wno-unused-parameter -Wno-unused-function) if(${crypto}) list(APPEND sources "${sqlite3mc_SOURCE_DIR}/sqlite3mc_amalgamation.c") list(APPEND sources "${CMAKE_CURRENT_SOURCE_DIR}/getentropy.c") # We only want to support the chacha20 cipher, some of the others are tricky to # compile to webassembly. list(APPEND flags "-DHAVE_CIPHER_AES_128_CBC=0" "-DHAVE_CIPHER_AES_256_CBC=0" "-DHAVE_CIPHER_SQLCIPHER=0" "-DHAVE_CIPHER_RC4=0" "-DHAVE_CIPHER_ASCON128=0" "-DHAVE_CIPHER_AEGIS=0" "-DHAVE_CIPHER_CHACHA20=1" ) else() list(APPEND sources "${sqlite3_SOURCE_DIR}/sqlite3.c") endif() if(${debug}) list(APPEND flags "-g" "-DDEBUG") else() list(APPEND flags "-Oz" "-DNDEBUG" "-flto") endif() add_custom_command( OUTPUT ${clang_output} COMMAND ${clang} --target=${triple} -std=c23 ${flags} -o ${clang_output} -I ${PROJECT_SOURCE_DIR} -I ${sqlite3_SOURCE_DIR} -DSQLITE_ENABLE_SESSION -DSQLITE_ENABLE_PREUPDATE_HOOK -D_HAVE_SQLITE_CONFIG_H -D__WASM__ -mcpu=generic -mexec-model=reactor -fno-stack-protector -fno-stack-clash-protection --sysroot ${wasi_sysroot} ${sources} @${CMAKE_CURRENT_BINARY_DIR}/required_symbols.txt DEPENDS ${sources} required_symbols VERBATIM ) if(NOT ${debug}) set(init_output ${name}.init.wasm) set(output ${name}.wasm) add_custom_command( OUTPUT ${init_output} COMMAND wasm-ctor-eval -c _initialize ${clang_output} -o ${init_output} VERBATIM DEPENDS ${clang_output} ) add_custom_command( OUTPUT ${output} COMMAND wasm-opt --strip --strip-producers -c -O4 ${init_output} -o ${output} VERBATIM DEPENDS ${init_output} ) endif() add_custom_target(${name} DEPENDS ${output}) endmacro() ``` -------------------------------- ### Export Project Build Directory Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/flutter/CMakeLists.txt Exports the project's build directory path to the parent scope. This is used for locating build artifacts. ```cmake set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) ``` -------------------------------- ### Build Debug SQLite3 Target Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_wasm_build/src/CMakeLists.txt Builds the debug version of the SQLite3 WebAssembly target. This includes debugging symbols and no optimization. ```cmake base_sqlite3_target(sqlite3_debug true false) ``` -------------------------------- ### Add Include Directories in CMake Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/linux/runner/CMakeLists.txt Specifies include directories for the application target. This ensures that header files are found during the build process. The source directory is added as a private include directory. ```cmake target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Add Preprocessor Definitions in CMake Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/linux/runner/CMakeLists.txt Adds preprocessor definitions to the build, specifically for the application ID. This is essential for correctly identifying the application during the build process. ```cmake # Add preprocessor definitions for the application ID. add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") ``` -------------------------------- ### Define Flutter Library Path Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/flutter/CMakeLists.txt Sets the path to the Flutter Windows DLL. This library is essential for Flutter applications running on Windows. ```cmake set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") ``` -------------------------------- ### Load SQLite Vector Extension in Dart Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3/example/custom_extension/README.md Extends the `Sqlite3` class to provide a method for loading the SQLite vector extension. It uses the previously defined native function to bind and load the extension. ```dart extension LoadVectorExtension on Sqlite3 { void loadSqliteVectorExtension() { ensureExtensionLoaded( SqliteExtension( Native.addressOf, Pointer, Pointer)>>( sqlite3_vec_init ).cast(), ), ); } } ``` -------------------------------- ### Define list_prepend function for CMake Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/linux/flutter/CMakeLists.txt This function prepends a prefix to each element in a CMake list. It is used because list(TRANSFORM ... PREPEND ...) is not available in CMake version 3.10. ```cmake function(list_prepend LIST_NAME PREFIX) set(NEW_LIST "") foreach(element ${${LIST_NAME}}) list(APPEND NEW_LIST "${PREFIX}${element}") endforeach(element) set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) endfunction() ``` -------------------------------- ### Generate Required Symbols Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3_wasm_build/src/CMakeLists.txt Generates a list of required symbols for the WebAssembly build using a Dart script. This ensures only necessary symbols are exported. ```cmake add_custom_command( OUTPUT required_symbols.txt WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../ COMMAND dart run ${CMAKE_CURRENT_SOURCE_DIR}/../tool/wasm_symbols.dart ${CMAKE_CURRENT_BINARY_DIR}/required_symbols.txt DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../tool/wasm_symbols.dart VERBATIM ) add_custom_target(required_symbols DEPENDS required_symbols.txt) ``` -------------------------------- ### Add Flutter Assemble Dependency Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/linux/CMakeLists.txt Ensures that the Flutter assemble target is built before the main application executable. ```cmake add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Compile Rust Target for WASM Source: https://github.com/simolus3/sqlite3.dart/blob/main/sqlite3/example/custom_wasm_build/README.md Add the WASM32-WASI target to your Rust toolchain for cross-compilation. This is a prerequisite for compiling custom extensions. ```bash rustup target add wasm32-wasi ``` -------------------------------- ### Set Default Build Type Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/linux/CMakeLists.txt Sets the default build type to 'Debug' if not already configured. It also defines the allowed build types for the cache. ```cmake if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() ``` -------------------------------- ### Add Flutter Assemble Dependency Source: https://github.com/simolus3/sqlite3.dart/blob/main/examples/flutter_integration_tests/windows/runner/CMakeLists.txt Ensures that the Flutter build tool's assembly process is completed before the application target is built. This is a mandatory step for Flutter projects. ```cmake # Run the Flutter tool portions of the build. This must not be removed. add_dependencies(${BINARY_NAME} flutter_assemble) ```