Skip to content

Commit 459d51a

Browse files
committed
Remove rsqlite-vfs deps
1 parent 7f70e71 commit 459d51a

File tree

11 files changed

+334
-84
lines changed

11 files changed

+334
-84
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ jobs:
6464
cd rusqlite
6565
printf "[patch.crates-io]\n" >> Cargo.toml
6666
printf "sqlite-wasm-rs = { path = \"..\" }\n" >> Cargo.toml
67-
printf "libsqlite3-sys = { path = \"libsqlite3-sys\"}\n" >> Cargo.toml
6867
WASM_BINDGEN_TEST_TIMEOUT=60 wasm-pack test --node --features modern-full
6968
7069
test_clippy:

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ include = [
6464
'LICENSE',
6565
]
6666

67-
6867
[patch.crates-io]
6968
sqlite-wasm-rs = { path = "./" }
7069
sqlite-wasm-vfs = { path = "./crates/sqlite-wasm-vfs" }

crates/rsqlite-vfs/Cargo.toml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,5 @@ include.workspace = true
1111
hashbrown = { version = "0.16.1", default-features = false, features = ["default-hasher"] }
1212
thiserror = { version = "2.0.12", default-features = false }
1313

14-
[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dependencies]
15-
# libsqlite3-sys doesn't compile without features
16-
# see https://github.com/rusqlite/rusqlite/issues/1205
17-
libsqlite3-sys = { version = "0.36.0", default-features = false, features = ["vcpkg", "pkg-config"] }
18-
19-
[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies]
20-
wsqlite3-sys = { default-features = false, path = "../wsqlite3-sys" }
21-
2214
[dev-dependencies]
2315
rand = { version = "0.9" }

crates/rsqlite-vfs/src/ffi.rs

