From 09ad55308177957dc17556b722f89164ef35ae05 Mon Sep 17 00:00:00 2001 From: "Joshua C. Randall" Date: Mon, 24 Feb 2020 20:34:10 +0000 Subject: [PATCH] don't perform threading mode checks on wasm32 --- src/inner_connection.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/inner_connection.rs b/src/inner_connection.rs index 33245c8..5752144 100644 --- a/src/inner_connection.rs +++ b/src/inner_connection.rs @@ -6,7 +6,7 @@ use std::path::Path; use std::ptr; use std::str; use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::{Arc, Mutex, Once}; +use std::sync::{Arc, Mutex}; use super::ffi; use super::{str_for_sqlite, str_to_cstring}; @@ -324,7 +324,7 @@ impl Drop for InnerConnection { } #[cfg(not(feature = "bundled"))] -static SQLITE_VERSION_CHECK: Once = Once::new(); +static SQLITE_VERSION_CHECK: std::sync::Once = std::sync::Once::new(); #[cfg(not(feature = "bundled"))] pub static BYPASS_VERSION_CHECK: AtomicBool = AtomicBool::new(false); @@ -372,9 +372,25 @@ rusqlite was built against SQLite {} but the runtime SQLite version is {}. To fi }); } -static SQLITE_INIT: Once = Once::new(); +#[cfg(not(any( + target_arch = "wasm32" +)))] +static SQLITE_INIT: std::sync::Once = std::sync::Once::new(); + pub static BYPASS_SQLITE_INIT: AtomicBool = AtomicBool::new(false); +// threading mode checks are not necessary (and do not work) on target +// platforms that do not have threading (such as webassembly) +#[cfg(any( + target_arch = "wasm32" +))] +fn ensure_safe_sqlite_threading_mode() -> Result<()> { + Ok(()) +} + +#[cfg(not(any( + target_arch = "wasm32" +)))] fn ensure_safe_sqlite_threading_mode() -> Result<()> { // Ensure SQLite was compiled in thredsafe mode. if unsafe { ffi::sqlite3_threadsafe() == 0 } {