Add support for linking to winsqlite3

Signed-off-by: Nazar Mishturak <nazarmx@gmail.com>
This commit is contained in:
Nazar Mishturak 2020-08-18 01:33:50 +03:00 committed by Thom Chiovoloni
parent 4a54e118f0
commit bc9b40a444
4 changed files with 44 additions and 0 deletions

View File

@ -61,6 +61,7 @@ bundled-windows = ["libsqlite3-sys/bundled-windows"]
with-asan = ["libsqlite3-sys/with-asan"] with-asan = ["libsqlite3-sys/with-asan"]
column_decltype = [] column_decltype = []
wasm32-wasi-vfs = ["libsqlite3-sys/wasm32-wasi-vfs"] wasm32-wasi-vfs = ["libsqlite3-sys/wasm32-wasi-vfs"]
winsqlite3 = ["libsqlite3-sys/winsqlite3"]
# Helper feature for enabling both `bundled` and most non-build-related optional # Helper feature for enabling both `bundled` and most non-build-related optional
# features or dependencies. This is useful for running tests / clippy / etc. New # features or dependencies. This is useful for running tests / clippy / etc. New

View File

@ -33,6 +33,8 @@ session = ["preupdate_hook", "buildtime_bindgen"]
in_gecko = [] in_gecko = []
with-asan = [] with-asan = []
wasm32-wasi-vfs = [] wasm32-wasi-vfs = []
# lowest version shipped with Windows 10.0.10586 was 3.8.8.3
winsqlite3 = ["min_sqlite_version_3_7_16"]
[build-dependencies] [build-dependencies]
bindgen = { version = "0.55", optional = true, default-features = false, features = ["runtime"] } bindgen = { version = "0.55", optional = true, default-features = false, features = ["runtime"] }

View File

@ -245,6 +245,11 @@ mod build_linked {
// on is available, for example. // on is available, for example.
println!("cargo:link-target={}", link_lib); println!("cargo:link-target={}", link_lib);
if cfg!(all(windows, feature = "winsqlite3")) {
println!("cargo:rustc-link-lib=dylib={}", link_lib);
return HeaderLocation::Wrapper;
}
// Allow users to specify where to find SQLite. // Allow users to specify where to find SQLite.
if let Ok(dir) = env::var(format!("{}_LIB_DIR", env_prefix())) { if let Ok(dir) = env::var(format!("{}_LIB_DIR", env_prefix())) {
// Try to use pkg-config to determine link commands // Try to use pkg-config to determine link commands
@ -306,6 +311,8 @@ mod build_linked {
fn link_lib() -> &'static str { fn link_lib() -> &'static str {
if cfg!(feature = "sqlcipher") { if cfg!(feature = "sqlcipher") {
"sqlcipher" "sqlcipher"
} else if cfg!(all(windows, feature = "winsqlite3")) {
"winsqlite3"
} else { } else {
"sqlite3" "sqlite3"
} }
@ -386,6 +393,36 @@ mod bindings {
if cfg!(feature = "session") { if cfg!(feature = "session") {
bindings = bindings.clang_arg("-DSQLITE_ENABLE_SESSION"); bindings = bindings.clang_arg("-DSQLITE_ENABLE_SESSION");
} }
if cfg!(all(windows, feature = "winsqlite3")) {
bindings = bindings
.clang_arg("-DBINDGEN_USE_WINSQLITE3")
.blacklist_item("NTDDI_.+")
.blacklist_item("WINAPI_FAMILY.*")
.blacklist_item("_WIN32_.+")
.blacklist_item("_VCRT_COMPILER_PREPROCESSOR")
.blacklist_item("_SAL_VERSION")
.blacklist_item("__SAL_H_VERSION")
.blacklist_item("_USE_DECLSPECS_FOR_SAL")
.blacklist_item("_USE_ATTRIBUTES_FOR_SAL")
.blacklist_item("_CRT_PACKING")
.blacklist_item("_HAS_EXCEPTIONS")
.blacklist_item("_STL_LANG")
.blacklist_item("_HAS_CXX17")
.blacklist_item("_HAS_CXX20")
.blacklist_item("_HAS_NODISCARD")
.blacklist_item("WDK_NTDDI_VERSION")
.blacklist_item("OSVERSION_MASK")
.blacklist_item("SPVERSION_MASK")
.blacklist_item("SUBVERSION_MASK")
.blacklist_item("WINVER")
.blacklist_item("__security_cookie")
.blacklist_type("size_t")
.blacklist_type("__vcrt_bool")
.blacklist_type("wchar_t")
.blacklist_function("__security_init_cookie")
.blacklist_function("__report_gsfailure")
.blacklist_function("__va_start");
}
// When cross compiling unless effort is taken to fix the issue, bindgen // When cross compiling unless effort is taken to fix the issue, bindgen
// will find the wrong headers. There's only one header included by the // will find the wrong headers. There's only one header included by the

View File

@ -1 +1,5 @@
#ifdef BINDGEN_USE_WINSQLITE3
#include <winsqlite/winsqlite3.h>
#else
#include "sqlite3.h" #include "sqlite3.h"
#endif