Lines changed: 274 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
1+
pub type sqlite3_int64 = ::core::ffi::c_longlong;
2+
pub type sqlite3_filename = *const ::core::ffi::c_char;
3+
pub type sqlite3_syscall_ptr = ::core::option::Option<unsafe extern "C" fn()>;
4+
5+
pub const SQLITE_CANTOPEN: i32 = 14;
6+
pub const SQLITE_ERROR: i32 = 1;
7+
pub const SQLITE_IOERR: i32 = 10;
8+
pub const SQLITE_IOERR_SHORT_READ: i32 = 522;
9+
pub const SQLITE_IOERR_DELETE: i32 = 2570;
10+
pub const SQLITE_OK: i32 = 0;
11+
pub const SQLITE_OPEN_DELETEONCLOSE: i32 = 8;
12+
pub const SQLITE_OPEN_MAIN_DB: i32 = 256;
13+
pub const SQLITE_OPEN_READWRITE: i32 = 2;
14+
pub const SQLITE_OPEN_CREATE: i32 = 4;
15+
pub const SQLITE_NOTFOUND: i32 = 12;
16+
17+
#[repr(C)]
18+
#[derive(Debug, Copy, Clone)]
19+
pub struct sqlite3_file {
20+
pub pMethods: *const sqlite3_io_methods,
21+
}
22+
23+
#[repr(C)]
24+
#[derive(Debug, Copy, Clone)]
25+
pub struct sqlite3_io_methods {
26+
pub iVersion: ::core::ffi::c_int,
27+
pub xClose: ::core::option::Option<
28+
unsafe extern "C" fn(arg1: *mut sqlite3_file) -> ::core::ffi::c_int,
29+
>,
30+
pub xRead: ::core::option::Option<
31+
unsafe extern "C" fn(
32+
arg1: *mut sqlite3_file,
33+
arg2: *mut ::core::ffi::c_void,
34+
iAmt: ::core::ffi::c_int,
35+
iOfst: sqlite3_int64,
36+
) -> ::core::ffi::c_int,
37+
>,
38+
pub xWrite: ::core::option::Option<
39+
unsafe extern "C" fn(
40+
arg1: *mut sqlite3_file,
41+
arg2: *const ::core::ffi::c_void,
42+
iAmt: ::core::ffi::c_int,
43+
iOfst: sqlite3_int64,
44+
) -> ::core::ffi::c_int,
45+
>,
46+
pub xTruncate: ::core::option::Option<
47+
unsafe extern "C" fn(
48+
arg1: *mut sqlite3_file,
49+
size: sqlite3_int64,
50+
) -> ::core::ffi::c_int,
51+
>,
52+
pub xSync: ::core::option::Option<
53+
unsafe extern "C" fn(
54+
arg1: *mut sqlite3_file,
55+
flags: ::core::ffi::c_int,
56+
) -> ::core::ffi::c_int,
57+
>,
58+
pub xFileSize: ::core::option::Option<
59+
unsafe extern "C" fn(
60+
arg1: *mut sqlite3_file,
61+
pSize: *mut sqlite3_int64,
62+
) -> ::core::ffi::c_int,
63+
>,
64+
pub xLock: ::core::option::Option<
65+
unsafe extern "C" fn(
66+
arg1: *mut sqlite3_file,
67+
arg2: ::core::ffi::c_int,
68+
) -> ::core::ffi::c_int,
69+
>,
70+
pub xUnlock: ::core::option::Option<
71+
unsafe extern "C" fn(
72+
arg1: *mut sqlite3_file,
73+
arg2: ::core::ffi::c_int,
74+
) -> ::core::ffi::c_int,
75+
>,
76+
pub xCheckReservedLock: ::core::option::Option<
77+
unsafe extern "C" fn(
78+
arg1: *mut sqlite3_file,
79+
pResOut: *mut ::core::ffi::c_int,
80+
) -> ::core::ffi::c_int,
81+
>,
82+
pub xFileControl: ::core::option::Option<
83+
unsafe extern "C" fn(
84+
arg1: *mut sqlite3_file,
85+
op: ::core::ffi::c_int,
86+
pArg: *mut ::core::ffi::c_void,
87+
) -> ::core::ffi::c_int,
88+
>,
89+
pub xSectorSize: ::core::option::Option<
90+
unsafe extern "C" fn(arg1: *mut sqlite3_file) -> ::core::ffi::c_int,
91+
>,
92+
pub xDeviceCharacteristics: ::core::option::Option<
93+
unsafe extern "C" fn(arg1: *mut sqlite3_file) -> ::core::ffi::c_int,
94+
>,
95+
pub xShmMap: ::core::option::Option<
96+
unsafe extern "C" fn(
97+
arg1: *mut sqlite3_file,
98+
iPg: ::core::ffi::c_int,
99+
pgsz: ::core::ffi::c_int,
100+
arg2: ::core::ffi::c_int,
101+
arg3: *mut *mut ::core::ffi::c_void,
102+
) -> ::core::ffi::c_int,
103+
>,
104+
pub xShmLock: ::core::option::Option<
105+
unsafe extern "C" fn(
106+
arg1: *mut sqlite3_file,
107+
offset: ::core::ffi::c_int,
108+
n: ::core::ffi::c_int,
109+
flags: ::core::ffi::c_int,
110+
) -> ::core::ffi::c_int,
111+
>,
112+
pub xShmBarrier: ::core::option::Option<
113+
unsafe extern "C" fn(arg1: *mut sqlite3_file),
114+
>,
115+
pub xShmUnmap: ::core::option::Option<
116+
unsafe extern "C" fn(
117+
arg1: *mut sqlite3_file,
118+
deleteFlag: ::core::ffi::c_int,
119+
) -> ::core::ffi::c_int,
120+
>,
121+
pub xFetch: ::core::option::Option<
122+
unsafe extern "C" fn(
123+
arg1: *mut sqlite3_file,
124+
iOfst: sqlite3_int64,
125+
iAmt: ::core::ffi::c_int,
126+
pp: *mut *mut ::core::ffi::c_void,
127+
) -> ::core::ffi::c_int,
128+
>,
129+
pub xUnfetch: ::core::option::Option<
130+
unsafe extern "C" fn(
131+
arg1: *mut sqlite3_file,
132+
iOfst: sqlite3_int64,
133+
p: *mut ::core::ffi::c_void,
134+
) -> ::core::ffi::c_int,
135+
>,
136+
}
137+
138+
#[repr(C)]
139+
#[derive(Debug, Copy, Clone)]
140+
pub struct sqlite3_vfs {
141+
pub iVersion: ::core::ffi::c_int,
142+
pub szOsFile: ::core::ffi::c_int,
143+
pub mxPathname: ::core::ffi::c_int,
144+
pub pNext: *mut sqlite3_vfs,
145+
pub zName: *const ::core::ffi::c_char,
146+
pub pAppData: *mut ::core::ffi::c_void,
147+
pub xOpen: ::core::option::Option<
148+
unsafe extern "C" fn(
149+
arg1: *mut sqlite3_vfs,
150+
zName: sqlite3_filename,
151+
arg2: *mut sqlite3_file,
152+
flags: ::core::ffi::c_int,
153+
pOutFlags: *mut ::core::ffi::c_int,
154+
) -> ::core::ffi::c_int,
155+
>,
156+
pub xDelete: ::core::option::Option<
157+
unsafe extern "C" fn(
158+
arg1: *mut sqlite3_vfs,
159+
zName: *const ::core::ffi::c_char,
160+
syncDir: ::core::ffi::c_int,
161+
) -> ::core::ffi::c_int,
162+
>,
163+
pub xAccess: ::core::option::Option<
164+
unsafe extern "C" fn(
165+
arg1: *mut sqlite3_vfs,
166+
zName: *const ::core::ffi::c_char,
167+
flags: ::core::ffi::c_int,
168+
pResOut: *mut ::core::ffi::c_int,
169+
) -> ::core::ffi::c_int,
170+
>,
171+
pub xFullPathname: ::core::option::Option<
172+
unsafe extern "C" fn(
173+
arg1: *mut sqlite3_vfs,
174+
zName: *const ::core::ffi::c_char,
175+
nOut: ::core::ffi::c_int,
176+
zOut: *mut ::core::ffi::c_char,
177+
) -> ::core::ffi::c_int,
178+
>,
179+
pub xDlOpen: ::core::option::Option<
180+
unsafe extern "C" fn(
181+
arg1: *mut sqlite3_vfs,
182+
zFilename: *const ::core::ffi::c_char,
183+
) -> *mut ::core::ffi::c_void,
184+
>,
185+
pub xDlError: ::core::option::Option<
186+
unsafe extern "C" fn(
187+
arg1: *mut sqlite3_vfs,
188+
nByte: ::core::ffi::c_int,
189+
zErrMsg: *mut ::core::ffi::c_char,
190+
),
191+
>,
192+
pub xDlSym: ::core::option::Option<
193+
unsafe extern "C" fn(
194+
arg1: *mut sqlite3_vfs,
195+
arg2: *mut ::core::ffi::c_void,
196+
zSymbol: *const ::core::ffi::c_char,
197+
) -> ::core::option::Option<
198+
unsafe extern "C" fn(
199+
arg1: *mut sqlite3_vfs,
200+
arg2: *mut ::core::ffi::c_void,
201+
zSymbol: *const ::core::ffi::c_char,
202+
),
203+
>,
204+
>,
205+
pub xDlClose: ::core::option::Option<
206+
unsafe extern "C" fn(arg1: *mut sqlite3_vfs, arg2: *mut ::core::ffi::c_void),
207+
>,
208+
pub xRandomness: ::core::option::Option<
209+
unsafe extern "C" fn(
210+
arg1: *mut sqlite3_vfs,
211+
nByte: ::core::ffi::c_int,
212+
zOut: *mut ::core::ffi::c_char,
213+
) -> ::core::ffi::c_int,
214+
>,
215+
pub xSleep: ::core::option::Option<
216+
unsafe extern "C" fn(
217+
arg1: *mut sqlite3_vfs,
218+
microseconds: ::core::ffi::c_int,
219+
) -> ::core::ffi::c_int,
220+
>,
221+
pub xCurrentTime: ::core::option::Option<
222+
unsafe extern "C" fn(
223+
arg1: *mut sqlite3_vfs,
224+
arg2: *mut f64,
225+
) -> ::core::ffi::c_int,
226+
>,
227+
pub xGetLastError: ::core::option::Option<
228+
unsafe extern "C" fn(
229+
arg1: *mut sqlite3_vfs,
230+
arg2: ::core::ffi::c_int,
231+
arg3: *mut ::core::ffi::c_char,
232+
) -> ::core::ffi::c_int,
233+
>,
234+
pub xCurrentTimeInt64: ::core::option::Option<
235+
unsafe extern "C" fn(
236+
arg1: *mut sqlite3_vfs,
237+
arg2: *mut sqlite3_int64,
238+
) -> ::core::ffi::c_int,
239+
>,
240+
pub xSetSystemCall: ::core::option::Option<
241+
unsafe extern "C" fn(
242+
arg1: *mut sqlite3_vfs,
243+
zName: *const ::core::ffi::c_char,
244+
arg2: sqlite3_syscall_ptr,
245+
) -> ::core::ffi::c_int,
246+
>,
247+
pub xGetSystemCall: ::core::option::Option<
248+
unsafe extern "C" fn(
249+
arg1: *mut sqlite3_vfs,
250+
zName: *const ::core::ffi::c_char,
251+
) -> sqlite3_syscall_ptr,
252+
>,
253+
pub xNextSystemCall: ::core::option::Option<
254+
unsafe extern "C" fn(
255+
arg1: *mut sqlite3_vfs,
256+
zName: *const ::core::ffi::c_char,
257+
) -> *const ::core::ffi::c_char,
258+
>,
259+
}
260+
261+
unsafe extern "C" {
262+
pub fn sqlite3_vfs_find(zVfsName: *const ::core::ffi::c_char) -> *mut sqlite3_vfs;
263+
}
264+
265+
unsafe extern "C" {
266+
pub fn sqlite3_vfs_register(
267+
arg1: *mut sqlite3_vfs,
268+
makeDflt: ::core::ffi::c_int,
269+
) -> ::core::ffi::c_int;
270+
}
271+
272+
unsafe extern "C" {
273+
pub fn sqlite3_vfs_unregister(arg1: *mut sqlite3_vfs) -> ::core::ffi::c_int;
274+
}

