From 6ca10a3cbd43673079afc4cbd2d9ec05023158db Mon Sep 17 00:00:00 2001 From: highghlow Date: Sat, 23 Aug 2025 17:23:03 +0300 Subject: [PATCH 01/15] feat(examples): Added build and target options to x.py --- examples/x.py | 9 ++++-- flake.lock | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 67 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/examples/x.py b/examples/x.py index aaf4170c77..9d83bbe70c 100755 --- a/examples/x.py +++ b/examples/x.py @@ -21,6 +21,7 @@ parser = argparse.ArgumentParser() parser.add_argument("-p", "--project") parser.add_argument("-l", "--list-projects", action="store_true") +parser.add_argument("-b", "--build", action="store_true") argv, unknown = parser.parse_known_args() @@ -47,7 +48,7 @@ def sqlx(command, url, cwd=None): display=f"sqlx {command}") -def project(name, database=None, driver=None): +def project(name, database=None, driver=None, target=None): if argv.list_projects: print(f"{name}") return @@ -77,8 +78,12 @@ def project(name, database=None, driver=None): # migrate sqlx("migrate run", database_url, cwd=cwd) + target_arg = "" if target is None else f" --target {target}" # check - run("cargo check", cwd=cwd, env=env) + run("cargo check" + target_arg, cwd=cwd, env=env) + + if argv.build: + run("cargo build" + target_arg, cwd=cwd, env=env) # todos diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000..1c50fe1cd3 --- /dev/null +++ b/flake.lock @@ -0,0 +1,81 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1720535198, + "narHash": "sha256-zwVvxrdIzralnSbcpghA92tWu2DV2lwv89xZc8MTrbg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "205fd4226592cc83fd4c0885a3e4c9c400efabb5", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-23.11", + "type": "indirect" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1755830208, + "narHash": "sha256-fMa/Hcg+4O2h+kl3gNPjtGSWPI8NtCl3LYMsejK6qGA=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "802a7b97f8ff672ba2dec70c9e354f51f844e796", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000000..4547e13569 --- /dev/null +++ b/flake.nix @@ -0,0 +1,67 @@ +{ + description = "Rust with WebAssembly"; + + inputs = { + nixpkgs.url = "nixpkgs/nixos-23.11"; + flake-utils.url = "github:numtide/flake-utils"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, rust-overlay, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem + (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ rust-overlay.overlays.default ]; + }; + in + { + devShells.default = + pkgs.mkShell rec { + name = "wasm-devshell"; + nativeBuildInputs = [ pkgs.pkg-config ]; + buildInputs = with pkgs; [ + clang + llvmPackages.bintools + nodejs_21 + wasm-pack + trunk + (rust-bin.stable.latest.default.override { + targets = [ "wasm32-unknown-unknown" ]; + }) + sqlx-cli + openssl + trunk + ]; + + # Add precompiled library to rustc search path + RUSTFLAGS = (builtins.map (a: ''-L ${a}/lib'') [ + pkgs.sqlite + ]); + + LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath (buildInputs ++ nativeBuildInputs); + + # Add glibc, clang, glib, and other headers to bindgen search path + BINDGEN_EXTRA_CLANG_ARGS = + # Includes normal include path + (builtins.map (a: ''-I"${a}/include"'') [ + pkgs.glibc.dev + pkgs.sqlite.dev + ]) + # Includes with special directory paths + ++ [ + ''-I"${pkgs.llvmPackages_latest.libclang.lib}/lib/clang/${pkgs.llvmPackages_latest.libclang.version}/include"'' + ''-I"${pkgs.glib.dev}/include/glib-2.0"'' + ''-I${pkgs.glib.out}/lib/glib-2.0/include/'' + ]; + + CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_LINKER = "lld"; + LIBCLANG_PATH = pkgs.lib.makeLibraryPath [ pkgs.llvmPackages_latest.libclang.lib ]; + }; + } + ); +} From 11f1c6ec150138e11aed428863ad923de5556582 Mon Sep 17 00:00:00 2001 From: highghlow Date: Sat, 23 Aug 2025 17:45:48 +0300 Subject: [PATCH 02/15] feat(sqlite): Added an option to use sqlite-wasm-rs insteal of libsqlite3-sys --- Cargo.toml | 2 + examples/sqlite/todos-wasm/Cargo.toml | 10 +++ examples/sqlite/todos-wasm/README.md | 41 ++++++++++++ .../migrations/20200718111257_todos.sql | 6 ++ examples/sqlite/todos-wasm/src/main.rs | 67 +++++++++++++++++++ sqlx-sqlite/Cargo.toml | 11 +-- sqlx-sqlite/src/arguments.rs | 4 +- sqlx-sqlite/src/connection/collation.rs | 2 +- sqlx-sqlite/src/connection/deserialize.rs | 2 +- sqlx-sqlite/src/connection/establish.rs | 2 +- sqlx-sqlite/src/connection/handle.rs | 2 +- sqlx-sqlite/src/connection/mod.rs | 2 +- sqlx-sqlite/src/error.rs | 2 +- sqlx-sqlite/src/lib.rs | 5 ++ sqlx-sqlite/src/regexp.rs | 3 +- sqlx-sqlite/src/statement/handle.rs | 3 +- sqlx-sqlite/src/statement/virtual.rs | 2 +- sqlx-sqlite/src/type_info.rs | 2 +- sqlx-sqlite/src/value.rs | 3 +- 19 files changed, 155 insertions(+), 16 deletions(-) create mode 100644 examples/sqlite/todos-wasm/Cargo.toml create mode 100644 examples/sqlite/todos-wasm/README.md create mode 100644 examples/sqlite/todos-wasm/migrations/20200718111257_todos.sql create mode 100644 examples/sqlite/todos-wasm/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index 9c37eb4a5d..525e447d3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ members = [ "examples/postgres/transaction", "examples/sqlite/todos", "examples/sqlite/extension", + "examples/sqlite/todos-wasm", ] [workspace.package] @@ -117,6 +118,7 @@ any = ["sqlx-core/any", "sqlx-mysql?/any", "sqlx-postgres?/any", "sqlx-sqlite?/a postgres = ["sqlx-postgres", "sqlx-macros?/postgres"] mysql = ["sqlx-mysql", "sqlx-macros?/mysql"] sqlite = ["sqlite-bundled", "sqlite-deserialize", "sqlite-load-extension", "sqlite-unlock-notify"] +sqlite-wasm = ["_sqlite", "sqlite-deserialize", "sqlx-sqlite/wasm", "sqlx-macros?/sqlite"] # SQLite base features sqlite-bundled = ["_sqlite", "sqlx-sqlite/bundled", "sqlx-macros?/sqlite"] diff --git a/examples/sqlite/todos-wasm/Cargo.toml b/examples/sqlite/todos-wasm/Cargo.toml new file mode 100644 index 0000000000..4262bb3802 --- /dev/null +++ b/examples/sqlite/todos-wasm/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "sqlx-example-sqlite-todos-wasm" +version = "0.1.0" +edition = "2018" +workspace = "../../../" + +[dependencies] +anyhow = "1.0" +sqlx = { path = "../../../", features = [ "sqlite-wasm", "tls-none" ] } +tokio = { version = "1.20.0", features = ["rt", "macros"]} diff --git a/examples/sqlite/todos-wasm/README.md b/examples/sqlite/todos-wasm/README.md new file mode 100644 index 0000000000..8bbb4d15be --- /dev/null +++ b/examples/sqlite/todos-wasm/README.md @@ -0,0 +1,41 @@ +# TODOs Example + +## Setup + +1. Declare the database URL + + ``` + export DATABASE_URL="sqlite:todos.db" + ``` + +2. Create the database. + + ``` + $ sqlx db create + ``` + +3. Run sql migrations + + ``` + $ sqlx migrate run + ``` + +## Usage + +Add a todo + +``` +cargo run -- add "todo description" +``` + +Complete a todo. + +``` +cargo run -- done +``` + +List all todos + +``` +cargo run +``` diff --git a/examples/sqlite/todos-wasm/migrations/20200718111257_todos.sql b/examples/sqlite/todos-wasm/migrations/20200718111257_todos.sql new file mode 100644 index 0000000000..5248bb9a44 --- /dev/null +++ b/examples/sqlite/todos-wasm/migrations/20200718111257_todos.sql @@ -0,0 +1,6 @@ +CREATE TABLE IF NOT EXISTS todos +( + id INTEGER PRIMARY KEY NOT NULL, + description TEXT NOT NULL, + done BOOLEAN NOT NULL DEFAULT 0 +); diff --git a/examples/sqlite/todos-wasm/src/main.rs b/examples/sqlite/todos-wasm/src/main.rs new file mode 100644 index 0000000000..4f7a3c6e03 --- /dev/null +++ b/examples/sqlite/todos-wasm/src/main.rs @@ -0,0 +1,67 @@ +use sqlx::sqlite::SqlitePool; + +const DATABASE_URL: &str = "file:session?vfs=kvvs"; + +#[tokio::main(flavor = "current_thread")] +async fn main() -> anyhow::Result<()> { + let pool = SqlitePool::connect(DATABASE_URL).await?; + + Ok(()) +} + +async fn add_todo(pool: &SqlitePool, description: String) -> anyhow::Result { + let mut conn = pool.acquire().await?; + + // Insert the task, then obtain the ID of this row + let id = sqlx::query!( + r#" +INSERT INTO todos ( description ) +VALUES ( ?1 ) + "#, + description + ) + .execute(&mut *conn) + .await? + .last_insert_rowid(); + + Ok(id) +} + +async fn complete_todo(pool: &SqlitePool, id: i64) -> anyhow::Result { + let rows_affected = sqlx::query!( + r#" +UPDATE todos +SET done = TRUE +WHERE id = ?1 + "#, + id + ) + .execute(pool) + .await? + .rows_affected(); + + Ok(rows_affected > 0) +} + +async fn list_todos(pool: &SqlitePool) -> anyhow::Result<()> { + let recs = sqlx::query!( + r#" +SELECT id, description, done +FROM todos +ORDER BY id + "# + ) + .fetch_all(pool) + .await?; + + for rec in recs { + println!( + "- [{}] {}: {}", + if rec.done { "x" } else { " " }, + rec.id, + &rec.description, + ); + } + + Ok(()) +} diff --git a/sqlx-sqlite/Cargo.toml b/sqlx-sqlite/Cargo.toml index 4508e19ff6..689e9e1302 100644 --- a/sqlx-sqlite/Cargo.toml +++ b/sqlx-sqlite/Cargo.toml @@ -25,11 +25,12 @@ regexp = ["dep:regex"] # Conditionally compiled SQLite features deserialize = [] load-extension = [] -preupdate-hook = ["libsqlite3-sys/preupdate_hook"] -unlock-notify = ["libsqlite3-sys/unlock_notify"] +preupdate-hook = ["libsqlite3-sys?/preupdate_hook"] +unlock-notify = ["libsqlite3-sys?/unlock_notify"] -bundled = ["libsqlite3-sys/bundled"] -unbundled = ["libsqlite3-sys/buildtime_bindgen"] +bundled = ["dep:libsqlite3-sys", "libsqlite3-sys/bundled"] +unbundled = ["dep:libsqlite3-sys", "libsqlite3-sys/buildtime_bindgen"] +wasm = ["dep:sqlite-wasm-rs"] sqlx-toml = ["sqlx-core/sqlx-toml"] @@ -56,6 +57,7 @@ _unstable-docs = [ [dependencies.libsqlite3-sys] # See `sqlx-sqlite/src/lib.rs` for details. +optional = true version = ">=0.30.0, <0.36.0" default-features = false features = [ @@ -89,6 +91,7 @@ thiserror = "2.0.0" serde = { version = "1.0.145", features = ["derive"], optional = true } regex = { version = "1.5.5", optional = true } +sqlite-wasm-rs = { version = "0.4.3", default-features = false, features = ["precompiled"], optional = true } [dependencies.sqlx-core] workspace = true diff --git a/sqlx-sqlite/src/arguments.rs b/sqlx-sqlite/src/arguments.rs index 6354cbebc9..6b48300e6a 100644 --- a/sqlx-sqlite/src/arguments.rs +++ b/sqlx-sqlite/src/arguments.rs @@ -3,7 +3,9 @@ use crate::error::Error; use crate::statement::StatementHandle; use crate::Sqlite; use atoi::atoi; -use libsqlite3_sys::SQLITE_OK; + +use crate::sqlite_lib::SQLITE_OK; + use std::sync::Arc; pub(crate) use sqlx_core::arguments::*; diff --git a/sqlx-sqlite/src/connection/collation.rs b/sqlx-sqlite/src/connection/collation.rs index e7422138bc..0b56728f5b 100644 --- a/sqlx-sqlite/src/connection/collation.rs +++ b/sqlx-sqlite/src/connection/collation.rs @@ -6,7 +6,7 @@ use std::slice; use std::str::from_utf8_unchecked; use std::sync::Arc; -use libsqlite3_sys::{sqlite3_create_collation_v2, SQLITE_OK, SQLITE_UTF8}; +use crate::sqlite_lib::{sqlite3_create_collation_v2, SQLITE_OK, SQLITE_UTF8}; use crate::connection::handle::ConnectionHandle; use crate::error::Error; diff --git a/sqlx-sqlite/src/connection/deserialize.rs b/sqlx-sqlite/src/connection/deserialize.rs index 5056eb6784..e37bd53b87 100644 --- a/sqlx-sqlite/src/connection/deserialize.rs +++ b/sqlx-sqlite/src/connection/deserialize.rs @@ -1,6 +1,6 @@ use super::ConnectionState; use crate::{error::Error, SqliteConnection, SqliteError}; -use libsqlite3_sys::{ +use crate::sqlite_lib::{ sqlite3_deserialize, sqlite3_free, sqlite3_malloc64, sqlite3_serialize, SQLITE_DESERIALIZE_FREEONCLOSE, SQLITE_DESERIALIZE_READONLY, SQLITE_DESERIALIZE_RESIZEABLE, SQLITE_NOMEM, SQLITE_OK, diff --git a/sqlx-sqlite/src/connection/establish.rs b/sqlx-sqlite/src/connection/establish.rs index d811275409..ab4c284049 100644 --- a/sqlx-sqlite/src/connection/establish.rs +++ b/sqlx-sqlite/src/connection/establish.rs @@ -3,7 +3,7 @@ use crate::connection::LogSettings; use crate::connection::{ConnectionState, Statements}; use crate::error::Error; use crate::SqliteConnectOptions; -use libsqlite3_sys::{ +use crate::sqlite_lib::{ sqlite3_busy_timeout, SQLITE_OPEN_CREATE, SQLITE_OPEN_FULLMUTEX, SQLITE_OPEN_MEMORY, SQLITE_OPEN_NOMUTEX, SQLITE_OPEN_PRIVATECACHE, SQLITE_OPEN_READONLY, SQLITE_OPEN_READWRITE, SQLITE_OPEN_SHAREDCACHE, SQLITE_OPEN_URI, diff --git a/sqlx-sqlite/src/connection/handle.rs b/sqlx-sqlite/src/connection/handle.rs index 7df3b1b717..5cfa52a3be 100644 --- a/sqlx-sqlite/src/connection/handle.rs +++ b/sqlx-sqlite/src/connection/handle.rs @@ -3,7 +3,7 @@ use std::ptr::NonNull; use std::{io, ptr}; use crate::error::Error; -use libsqlite3_sys::{ +use crate::sqlite_lib::{ sqlite3, sqlite3_close, sqlite3_exec, sqlite3_extended_result_codes, sqlite3_get_autocommit, sqlite3_last_insert_rowid, sqlite3_open_v2, SQLITE_OK, }; diff --git a/sqlx-sqlite/src/connection/mod.rs b/sqlx-sqlite/src/connection/mod.rs index 218c747143..78d140b6f8 100644 --- a/sqlx-sqlite/src/connection/mod.rs +++ b/sqlx-sqlite/src/connection/mod.rs @@ -9,7 +9,7 @@ use std::ptr; use std::ptr::NonNull; use futures_intrusive::sync::MutexGuard; -use libsqlite3_sys::{ +use crate::sqlite_lib::{ sqlite3, sqlite3_commit_hook, sqlite3_progress_handler, sqlite3_rollback_hook, sqlite3_update_hook, SQLITE_DELETE, SQLITE_INSERT, SQLITE_UPDATE, }; diff --git a/sqlx-sqlite/src/error.rs b/sqlx-sqlite/src/error.rs index b4373d7a07..9b8c2ff8f3 100644 --- a/sqlx-sqlite/src/error.rs +++ b/sqlx-sqlite/src/error.rs @@ -4,7 +4,7 @@ use std::fmt::{self, Display, Formatter}; use std::os::raw::c_int; use std::{borrow::Cow, str}; -use libsqlite3_sys::{ +use crate::sqlite_lib::{ sqlite3, sqlite3_errmsg, sqlite3_errstr, sqlite3_extended_errcode, SQLITE_CONSTRAINT_CHECK, SQLITE_CONSTRAINT_FOREIGNKEY, SQLITE_CONSTRAINT_NOTNULL, SQLITE_CONSTRAINT_PRIMARYKEY, SQLITE_CONSTRAINT_UNIQUE, SQLITE_ERROR, SQLITE_NOMEM, diff --git a/sqlx-sqlite/src/lib.rs b/sqlx-sqlite/src/lib.rs index 17b4bed1ca..51478d85d7 100644 --- a/sqlx-sqlite/src/lib.rs +++ b/sqlx-sqlite/src/lib.rs @@ -72,6 +72,11 @@ #[macro_use] extern crate sqlx_core; +#[cfg(not(feature = "wasm"))] +pub(crate) use libsqlite3_sys as sqlite_lib; +#[cfg(feature = "wasm")] +pub(crate) use sqlite_wasm_rs as sqlite_lib; + use std::sync::atomic::AtomicBool; pub use arguments::{SqliteArgumentValue, SqliteArguments, SqliteArgumentsBuffer}; diff --git a/sqlx-sqlite/src/regexp.rs b/sqlx-sqlite/src/regexp.rs index eb14fffc77..a91a481732 100644 --- a/sqlx-sqlite/src/regexp.rs +++ b/sqlx-sqlite/src/regexp.rs @@ -14,7 +14,8 @@ //! - //! - -use libsqlite3_sys as ffi; +use crate::sqlite_lib as ffi; + use log::error; use regex::Regex; use std::sync::Arc; diff --git a/sqlx-sqlite/src/statement/handle.rs b/sqlx-sqlite/src/statement/handle.rs index 7985ff9d36..c61d824664 100644 --- a/sqlx-sqlite/src/statement/handle.rs +++ b/sqlx-sqlite/src/statement/handle.rs @@ -4,7 +4,8 @@ use std::ffi::CStr; use crate::error::{BoxDynError, Error}; use crate::type_info::DataType; use crate::{SqliteError, SqliteTypeInfo}; -use libsqlite3_sys::{ + +use crate::sqlite_lib::{ sqlite3, sqlite3_bind_blob64, sqlite3_bind_double, sqlite3_bind_int, sqlite3_bind_int64, sqlite3_bind_null, sqlite3_bind_parameter_count, sqlite3_bind_parameter_name, sqlite3_bind_text64, sqlite3_changes, sqlite3_clear_bindings, sqlite3_column_blob, diff --git a/sqlx-sqlite/src/statement/virtual.rs b/sqlx-sqlite/src/statement/virtual.rs index b25aa69e47..25bb181d17 100644 --- a/sqlx-sqlite/src/statement/virtual.rs +++ b/sqlx-sqlite/src/statement/virtual.rs @@ -5,7 +5,7 @@ use std::os::raw::c_char; use std::ptr::{null, null_mut, NonNull}; use std::sync::Arc; -use libsqlite3_sys::{ +use crate::sqlite_lib::{ sqlite3, sqlite3_prepare_v3, sqlite3_stmt, SQLITE_OK, SQLITE_PREPARE_PERSISTENT, }; diff --git a/sqlx-sqlite/src/type_info.rs b/sqlx-sqlite/src/type_info.rs index 38a0fc4169..a22c4c6f8a 100644 --- a/sqlx-sqlite/src/type_info.rs +++ b/sqlx-sqlite/src/type_info.rs @@ -2,7 +2,7 @@ use std::fmt::{self, Display, Formatter}; use std::os::raw::c_int; use std::str::FromStr; -use libsqlite3_sys::{SQLITE_BLOB, SQLITE_FLOAT, SQLITE_INTEGER, SQLITE_NULL, SQLITE_TEXT}; +use crate::sqlite_lib::{SQLITE_BLOB, SQLITE_FLOAT, SQLITE_INTEGER, SQLITE_NULL, SQLITE_TEXT}; use crate::error::BoxDynError; diff --git a/sqlx-sqlite/src/value.rs b/sqlx-sqlite/src/value.rs index bdf376c187..c7653144c3 100644 --- a/sqlx-sqlite/src/value.rs +++ b/sqlx-sqlite/src/value.rs @@ -4,10 +4,11 @@ use std::ptr::NonNull; use std::slice; use std::str; -use libsqlite3_sys::{ +use crate::sqlite_lib::{ sqlite3_value, sqlite3_value_blob, sqlite3_value_bytes, sqlite3_value_double, sqlite3_value_dup, sqlite3_value_free, sqlite3_value_int64, sqlite3_value_type, }; + use sqlx_core::type_info::TypeInfo; pub(crate) use sqlx_core::value::{Value, ValueRef}; From 7fcbdd4f0cfb0904220f68720943e43460bb56ca Mon Sep 17 00:00:00 2001 From: highghlow Date: Sat, 23 Aug 2025 17:45:56 +0300 Subject: [PATCH 03/15] chore: Updated Cargo.lock --- Cargo.lock | 139 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 102 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 74f9054912..c30dd14403 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1374,9 +1374,9 @@ dependencies = [ [[package]] name = "fragile" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c2141d6d6c8512188a7891b4b01590a45f6dac67afb4f255c4124dbb86d4eaa" +checksum = "28dd6caf6059519a65843af8fe2a3ae298b14b80179855aeb4adc2c1934ee619" [[package]] name = "fs_extra" @@ -1698,7 +1698,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2", + "socket2 0.5.8", "tokio", "tower-service", "tracing", @@ -1925,6 +1925,17 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "io-uring" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "046fa2d4d00aea763528b4950358d0ead425372445dc8ff86312b3c69ff7727b" +dependencies = [ + "bitflags 2.7.0", + "cfg-if", + "libc", +] + [[package]] name = "ipnet" version = "2.10.1" @@ -1998,9 +2009,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.76" +version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6717b6b5b077764fb5966237269cb3c64edddde4b14ce42647430a78ced9e7b7" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" dependencies = [ "once_cell", "wasm-bindgen", @@ -2032,9 +2043,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.169" +version = "0.2.175" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" +checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" [[package]] name = "libloading" @@ -2363,9 +2374,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.20.2" +version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] name = "oorandom" @@ -3354,6 +3365,16 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "socket2" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "233504af464074f9d066d7b5416c5f9b894a5862a6506e306f7b816cdd6f1807" +dependencies = [ + "libc", + "windows-sys 0.59.0", +] + [[package]] name = "spin" version = "0.9.8" @@ -3373,6 +3394,24 @@ dependencies = [ "der", ] +[[package]] +name = "sqlite-wasm-rs" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0894a1b91dc660fbf1e6ea6f287562708e01ca1a18fa4e2c6dae0df5a05199c5" +dependencies = [ + "fragile", + "js-sys", + "once_cell", + "parking_lot", + "thiserror 2.0.16", + "tokio", + "wasm-array-cp", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + [[package]] name = "sqlx" version = "0.9.0-alpha.1" @@ -3465,7 +3504,7 @@ dependencies = [ "sha2", "smallvec", "sqlx", - "thiserror 2.0.11", + "thiserror 2.0.16", "time", "tokio", "tokio-stream", @@ -3500,7 +3539,7 @@ dependencies = [ "serde_json", "serde_with", "sqlx", - "thiserror 2.0.11", + "thiserror 2.0.16", "time", "tokio", "tower", @@ -3720,6 +3759,15 @@ dependencies = [ "tokio", ] +[[package]] +name = "sqlx-example-sqlite-todos-wasm" +version = "0.1.0" +dependencies = [ + "anyhow", + "sqlx", + "tokio", +] + [[package]] name = "sqlx-macros" version = "0.9.0-alpha.1" @@ -3792,7 +3840,7 @@ dependencies = [ "sqlx", "sqlx-core", "stringprep", - "thiserror 2.0.11", + "thiserror 2.0.16", "time", "tracing", "uuid", @@ -3837,7 +3885,7 @@ dependencies = [ "sqlx", "sqlx-core", "stringprep", - "thiserror 2.0.11", + "thiserror 2.0.16", "time", "tracing", "uuid", @@ -3862,9 +3910,10 @@ dependencies = [ "regex", "serde", "serde_urlencoded", + "sqlite-wasm-rs", "sqlx", "sqlx-core", - "thiserror 2.0.11", + "thiserror 2.0.16", "time", "tracing", "url", @@ -4127,11 +4176,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.11" +version = "2.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc" +checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0" dependencies = [ - "thiserror-impl 2.0.11", + "thiserror-impl 2.0.16", ] [[package]] @@ -4147,9 +4196,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.11" +version = "2.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2" +checksum = "6c5e1be1c48b9172ee610da68fd9cd2770e7a4056cb3fc98710ee6906f0c7960" dependencies = [ "proc-macro2", "quote", @@ -4234,20 +4283,22 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.43.0" +version = "1.47.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d61fa4ffa3de412bfea335c6ecff681de2b609ba3c77ef3e00e521813a9ed9e" +checksum = "89e49afdadebb872d3145a5638b59eb0691ea23e46ca484037cfab3b76b95038" dependencies = [ "backtrace", "bytes", + "io-uring", "libc", "mio 1.0.3", "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2", + "slab", + "socket2 0.6.0", "tokio-macros", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -4690,22 +4741,33 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" +[[package]] +name = "wasm-array-cp" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb633b3e235f0ebe0a35162adc1e0293fc4b7e3f3a6fc7b5374d80464267ff84" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "wasm-bindgen" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" dependencies = [ "cfg-if", "once_cell", + "rustversion", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" dependencies = [ "bumpalo", "log", @@ -4717,9 +4779,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.49" +version = "0.4.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38176d9b44ea84e9184eff0bc34cc167ed044f816accfe5922e54d84cf48eca2" +checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61" dependencies = [ "cfg-if", "js-sys", @@ -4730,9 +4792,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -4740,9 +4802,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ "proc-macro2", "quote", @@ -4753,15 +4815,18 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] [[package]] name = "web-sys" -version = "0.3.76" +version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04dd7223427d52553d3702c004d3b2fe07c148165faa56313cb00211e31c12bc" +checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" dependencies = [ "js-sys", "wasm-bindgen", From d146d9cb0de0fb8c9a2790ba4ae23c70adec9da0 Mon Sep 17 00:00:00 2001 From: highghlow Date: Sat, 23 Aug 2025 17:46:14 +0300 Subject: [PATCH 04/15] feat(examples:) Added locked and offline options to x.py --- examples/x.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/examples/x.py b/examples/x.py index 9d83bbe70c..bc8f6355d6 100755 --- a/examples/x.py +++ b/examples/x.py @@ -22,6 +22,8 @@ parser.add_argument("-p", "--project") parser.add_argument("-l", "--list-projects", action="store_true") parser.add_argument("-b", "--build", action="store_true") +parser.add_argument("--locked", action="store_true") +parser.add_argument("--offline", action="store_true") argv, unknown = parser.parse_known_args() @@ -78,12 +80,21 @@ def project(name, database=None, driver=None, target=None): # migrate sqlx("migrate run", database_url, cwd=cwd) - target_arg = "" if target is None else f" --target {target}" + args = "" + if target is not None: + args += f" --target {target}" + + if argv.locked: + args += " --locked" + + if argv.offline: + args += " --offline" + # check - run("cargo check" + target_arg, cwd=cwd, env=env) + run("cargo check" + args, cwd=cwd, env=env) if argv.build: - run("cargo build" + target_arg, cwd=cwd, env=env) + run("cargo build" + args, cwd=cwd, env=env) # todos @@ -91,3 +102,4 @@ def project(name, database=None, driver=None, target=None): project("postgres/todos", driver="postgres_12", database="todos") project("sqlite/todos", driver="sqlite", database="todos.db") project("sqlite/extension", driver="sqlite", database="extension.db") +project("sqlite/todos-wasm", driver="sqlite", database="wasm.db", target="wasm32-unknown-unknown") From bbe0334ba51f74ff26c32e5ee65dc2b94baa655b Mon Sep 17 00:00:00 2001 From: highghlow Date: Sat, 23 Aug 2025 19:09:13 +0300 Subject: [PATCH 05/15] fix(sqlite): Removed all remaining uses of libsqlite3-sys --- sqlx-sqlite/src/connection/establish.rs | 6 +++--- sqlx-sqlite/src/connection/mod.rs | 4 ++-- sqlx-sqlite/src/connection/preupdate_hook.rs | 2 +- sqlx-sqlite/src/statement/handle.rs | 2 +- sqlx-sqlite/src/statement/unlock_notify.rs | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sqlx-sqlite/src/connection/establish.rs b/sqlx-sqlite/src/connection/establish.rs index ab4c284049..d1f2c32dc4 100644 --- a/sqlx-sqlite/src/connection/establish.rs +++ b/sqlx-sqlite/src/connection/establish.rs @@ -163,7 +163,7 @@ impl EstablishParams { if self.register_regexp_function { // configure a `regexp` function for sqlite, it does not come with one by default let status = crate::regexp::register(handle.as_ptr()); - if status != libsqlite3_sys::SQLITE_OK { + if status != crate::sqlite_lib::SQLITE_OK { return Err(Error::Database(Box::new(handle.expect_error()))); } } @@ -193,7 +193,7 @@ impl EstablishParams { #[cfg(feature = "load-extension")] unsafe fn apply_extensions(&self, handle: &mut ConnectionHandle) -> Result<(), Error> { - use libsqlite3_sys::{sqlite3_free, sqlite3_load_extension}; + use crate::sqlite_lib::{sqlite3_free, sqlite3_load_extension}; use std::ffi::{c_int, CStr}; use std::ptr; @@ -202,7 +202,7 @@ impl EstablishParams { handle: &mut ConnectionHandle, enabled: bool, ) -> Result<(), Error> { - use libsqlite3_sys::{sqlite3_db_config, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION}; + use crate::sqlite_lib::{sqlite3_db_config, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION}; // SAFETY: we have exclusive access and this matches the expected signature // diff --git a/sqlx-sqlite/src/connection/mod.rs b/sqlx-sqlite/src/connection/mod.rs index 78d140b6f8..2d77cedc42 100644 --- a/sqlx-sqlite/src/connection/mod.rs +++ b/sqlx-sqlite/src/connection/mod.rs @@ -149,7 +149,7 @@ impl ConnectionState { pub(crate) fn remove_preupdate_hook(&mut self) { if let Some(mut handler) = self.preupdate_hook_callback.take() { unsafe { - libsqlite3_sys::sqlite3_preupdate_hook(self.handle.as_ptr(), None, ptr::null_mut()); + crate::sqlite_lib::sqlite3_preupdate_hook(self.handle.as_ptr(), None, ptr::null_mut()); let _ = { Box::from_raw(handler.0.as_mut()) }; } } @@ -457,7 +457,7 @@ impl LockedSqliteHandle<'_> { self.guard.remove_preupdate_hook(); self.guard.preupdate_hook_callback = Some(PreupdateHookHandler(callback)); - libsqlite3_sys::sqlite3_preupdate_hook( + crate::sqlite_lib::sqlite3_preupdate_hook( self.as_raw_handle().as_mut(), Some(preupdate_hook::), handler, diff --git a/sqlx-sqlite/src/connection/preupdate_hook.rs b/sqlx-sqlite/src/connection/preupdate_hook.rs index 2759588873..94b2b6ce49 100644 --- a/sqlx-sqlite/src/connection/preupdate_hook.rs +++ b/sqlx-sqlite/src/connection/preupdate_hook.rs @@ -1,7 +1,7 @@ use super::SqliteOperation; use crate::{SqliteError, SqliteValueRef}; -use libsqlite3_sys::{ +use crate::sqlite_lib::{ sqlite3, sqlite3_preupdate_count, sqlite3_preupdate_depth, sqlite3_preupdate_new, sqlite3_preupdate_old, sqlite3_value, SQLITE_OK, }; diff --git a/sqlx-sqlite/src/statement/handle.rs b/sqlx-sqlite/src/statement/handle.rs index c61d824664..5461f353af 100644 --- a/sqlx-sqlite/src/statement/handle.rs +++ b/sqlx-sqlite/src/statement/handle.rs @@ -399,7 +399,7 @@ impl StatementHandle { SQLITE_DONE => return Ok(false), SQLITE_MISUSE => panic!("misuse!"), #[cfg(feature = "unlock-notify")] - libsqlite3_sys::SQLITE_LOCKED_SHAREDCACHE => { + crate::sqlite_lib::SQLITE_LOCKED_SHAREDCACHE => { // The shared cache is locked by another connection. Wait for unlock // notification and try again. super::unlock_notify::wait(self.db_handle())?; diff --git a/sqlx-sqlite/src/statement/unlock_notify.rs b/sqlx-sqlite/src/statement/unlock_notify.rs index 5821c23ae3..7d05860df5 100644 --- a/sqlx-sqlite/src/statement/unlock_notify.rs +++ b/sqlx-sqlite/src/statement/unlock_notify.rs @@ -3,7 +3,7 @@ use std::os::raw::c_int; use std::slice; use std::sync::{Condvar, Mutex}; -use libsqlite3_sys::{sqlite3, sqlite3_unlock_notify, SQLITE_OK}; +use crate::sqlite_lib::{sqlite3, sqlite3_unlock_notify, SQLITE_OK}; use crate::SqliteError; From e18cc299f0f0c346ef409054f457ecc0304a2370 Mon Sep 17 00:00:00 2001 From: highghlow Date: Sat, 23 Aug 2025 19:44:04 +0300 Subject: [PATCH 06/15] feat!(sqlite): Now using target detection instead of a feature for sqlite --- Cargo.toml | 1 - examples/sqlite/todos-wasm/Cargo.toml | 2 +- sqlx-sqlite/Cargo.toml | 18 +++++++++--------- sqlx-sqlite/src/lib.rs | 5 +++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 525e447d3e..ab8a1d912f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -118,7 +118,6 @@ any = ["sqlx-core/any", "sqlx-mysql?/any", "sqlx-postgres?/any", "sqlx-sqlite?/a postgres = ["sqlx-postgres", "sqlx-macros?/postgres"] mysql = ["sqlx-mysql", "sqlx-macros?/mysql"] sqlite = ["sqlite-bundled", "sqlite-deserialize", "sqlite-load-extension", "sqlite-unlock-notify"] -sqlite-wasm = ["_sqlite", "sqlite-deserialize", "sqlx-sqlite/wasm", "sqlx-macros?/sqlite"] # SQLite base features sqlite-bundled = ["_sqlite", "sqlx-sqlite/bundled", "sqlx-macros?/sqlite"] diff --git a/examples/sqlite/todos-wasm/Cargo.toml b/examples/sqlite/todos-wasm/Cargo.toml index 4262bb3802..f57835524c 100644 --- a/examples/sqlite/todos-wasm/Cargo.toml +++ b/examples/sqlite/todos-wasm/Cargo.toml @@ -6,5 +6,5 @@ workspace = "../../../" [dependencies] anyhow = "1.0" -sqlx = { path = "../../../", features = [ "sqlite-wasm", "tls-none" ] } +sqlx = { path = "../../../", features = [ "sqlite", "tls-none" ] } tokio = { version = "1.20.0", features = ["rt", "macros"]} diff --git a/sqlx-sqlite/Cargo.toml b/sqlx-sqlite/Cargo.toml index 689e9e1302..28eac1441d 100644 --- a/sqlx-sqlite/Cargo.toml +++ b/sqlx-sqlite/Cargo.toml @@ -25,12 +25,11 @@ regexp = ["dep:regex"] # Conditionally compiled SQLite features deserialize = [] load-extension = [] -preupdate-hook = ["libsqlite3-sys?/preupdate_hook"] -unlock-notify = ["libsqlite3-sys?/unlock_notify"] +preupdate-hook = ["libsqlite3-sys/preupdate_hook"] +unlock-notify = ["libsqlite3-sys/unlock_notify"] -bundled = ["dep:libsqlite3-sys", "libsqlite3-sys/bundled"] -unbundled = ["dep:libsqlite3-sys", "libsqlite3-sys/buildtime_bindgen"] -wasm = ["dep:sqlite-wasm-rs"] +bundled = ["libsqlite3-sys/bundled"] +unbundled = ["libsqlite3-sys/buildtime_bindgen"] sqlx-toml = ["sqlx-core/sqlx-toml"] @@ -52,12 +51,11 @@ _unstable-all-sqlite-features = [ _unstable-docs = [ "bundled", "any", "_unstable-all-types", - "_unstable-all-sqlite-features" + "_unstable-all-sqlite-features", ] -[dependencies.libsqlite3-sys] +[target.'cfg(not(any(target_os = "wasi", target_os = "emscripten")))'.dependencies.libsqlite3-sys] # See `sqlx-sqlite/src/lib.rs` for details. -optional = true version = ">=0.30.0, <0.36.0" default-features = false features = [ @@ -65,6 +63,9 @@ features = [ "vcpkg", ] +[target.'cfg(any(target_os = "wasi", target_os = "emscripten"))'.dependencies] +sqlite-wasm-rs = { version = "0.4.3", default-features = false, features = ["precompiled"] } + [dependencies] futures-core = { version = "0.3.19", default-features = false } futures-channel = { version = "0.3.19", default-features = false, features = ["sink", "alloc", "std"] } @@ -91,7 +92,6 @@ thiserror = "2.0.0" serde = { version = "1.0.145", features = ["derive"], optional = true } regex = { version = "1.5.5", optional = true } -sqlite-wasm-rs = { version = "0.4.3", default-features = false, features = ["precompiled"], optional = true } [dependencies.sqlx-core] workspace = true diff --git a/sqlx-sqlite/src/lib.rs b/sqlx-sqlite/src/lib.rs index 51478d85d7..e77552913a 100644 --- a/sqlx-sqlite/src/lib.rs +++ b/sqlx-sqlite/src/lib.rs @@ -72,9 +72,10 @@ #[macro_use] extern crate sqlx_core; -#[cfg(not(feature = "wasm"))] +#[cfg(not(any(target_os = "wasi", target_os = "emscripten")))] pub(crate) use libsqlite3_sys as sqlite_lib; -#[cfg(feature = "wasm")] + +#[cfg(any(target_os = "wasi", target_os = "emscripten"))] pub(crate) use sqlite_wasm_rs as sqlite_lib; use std::sync::atomic::AtomicBool; From 158031aeac0193746a0dedeb82e94b755ed4904a Mon Sep 17 00:00:00 2001 From: highghlow Date: Sat, 23 Aug 2025 19:47:55 +0300 Subject: [PATCH 07/15] chore: Ran cargo fmt --- sqlx-sqlite/src/connection/deserialize.rs | 2 +- sqlx-sqlite/src/connection/establish.rs | 2 +- sqlx-sqlite/src/connection/mod.rs | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/sqlx-sqlite/src/connection/deserialize.rs b/sqlx-sqlite/src/connection/deserialize.rs index e37bd53b87..ab67074fec 100644 --- a/sqlx-sqlite/src/connection/deserialize.rs +++ b/sqlx-sqlite/src/connection/deserialize.rs @@ -1,10 +1,10 @@ use super::ConnectionState; -use crate::{error::Error, SqliteConnection, SqliteError}; use crate::sqlite_lib::{ sqlite3_deserialize, sqlite3_free, sqlite3_malloc64, sqlite3_serialize, SQLITE_DESERIALIZE_FREEONCLOSE, SQLITE_DESERIALIZE_READONLY, SQLITE_DESERIALIZE_RESIZEABLE, SQLITE_NOMEM, SQLITE_OK, }; +use crate::{error::Error, SqliteConnection, SqliteError}; use std::ffi::c_char; use std::fmt::Debug; use std::{ diff --git a/sqlx-sqlite/src/connection/establish.rs b/sqlx-sqlite/src/connection/establish.rs index d1f2c32dc4..344667959d 100644 --- a/sqlx-sqlite/src/connection/establish.rs +++ b/sqlx-sqlite/src/connection/establish.rs @@ -2,12 +2,12 @@ use crate::connection::handle::ConnectionHandle; use crate::connection::LogSettings; use crate::connection::{ConnectionState, Statements}; use crate::error::Error; -use crate::SqliteConnectOptions; use crate::sqlite_lib::{ sqlite3_busy_timeout, SQLITE_OPEN_CREATE, SQLITE_OPEN_FULLMUTEX, SQLITE_OPEN_MEMORY, SQLITE_OPEN_NOMUTEX, SQLITE_OPEN_PRIVATECACHE, SQLITE_OPEN_READONLY, SQLITE_OPEN_READWRITE, SQLITE_OPEN_SHAREDCACHE, SQLITE_OPEN_URI, }; +use crate::SqliteConnectOptions; use percent_encoding::NON_ALPHANUMERIC; use std::collections::BTreeMap; use std::ffi::CString; diff --git a/sqlx-sqlite/src/connection/mod.rs b/sqlx-sqlite/src/connection/mod.rs index 2d77cedc42..ef2de5bb98 100644 --- a/sqlx-sqlite/src/connection/mod.rs +++ b/sqlx-sqlite/src/connection/mod.rs @@ -8,11 +8,11 @@ use std::panic::catch_unwind; use std::ptr; use std::ptr::NonNull; -use futures_intrusive::sync::MutexGuard; use crate::sqlite_lib::{ sqlite3, sqlite3_commit_hook, sqlite3_progress_handler, sqlite3_rollback_hook, sqlite3_update_hook, SQLITE_DELETE, SQLITE_INSERT, SQLITE_UPDATE, }; +use futures_intrusive::sync::MutexGuard; #[cfg(feature = "preupdate-hook")] pub use preupdate_hook::*; @@ -149,7 +149,11 @@ impl ConnectionState { pub(crate) fn remove_preupdate_hook(&mut self) { if let Some(mut handler) = self.preupdate_hook_callback.take() { unsafe { - crate::sqlite_lib::sqlite3_preupdate_hook(self.handle.as_ptr(), None, ptr::null_mut()); + crate::sqlite_lib::sqlite3_preupdate_hook( + self.handle.as_ptr(), + None, + ptr::null_mut(), + ); let _ = { Box::from_raw(handler.0.as_mut()) }; } } From f158e142c5f292700ddf383e52af9d09a4095bf8 Mon Sep 17 00:00:00 2001 From: highghlow Date: Sat, 23 Aug 2025 20:29:45 +0300 Subject: [PATCH 08/15] chore: Removed accidentally comitted flake --- flake.lock | 81 ------------------------------------------------------ flake.nix | 67 -------------------------------------------- 2 files changed, 148 deletions(-) delete mode 100644 flake.lock delete mode 100644 flake.nix diff --git a/flake.lock b/flake.lock deleted file mode 100644 index 1c50fe1cd3..0000000000 --- a/flake.lock +++ /dev/null @@ -1,81 +0,0 @@ -{ - "nodes": { - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1731533236, - "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1720535198, - "narHash": "sha256-zwVvxrdIzralnSbcpghA92tWu2DV2lwv89xZc8MTrbg=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "205fd4226592cc83fd4c0885a3e4c9c400efabb5", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "ref": "nixos-23.11", - "type": "indirect" - } - }, - "root": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs", - "rust-overlay": "rust-overlay" - } - }, - "rust-overlay": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1755830208, - "narHash": "sha256-fMa/Hcg+4O2h+kl3gNPjtGSWPI8NtCl3LYMsejK6qGA=", - "owner": "oxalica", - "repo": "rust-overlay", - "rev": "802a7b97f8ff672ba2dec70c9e354f51f844e796", - "type": "github" - }, - "original": { - "owner": "oxalica", - "repo": "rust-overlay", - "type": "github" - } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/flake.nix b/flake.nix deleted file mode 100644 index 4547e13569..0000000000 --- a/flake.nix +++ /dev/null @@ -1,67 +0,0 @@ -{ - description = "Rust with WebAssembly"; - - inputs = { - nixpkgs.url = "nixpkgs/nixos-23.11"; - flake-utils.url = "github:numtide/flake-utils"; - rust-overlay = { - url = "github:oxalica/rust-overlay"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - }; - - outputs = { self, rust-overlay, nixpkgs, flake-utils }: - flake-utils.lib.eachDefaultSystem - (system: - let - pkgs = import nixpkgs { - inherit system; - overlays = [ rust-overlay.overlays.default ]; - }; - in - { - devShells.default = - pkgs.mkShell rec { - name = "wasm-devshell"; - nativeBuildInputs = [ pkgs.pkg-config ]; - buildInputs = with pkgs; [ - clang - llvmPackages.bintools - nodejs_21 - wasm-pack - trunk - (rust-bin.stable.latest.default.override { - targets = [ "wasm32-unknown-unknown" ]; - }) - sqlx-cli - openssl - trunk - ]; - - # Add precompiled library to rustc search path - RUSTFLAGS = (builtins.map (a: ''-L ${a}/lib'') [ - pkgs.sqlite - ]); - - LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath (buildInputs ++ nativeBuildInputs); - - # Add glibc, clang, glib, and other headers to bindgen search path - BINDGEN_EXTRA_CLANG_ARGS = - # Includes normal include path - (builtins.map (a: ''-I"${a}/include"'') [ - pkgs.glibc.dev - pkgs.sqlite.dev - ]) - # Includes with special directory paths - ++ [ - ''-I"${pkgs.llvmPackages_latest.libclang.lib}/lib/clang/${pkgs.llvmPackages_latest.libclang.version}/include"'' - ''-I"${pkgs.glib.dev}/include/glib-2.0"'' - ''-I${pkgs.glib.out}/lib/glib-2.0/include/'' - ]; - - CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_LINKER = "lld"; - LIBCLANG_PATH = pkgs.lib.makeLibraryPath [ pkgs.llvmPackages_latest.libclang.lib ]; - }; - } - ); -} From 4e2909065b446de3b384c2574db965eee238d59b Mon Sep 17 00:00:00 2001 From: highghlow Date: Sat, 23 Aug 2025 20:52:00 +0300 Subject: [PATCH 09/15] fix: Removed the last use of sqlite3_sys (for real now) --- sqlx-sqlite/src/connection/handle.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlx-sqlite/src/connection/handle.rs b/sqlx-sqlite/src/connection/handle.rs index 5cfa52a3be..19e20019c2 100644 --- a/sqlx-sqlite/src/connection/handle.rs +++ b/sqlx-sqlite/src/connection/handle.rs @@ -122,7 +122,7 @@ impl ConnectionHandle { match status { SQLITE_OK => return Ok(()), #[cfg(feature = "unlock-notify")] - libsqlite3_sys::SQLITE_LOCKED_SHAREDCACHE => { + crate::sqlite_lib::SQLITE_LOCKED_SHAREDCACHE => { crate::statement::unlock_notify::wait(self.as_ptr())? } _ => return Err(SqliteError::new(self.as_ptr()).into()), From e488a13494f8be761567e15a975b3cce78cdac89 Mon Sep 17 00:00:00 2001 From: highghlow Date: Sat, 23 Aug 2025 20:53:11 +0300 Subject: [PATCH 10/15] fix!: Fixed the WASM condition --- sqlx-sqlite/Cargo.toml | 4 ++-- sqlx-sqlite/src/lib.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sqlx-sqlite/Cargo.toml b/sqlx-sqlite/Cargo.toml index 28eac1441d..3c3e9c2bab 100644 --- a/sqlx-sqlite/Cargo.toml +++ b/sqlx-sqlite/Cargo.toml @@ -54,7 +54,7 @@ _unstable-docs = [ "_unstable-all-sqlite-features", ] -[target.'cfg(not(any(target_os = "wasi", target_os = "emscripten")))'.dependencies.libsqlite3-sys] +[target.'cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))'.dependencies.libsqlite3-sys] # See `sqlx-sqlite/src/lib.rs` for details. version = ">=0.30.0, <0.36.0" default-features = false @@ -63,7 +63,7 @@ features = [ "vcpkg", ] -[target.'cfg(any(target_os = "wasi", target_os = "emscripten"))'.dependencies] +[target.'cfg(any(target_arch = "wasm32", target_arch = "wasm64"))'.dependencies] sqlite-wasm-rs = { version = "0.4.3", default-features = false, features = ["precompiled"] } [dependencies] diff --git a/sqlx-sqlite/src/lib.rs b/sqlx-sqlite/src/lib.rs index e77552913a..9dff2d4b8b 100644 --- a/sqlx-sqlite/src/lib.rs +++ b/sqlx-sqlite/src/lib.rs @@ -72,10 +72,10 @@ #[macro_use] extern crate sqlx_core; -#[cfg(not(any(target_os = "wasi", target_os = "emscripten")))] +#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] pub(crate) use libsqlite3_sys as sqlite_lib; -#[cfg(any(target_os = "wasi", target_os = "emscripten"))] +#[cfg(any(target_arch = "wasm32", target_arch = "wasm64"))] pub(crate) use sqlite_wasm_rs as sqlite_lib; use std::sync::atomic::AtomicBool; From cc17d7164649a800ca6be997a1812d94c8090906 Mon Sep 17 00:00:00 2001 From: highghlow Date: Sat, 23 Aug 2025 20:53:28 +0300 Subject: [PATCH 11/15] fix: Added incompatibility warning --- sqlx-sqlite/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sqlx-sqlite/src/lib.rs b/sqlx-sqlite/src/lib.rs index 9dff2d4b8b..2fa18ff74d 100644 --- a/sqlx-sqlite/src/lib.rs +++ b/sqlx-sqlite/src/lib.rs @@ -78,6 +78,12 @@ pub(crate) use libsqlite3_sys as sqlite_lib; #[cfg(any(target_arch = "wasm32", target_arch = "wasm64"))] pub(crate) use sqlite_wasm_rs as sqlite_lib; +#[cfg(all( + feature = "load-extension", + any(target_arch = "wasm32", target_arch = "wasm64") +))] +compile_error!("Sqlite on WASM does not support `load-extension`"); + use std::sync::atomic::AtomicBool; pub use arguments::{SqliteArgumentValue, SqliteArguments, SqliteArgumentsBuffer}; From 73c2b90d5f9270e27f91cc2236d0c45bb34dfd08 Mon Sep 17 00:00:00 2001 From: highghlow Date: Sat, 23 Aug 2025 21:30:31 +0300 Subject: [PATCH 12/15] feat(sqlite): Added WASM example test --- .github/workflows/examples.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 4b405dfa02..783df88760 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -279,3 +279,13 @@ jobs: env: DATABASE_URL: sqlite://todos.sqlite run: cargo run -p sqlx-example-sqlite-todos + + - name: TODOs WASM (Setup) + env: + DATABASE_URL: sqlite://todos-wasm.sqlite + run: sqlx db setup --source=examples/sqlite/todos-wasm/migrations + + - name: TODOs WASM (Build) + env: + DATABASE_URL: sqlite://todos-wasm.sqlite + run: cargo build -p sqlx-example-sqlite-todos-wasm --target wasm32-unknown-unknown From 4ae22dc6389c5c3692c64caa13ff66b73ceca3ef Mon Sep 17 00:00:00 2001 From: highghlow Date: Sat, 23 Aug 2025 21:36:03 +0300 Subject: [PATCH 13/15] fix: Fixed the sqlite wasm example test --- .github/workflows/examples.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 783df88760..3aa9e580be 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -267,6 +267,9 @@ jobs: - name: Setup Rust run: rustup show active-toolchain || rustup toolchain install + + - name: Add wasm32-unknown-unknown toolchain + run: rutup target add wasm32-unknown-unknown - uses: Swatinem/rust-cache@v2 From 5d9aae930f87f451b30247390b2dc9a639ec6d11 Mon Sep 17 00:00:00 2001 From: highghlow Date: Sat, 23 Aug 2025 21:43:52 +0300 Subject: [PATCH 14/15] fix: Fixed the fix --- .github/workflows/examples.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 3aa9e580be..d87dd846e7 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -269,7 +269,7 @@ jobs: run: rustup show active-toolchain || rustup toolchain install - name: Add wasm32-unknown-unknown toolchain - run: rutup target add wasm32-unknown-unknown + run: rustup target add wasm32-unknown-unknown - uses: Swatinem/rust-cache@v2 From 7ea678c2b24a11e413565852bbfd2c1855b2c087 Mon Sep 17 00:00:00 2001 From: highghlow Date: Sun, 24 Aug 2025 12:11:45 +0300 Subject: [PATCH 15/15] fix: Fixed the todos-wasm example --- examples/sqlite/todos-wasm/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/sqlite/todos-wasm/Cargo.toml b/examples/sqlite/todos-wasm/Cargo.toml index f57835524c..decff7dae4 100644 --- a/examples/sqlite/todos-wasm/Cargo.toml +++ b/examples/sqlite/todos-wasm/Cargo.toml @@ -6,5 +6,5 @@ workspace = "../../../" [dependencies] anyhow = "1.0" -sqlx = { path = "../../../", features = [ "sqlite", "tls-none" ] } +sqlx = { path = "../../../", features = [ "sqlite-bundled", "sqlite-deserialize", "sqlite-unlock-notify", "tls-none" ] } tokio = { version = "1.20.0", features = ["rt", "macros"]}