Skip to content

Commit 691efb1

Browse files
authored
Add no_std support for sqlite-wasm-rs (#149)
* Move `sahpool` vfs to `sqlite-wasm-vfs` crate * Added `no_std` support for `sqlite-wasm-rs` * Add changelog
1 parent ae12cd9 commit 691efb1

22 files changed

Lines changed: 5466 additions & 5527 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
* New crate `sqlite-wasm-vfs`: some experimental VFS implementations.
99
[#146](https://github.com/Spxg/sqlite-wasm-rs/pull/146)
1010

11+
* Added `no_std` support for `sqlite-wasm-rs`.
12+
[#149](https://github.com/Spxg/sqlite-wasm-rs/pull/149)
13+
1114
### Fixed
1215

1316
### Changed
@@ -24,6 +27,9 @@
2427
* Bump MSRV to 1.82.0.
2528
[#148](https://github.com/Spxg/sqlite-wasm-rs/pull/148)
2629

30+
* Moved `opfs-sahpool` vfs to `sqlite-wasm-vfs`.
31+
[#149](https://github.com/Spxg/sqlite-wasm-rs/pull/149)
32+
2733
--------------------------------------------------------------------------------
2834

2935
## [0.4.8](https://github.com/Spxg/sqlite-wasm-rs/compare/0.4.7...0.4.8)

Cargo.toml

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,10 @@ include = [
2828
]
2929

3030
[dependencies]
31-
tokio = { version = "1.45.1", features = ["sync"] }
32-
thiserror = "2.0.12"
33-
34-
wasm-bindgen = "0.2.104"
35-
wasm-bindgen-futures = "0.4.54"
36-
js-sys = "0.3.81"
37-
web-sys = { version = "0.3.81", features = [
38-
"StorageManager",
39-
"FileSystemSyncAccessHandle",
40-
"FileSystemDirectoryHandle",
41-
"FileSystemGetDirectoryOptions",
42-
"FileSystemReadWriteOptions",
43-
"WorkerGlobalScope",
44-
"WorkerNavigator",
45-
"FileSystemGetFileOptions",
46-
"FileSystemFileHandle",
47-
]}
31+
wasm-bindgen = { version = "0.2.104", default-features = false }
32+
js-sys = { version = "0.3.81", default-features = false }
33+
thiserror = { version = "2.0.12", default-features = false }
34+
hashbrown = { version = "0.16.1", default-features = false, features = ["default-hasher"] }
4835

4936
[features]
5037
# SQLite3MultipleCiphers

README.md

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ sqlite-wasm-rs = { version = "0.5", features = ["sqlite3mc"] }
1919
```
2020

2121
```rust
22-
use sqlite_wasm_rs::{
23-
self as ffi,
24-
sahpool_vfs::{install as install_opfs_sahpool, OpfsSAHPoolCfg},
25-
};
22+
use sqlite_wasm_rs as ffi;
2623

2724
async fn open_db() {
2825
// open with memory vfs
@@ -36,23 +33,6 @@ async fn open_db() {
3633
)
3734
};
3835
assert_eq!(ffi::SQLITE_OK, ret);
39-
40-
// install opfs-sahpool persistent vfs and set as default vfs
41-
install_opfs_sahpool(&OpfsSAHPoolCfg::default(), true)
42-
.await
43-
.unwrap();
44-
45-
// open with opfs-sahpool vfs
46-
let mut db = std::ptr::null_mut();
47-
let ret = unsafe {
48-
ffi::sqlite3_open_v2(
49-
c"opfs-sahpool.db".as_ptr().cast(),
50-
&mut db as *mut _,
51-
ffi::SQLITE_OPEN_READWRITE | ffi::SQLITE_OPEN_CREATE,
52-
std::ptr::null()
53-
)
54-
};
55-
assert_eq!(ffi::SQLITE_OK, ret);
5636
}
5737
```
5838

build.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ fn main() {
5555

5656
if update_bindgen {
5757
#[cfg(not(feature = "sqlite3mc"))]
58-
const SQLITE3_BINDGEN: &str = "src/libsqlite3/sqlite3_bindgen.rs";
58+
const SQLITE3_BINDGEN: &str = "src/bindings/sqlite3_bindgen.rs";
5959
#[cfg(feature = "sqlite3mc")]
60-
const SQLITE3_BINDGEN: &str = "src/libsqlite3/sqlite3mc_bindgen.rs";
60+
const SQLITE3_BINDGEN: &str = "src/bindings/sqlite3mc_bindgen.rs";
6161
std::fs::copy(&output, SQLITE3_BINDGEN).unwrap();
6262
}
6363
}
@@ -102,28 +102,28 @@ fn bindgen(output: &std::path::PathBuf) {
102102
.raw_line(
103103
r#"extern "C" {
104104
pub fn sqlite3_auto_extension(
105-
xEntryPoint: ::std::option::Option<
105+
xEntryPoint: ::core::option::Option<
106106
unsafe extern "C" fn(
107107
db: *mut sqlite3,
108-
pzErrMsg: *mut *mut ::std::os::raw::c_char,
108+
pzErrMsg: *mut *mut ::core::ffi::c_char,
109109
_: *const sqlite3_api_routines,
110-
) -> ::std::os::raw::c_int,
110+
) -> ::core::ffi::c_int,
111111
>,
112-
) -> ::std::os::raw::c_int;
112+
) -> ::core::ffi::c_int;
113113
}"#,
114114
)
115115
.blocklist_function("sqlite3_cancel_auto_extension")
116116
.raw_line(
117117
r#"extern "C" {
118118
pub fn sqlite3_cancel_auto_extension(
119-
xEntryPoint: ::std::option::Option<
119+
xEntryPoint: ::core::option::Option<
120120
unsafe extern "C" fn(
121121
db: *mut sqlite3,
122-
pzErrMsg: *mut *mut ::std::os::raw::c_char,
122+
pzErrMsg: *mut *mut ::core::ffi::c_char,
123123
_: *const sqlite3_api_routines,
124-
) -> ::std::os::raw::c_int,
124+
) -> ::core::ffi::c_int,
125125
>,
126-
) -> ::std::os::raw::c_int;
126+
) -> ::core::ffi::c_int;
127127
}"#,
128128
)
129129
// Block functions related to dynamic library loading, which is not available.
@@ -160,6 +160,7 @@ fn bindgen(output: &std::path::PathBuf) {
160160

161161
let bindings = bindings
162162
.layout_tests(false)
163+
.use_core()
163164
.formatter(bindgen::Formatter::Prettyplease)
164165
.generate()
165166
.unwrap();

crates/sqlite-wasm-vfs/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ js-sys = "0.3.81"
1818
wasm-bindgen-futures = "0.4.54"
1919
tokio = { version = "1.45.1", features = ["sync"] }
2020
thiserror = "2.0.12"
21+
web-sys = { version = "0.3.81", features = [
22+
"StorageManager",
23+
"FileSystemSyncAccessHandle",
24+
"FileSystemDirectoryHandle",
25+
"FileSystemGetDirectoryOptions",
26+
"FileSystemReadWriteOptions",
27+
"WorkerGlobalScope",
28+
"WorkerNavigator",
29+
"FileSystemGetFileOptions",
30+
"FileSystemFileHandle",
31+
]}
32+
2133
indexed_db_futures = { version = "0.6.4", optional = true }
2234

2335
[dev-dependencies]

crates/sqlite-wasm-vfs/LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../LICENSE

crates/sqlite-wasm-vfs/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@
77
#[cfg(feature = "relaxed-idb")]
88
pub mod relaxed_idb;
99

10+
/// Origin Private File System (OPFS) VFS implementation using `SyncAccessHandle`.
11+
pub mod sahpool;
12+
1013
#[cfg(test)]
1114
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_dedicated_worker);
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
//! See [`opfs-sahpool`](https://sqlite.org/wasm/doc/trunk/persistence.md#vfs-opfs-sahpool) for details.
44
//!
55
//! ```rust
6-
//! use sqlite_wasm_rs::{
7-
//! self as ffi,
8-
//! sahpool_vfs::{install as install_opfs_sahpool, OpfsSAHPoolCfg},
9-
//! };
6+
//! use sqlite_wasm_rs as ffi;
7+
//! use sqlite_wasm_vfs::sahpool::{install as install_opfs_sahpool, OpfsSAHPoolCfg};
108
//!
119
//! async fn open_db() {
1210
//! // install opfs-sahpool persistent vfs and set as default vfs
@@ -34,15 +32,19 @@
3432
//! [`opfs-explorer`](https://chromewebstore.google.com/detail/opfs-explorer/acndjpgkpaclldomagafnognkcgjignd)
3533
//! plugin to browse files.
3634
37-
use crate::libsqlite3::*;
38-
use crate::vfs::utils::{
35+
use sqlite_wasm_rs::utils::{
3936
check_import_db, random_name, register_vfs, registered_vfs, ImportDbError, RegisterVfsError,
40-
SQLiteIoMethods, SQLiteVfs, VfsAppData, VfsError, VfsFile, VfsResult, VfsStore,
37+
SQLiteIoMethods, SQLiteVfs, SQLiteVfsFile, VfsAppData, VfsError, VfsFile, VfsResult, VfsStore,
38+
};
39+
use sqlite_wasm_rs::{
40+
sqlite3_file, sqlite3_filename, sqlite3_vfs, sqlite3_vfs_register, sqlite3_vfs_unregister,
41+
SQLITE_CANTOPEN, SQLITE_ERROR, SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN, SQLITE_IOERR,
42+
SQLITE_IOERR_DELETE, SQLITE_OK, SQLITE_OPEN_DELETEONCLOSE, SQLITE_OPEN_MAIN_DB,
43+
SQLITE_OPEN_MAIN_JOURNAL, SQLITE_OPEN_SUPER_JOURNAL, SQLITE_OPEN_WAL,
4144
};
4245
use std::cell::{Cell, RefCell};
4346
use std::collections::{HashMap, HashSet};
4447

45-
use crate::utils::SQLiteVfsFile;
4648
use js_sys::{Array, DataView, IteratorNext, Reflect, Uint8Array};
4749
use wasm_bindgen::{JsCast, JsValue};
4850
use wasm_bindgen_futures::JsFuture;
@@ -605,7 +607,7 @@ impl VfsStore<SyncAccessFile, SyncAccessHandleAppData> for SyncAccessHandleStore
605607
}
606608

607609
fn with_file<F: Fn(&SyncAccessFile) -> VfsResult<i32>>(
608-
vfs_file: &super::utils::SQLiteVfsFile,
610+
vfs_file: &SQLiteVfsFile,
609611
f: F,
610612
) -> VfsResult<i32> {
611613
let name = unsafe { vfs_file.name() };
@@ -615,7 +617,7 @@ impl VfsStore<SyncAccessFile, SyncAccessHandleAppData> for SyncAccessHandleStore
615617
}
616618

617619
fn with_file_mut<F: Fn(&mut SyncAccessFile) -> VfsResult<i32>>(
618-
vfs_file: &super::utils::SQLiteVfsFile,
620+
vfs_file: &SQLiteVfsFile,
619621
f: F,
620622
) -> VfsResult<i32> {
621623
let name = unsafe { vfs_file.name() };
@@ -951,13 +953,11 @@ pub async fn install(options: &OpfsSAHPoolCfg, default_vfs: bool) -> Result<Opfs
951953

952954
#[cfg(test)]
953955
mod tests {
954-
use crate::{
955-
sahpool_vfs::{
956-
OpfsSAHPool, OpfsSAHPoolCfgBuilder, SyncAccessFile, SyncAccessHandleAppData,
957-
SyncAccessHandleStore,
958-
},
959-
utils::{test_suite::test_vfs_store, VfsAppData},
956+
use super::{
957+
OpfsSAHPool, OpfsSAHPoolCfgBuilder, SyncAccessFile, SyncAccessHandleAppData,
958+
SyncAccessHandleStore,
960959
};
960+
use sqlite_wasm_rs::utils::{test_suite::test_vfs_store, VfsAppData};
961961
use wasm_bindgen_test::wasm_bindgen_test;
962962

963963
#[wasm_bindgen_test]
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::error;
2-
use std::fmt;
3-
use std::os::raw::c_int;
1+
use core::error;
2+
use core::fmt;
3+
use core::ffi::c_int;
44

55
/// Error Codes
66
#[derive(Clone, Copy, Debug, PartialEq, Eq)]

0 commit comments

Comments
 (0)