crates/rsqlite-vfs/src/lib.rs

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,22 @@
33
//! This crate also contains a simple operating system independent memvfs implementation
44
#![no_std]
55
#![allow(non_snake_case)]
6+
#![allow(non_camel_case_types)]
67

78
extern crate alloc;
89

9-
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
10-
extern crate libsqlite3_sys as bindings;
11-
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
12-
extern crate wsqlite3_sys as bindings;
13-
14-
use self::bindings::*;
15-
16-
// libsqlite3-sys misses this type
17-
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
18-
#[allow(non_camel_case_types)]
19-
type sqlite3_filename = *const ::core::ffi::c_char;
10+
/// sqlite3 types to implement VFS.
11+
#[rustfmt::skip]
12+
pub mod ffi;
13+
pub mod memvfs;
2014

2115
use alloc::string::String;
2216
use alloc::vec::Vec;
2317
use alloc::{boxed::Box, ffi::CString};
2418
use alloc::{format, vec};
2519
use core::time::Duration;
2620
use core::{cell::RefCell, ffi::CStr, ops::Deref};
27-
28-
pub mod memvfs;
21+
use ffi::*;
2922

3023
/// A macro to return a specific SQLite error code if a condition is true.
3124
///
@@ -456,6 +449,13 @@ pub trait VfsStore<File, AppData> {
456449
) -> VfsResult<i32>;
457450
}
458451

452+
/// Platform implementation
453+
pub trait OsCallback {
454+
fn sleep(dur: Duration);
455+
fn random(buf: &mut [u8]);
456+
fn epoch_timestamp_in_ms() -> i64;
457+
}
458+
459459
/// A trait that abstracts the `sqlite3_vfs` struct, allowing for a more idiomatic Rust implementation.
460460
#[allow(clippy::missing_safety_doc)]
461461
pub trait SQLiteVfs<IO: SQLiteIoMethods> {
@@ -1056,12 +1056,12 @@ pub mod test_suite {
10561056
}
10571057
}
10581058

1059-
#[cfg(all(test, target_arch = "wasm32"))]
1059+
#[cfg(test)]
10601060
mod tests {
1061-
use super::{MemChunksFile, VfsFile};
1062-
use wasm_bindgen_test::wasm_bindgen_test;
1061+
use crate::random_name;
1062+
use crate::{MemChunksFile, VfsFile};
10631063

1064-
#[wasm_bindgen_test]
1064+
#[test]
10651065
fn test_chunks_file() {
10661066
let mut file = MemChunksFile::new(512);
10671067
file.write(&[], 0).unwrap();
@@ -1109,17 +1109,16 @@ mod tests {
11091109
assert!(file.size().unwrap() == 0);
11101110
assert!(file.chunks.len() == 0);
11111111
}
1112-
}
11131112

1114-
#[cfg(not(all(test, target_arch = "wasm32")))]
1115-
#[test]
1116-
fn random_name_is_valid() {
1117-
fn random(buf: &mut [u8]) {
1118-
rand::fill(buf);
1113+
#[test]
1114+
fn random_name_is_valid() {
1115+
fn random(buf: &mut [u8]) {
1116+
rand::fill(buf);
1117+
}
1118+
let name_1 = random_name(random);
1119+
let name_2 = random_name(random);
1120+
assert!(name_1.is_ascii(), "Expected an ascii-name: `{name_1}`");
1121+
assert!(name_2.is_ascii(), "Expected an ascii-name: `{name_2}`");
1122+
assert_ne!(name_1, name_2);
11191123
}
1120-
let name_1 = random_name(random);
1121-
let name_2 = random_name(random);
1122-
assert!(name_1.is_ascii(), "Expected an ascii-name: `{name_1}`");
1123-
assert!(name_2.is_ascii(), "Expected an ascii-name: `{name_2}`");
1124-
assert_ne!(name_1, name_2);
11251124
}

0 commit comments

Comments
 (0)