2018-10-29 01:16:48 +08:00
|
|
|
use std::env;
|
|
|
|
use std::path::Path;
|
|
|
|
|
2017-03-04 03:57:40 +08:00
|
|
|
fn main() {
|
2018-10-29 01:16:48 +08:00
|
|
|
let out_dir = env::var("OUT_DIR").unwrap();
|
|
|
|
let out_path = Path::new(&out_dir).join("bindgen.rs");
|
2020-04-03 00:12:36 +08:00
|
|
|
if cfg!(feature = "in_gecko") {
|
|
|
|
// When inside mozilla-central, we are included into the build with
|
|
|
|
// sqlite3.o directly, so we don't want to provide any linker arguments.
|
|
|
|
std::fs::copy("sqlite3/bindgen_bundled_version.rs", out_path)
|
|
|
|
.expect("Could not copy bindings to output directory");
|
|
|
|
return;
|
|
|
|
}
|
2019-04-20 01:22:03 +08:00
|
|
|
if cfg!(feature = "sqlcipher") {
|
2019-06-26 02:40:28 +08:00
|
|
|
if cfg!(any(
|
|
|
|
feature = "bundled",
|
|
|
|
all(windows, feature = "bundled-windows")
|
|
|
|
)) {
|
2019-04-20 01:22:03 +08:00
|
|
|
println!(
|
2020-03-14 14:41:57 +08:00
|
|
|
"cargo:warning=Builds with bundled SQLCipher are not supported. Searching for SQLCipher to link against. \
|
2019-04-20 01:22:03 +08:00
|
|
|
This can lead to issues if your version of SQLCipher is not up to date!");
|
|
|
|
}
|
|
|
|
build_linked::main(&out_dir, &out_path)
|
|
|
|
} else {
|
2019-06-02 15:11:47 +08:00
|
|
|
// This can't be `cfg!` without always requiring our `mod build_bundled` (and
|
|
|
|
// thus `cc`)
|
2019-06-26 02:40:28 +08:00
|
|
|
#[cfg(any(feature = "bundled", all(windows, feature = "bundled-windows")))]
|
2019-04-20 01:22:03 +08:00
|
|
|
{
|
|
|
|
build_bundled::main(&out_dir, &out_path)
|
|
|
|
}
|
2019-06-26 02:40:28 +08:00
|
|
|
#[cfg(not(any(feature = "bundled", all(windows, feature = "bundled-windows"))))]
|
2019-04-20 01:22:03 +08:00
|
|
|
{
|
|
|
|
build_linked::main(&out_dir, &out_path)
|
|
|
|
}
|
|
|
|
}
|
2017-02-08 09:37:52 +08:00
|
|
|
}
|
|
|
|
|
2019-06-26 02:40:28 +08:00
|
|
|
#[cfg(any(feature = "bundled", all(windows, feature = "bundled-windows")))]
|
2019-04-20 01:22:03 +08:00
|
|
|
mod build_bundled {
|
2019-05-16 00:41:23 +08:00
|
|
|
use std::env;
|
2019-06-02 15:11:47 +08:00
|
|
|
use std::path::Path;
|
2017-02-09 10:41:34 +08:00
|
|
|
|
2018-10-29 01:16:48 +08:00
|
|
|
pub fn main(out_dir: &str, out_path: &Path) {
|
2017-10-24 16:54:48 +08:00
|
|
|
if cfg!(feature = "sqlcipher") {
|
2019-04-20 01:22:03 +08:00
|
|
|
// This is just a sanity check, the top level `main` should ensure this.
|
2017-10-24 16:54:48 +08:00
|
|
|
panic!("Builds with bundled SQLCipher are not supported");
|
|
|
|
}
|
|
|
|
|
2018-10-29 01:16:48 +08:00
|
|
|
#[cfg(feature = "buildtime_bindgen")]
|
|
|
|
{
|
|
|
|
use super::{bindings, HeaderLocation};
|
|
|
|
let header = HeaderLocation::FromPath("sqlite3/sqlite3.h".to_owned());
|
|
|
|
bindings::write_to_out_dir(header, out_path);
|
|
|
|
}
|
|
|
|
#[cfg(not(feature = "buildtime_bindgen"))]
|
|
|
|
{
|
|
|
|
use std::fs;
|
|
|
|
fs::copy("sqlite3/bindgen_bundled_version.rs", out_path)
|
|
|
|
.expect("Could not copy bindings to output directory");
|
|
|
|
}
|
2017-02-09 10:41:34 +08:00
|
|
|
|
2017-09-21 03:28:19 +08:00
|
|
|
let mut cfg = cc::Build::new();
|
|
|
|
cfg.file("sqlite3/sqlite3.c")
|
2017-03-04 03:57:40 +08:00
|
|
|
.flag("-DSQLITE_CORE")
|
|
|
|
.flag("-DSQLITE_DEFAULT_FOREIGN_KEYS=1")
|
|
|
|
.flag("-DSQLITE_ENABLE_API_ARMOR")
|
|
|
|
.flag("-DSQLITE_ENABLE_COLUMN_METADATA")
|
|
|
|
.flag("-DSQLITE_ENABLE_DBSTAT_VTAB")
|
|
|
|
.flag("-DSQLITE_ENABLE_FTS3")
|
|
|
|
.flag("-DSQLITE_ENABLE_FTS3_PARENTHESIS")
|
|
|
|
.flag("-DSQLITE_ENABLE_FTS5")
|
|
|
|
.flag("-DSQLITE_ENABLE_JSON1")
|
|
|
|
.flag("-DSQLITE_ENABLE_LOAD_EXTENSION=1")
|
|
|
|
.flag("-DSQLITE_ENABLE_MEMORY_MANAGEMENT")
|
|
|
|
.flag("-DSQLITE_ENABLE_RTREE")
|
|
|
|
.flag("-DSQLITE_ENABLE_STAT2")
|
|
|
|
.flag("-DSQLITE_ENABLE_STAT4")
|
|
|
|
.flag("-DSQLITE_SOUNDEX")
|
|
|
|
.flag("-DSQLITE_THREADSAFE=1")
|
|
|
|
.flag("-DSQLITE_USE_URI")
|
2020-04-07 01:43:43 +08:00
|
|
|
.flag("-DHAVE_USLEEP=1")
|
|
|
|
.warnings(false);
|
2019-08-10 02:03:46 +08:00
|
|
|
// Older versions of visual studio don't support c99 (including isnan), which
|
|
|
|
// causes a build failure when the linker fails to find the `isnan`
|
|
|
|
// function. `sqlite` provides its own implmentation, using the fact
|
|
|
|
// that x != x when x is NaN.
|
2019-05-10 20:42:02 +08:00
|
|
|
//
|
2019-08-10 02:03:46 +08:00
|
|
|
// There may be other platforms that don't support `isnan`, they should be
|
|
|
|
// tested for here.
|
2019-05-10 20:42:02 +08:00
|
|
|
if cfg!(target_env = "msvc") {
|
2019-08-17 14:18:37 +08:00
|
|
|
use cc::windows_registry::{find_vs_version, VsVers};
|
2019-05-10 20:42:02 +08:00
|
|
|
let vs_has_nan = match find_vs_version() {
|
|
|
|
Ok(ver) => ver != VsVers::Vs12,
|
|
|
|
Err(_msg) => false,
|
|
|
|
};
|
|
|
|
if vs_has_nan {
|
|
|
|
cfg.flag("-DSQLITE_HAVE_ISNAN");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cfg.flag("-DSQLITE_HAVE_ISNAN");
|
|
|
|
}
|
2017-09-21 03:28:19 +08:00
|
|
|
if cfg!(feature = "unlock_notify") {
|
|
|
|
cfg.flag("-DSQLITE_ENABLE_UNLOCK_NOTIFY");
|
|
|
|
}
|
2019-01-13 19:46:19 +08:00
|
|
|
if cfg!(feature = "preupdate_hook") {
|
|
|
|
cfg.flag("-DSQLITE_ENABLE_PREUPDATE_HOOK");
|
|
|
|
}
|
|
|
|
if cfg!(feature = "session") {
|
|
|
|
cfg.flag("-DSQLITE_ENABLE_SESSION");
|
|
|
|
}
|
2019-05-16 02:23:20 +08:00
|
|
|
|
2019-05-16 00:41:23 +08:00
|
|
|
if let Ok(limit) = env::var("SQLITE_MAX_VARIABLE_NUMBER") {
|
|
|
|
cfg.flag(&format!("-DSQLITE_MAX_VARIABLE_NUMBER={}", limit));
|
|
|
|
}
|
2019-05-16 02:23:20 +08:00
|
|
|
println!("cargo:rerun-if-env-changed=SQLITE_MAX_VARIABLE_NUMBER");
|
|
|
|
|
2019-05-16 00:41:23 +08:00
|
|
|
if let Ok(limit) = env::var("SQLITE_MAX_EXPR_DEPTH") {
|
|
|
|
cfg.flag(&format!("-DSQLITE_MAX_EXPR_DEPTH={}", limit));
|
|
|
|
}
|
2019-05-16 02:23:20 +08:00
|
|
|
println!("cargo:rerun-if-env-changed=SQLITE_MAX_EXPR_DEPTH");
|
2019-05-16 00:41:23 +08:00
|
|
|
|
2017-09-21 03:28:19 +08:00
|
|
|
cfg.compile("libsqlite3.a");
|
2018-06-30 06:20:59 +08:00
|
|
|
|
|
|
|
println!("cargo:lib_dir={}", out_dir);
|
2017-03-04 03:57:40 +08:00
|
|
|
}
|
2017-02-08 09:37:52 +08:00
|
|
|
}
|
|
|
|
|
2018-10-29 01:16:48 +08:00
|
|
|
fn env_prefix() -> &'static str {
|
|
|
|
if cfg!(feature = "sqlcipher") {
|
|
|
|
"SQLCIPHER"
|
|
|
|
} else {
|
|
|
|
"SQLITE3"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum HeaderLocation {
|
|
|
|
FromEnvironment,
|
|
|
|
Wrapper,
|
|
|
|
FromPath(String),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<HeaderLocation> for String {
|
|
|
|
fn from(header: HeaderLocation) -> String {
|
|
|
|
match header {
|
|
|
|
HeaderLocation::FromEnvironment => {
|
|
|
|
let prefix = env_prefix();
|
2019-12-20 03:08:04 +08:00
|
|
|
let mut header = env::var(format!("{}_INCLUDE_DIR", prefix)).unwrap_or_else(|_| {
|
|
|
|
panic!(
|
|
|
|
"{}_INCLUDE_DIR must be set if {}_LIB_DIR is set",
|
|
|
|
prefix, prefix
|
|
|
|
)
|
|
|
|
});
|
2018-10-29 01:16:48 +08:00
|
|
|
header.push_str("/sqlite3.h");
|
|
|
|
header
|
|
|
|
}
|
|
|
|
HeaderLocation::Wrapper => "wrapper.h".into(),
|
|
|
|
HeaderLocation::FromPath(path) => path,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-20 01:22:03 +08:00
|
|
|
mod build_linked {
|
2017-05-28 19:15:47 +08:00
|
|
|
#[cfg(all(feature = "vcpkg", target_env = "msvc"))]
|
2017-05-28 11:35:46 +08:00
|
|
|
extern crate vcpkg;
|
|
|
|
|
2018-10-29 01:16:48 +08:00
|
|
|
use super::{bindings, env_prefix, HeaderLocation};
|
2017-03-04 03:57:40 +08:00
|
|
|
use std::env;
|
2018-10-29 01:16:48 +08:00
|
|
|
use std::path::Path;
|
2017-03-04 03:57:40 +08:00
|
|
|
|
2018-10-29 01:16:48 +08:00
|
|
|
pub fn main(_out_dir: &str, out_path: &Path) {
|
2017-03-04 03:57:40 +08:00
|
|
|
let header = find_sqlite();
|
2019-06-26 02:40:28 +08:00
|
|
|
if cfg!(any(
|
2020-01-15 00:11:36 +08:00
|
|
|
feature = "bundled_bindings",
|
2019-06-26 02:40:28 +08:00
|
|
|
feature = "bundled",
|
|
|
|
all(windows, feature = "bundled-windows")
|
|
|
|
)) && !cfg!(feature = "buildtime_bindgen")
|
|
|
|
{
|
2020-01-15 00:11:36 +08:00
|
|
|
// Generally means the `bundled_bindings` feature is enabled
|
|
|
|
// (there's also an edge case where we get here involving
|
|
|
|
// sqlcipher). In either case most users are better off with turning
|
|
|
|
// on buildtime_bindgen instead, but this is still supported as we
|
|
|
|
// have runtime version checks and there are good reasons to not
|
|
|
|
// want to run bindgen.
|
2019-04-20 01:22:03 +08:00
|
|
|
std::fs::copy("sqlite3/bindgen_bundled_version.rs", out_path)
|
|
|
|
.expect("Could not copy bindings to output directory");
|
|
|
|
} else {
|
|
|
|
bindings::write_to_out_dir(header, out_path);
|
|
|
|
}
|
2017-02-08 09:37:52 +08:00
|
|
|
}
|
|
|
|
|
2018-12-15 09:12:31 +08:00
|
|
|
fn find_link_mode() -> &'static str {
|
|
|
|
// If the user specifies SQLITE_STATIC (or SQLCIPHER_STATIC), do static
|
|
|
|
// linking, unless it's explicitly set to 0.
|
|
|
|
match &env::var(format!("{}_STATIC", env_prefix())) {
|
|
|
|
Ok(v) if v != "0" => "static",
|
|
|
|
_ => "dylib",
|
|
|
|
}
|
|
|
|
}
|
2017-03-04 03:57:40 +08:00
|
|
|
// Prints the necessary cargo link commands and returns the path to the header.
|
2017-03-04 04:16:49 +08:00
|
|
|
fn find_sqlite() -> HeaderLocation {
|
2017-10-24 16:54:48 +08:00
|
|
|
let link_lib = link_lib();
|
|
|
|
|
2018-04-07 04:27:07 +08:00
|
|
|
println!("cargo:rerun-if-env-changed={}_INCLUDE_DIR", env_prefix());
|
|
|
|
println!("cargo:rerun-if-env-changed={}_LIB_DIR", env_prefix());
|
2018-12-15 09:12:31 +08:00
|
|
|
println!("cargo:rerun-if-env-changed={}_STATIC", env_prefix());
|
2019-03-25 04:21:13 +08:00
|
|
|
if cfg!(all(feature = "vcpkg", target_env = "msvc")) {
|
|
|
|
println!("cargo:rerun-if-env-changed=VCPKGRS_DYNAMIC");
|
|
|
|
}
|
2020-01-08 15:48:19 +08:00
|
|
|
|
|
|
|
// dependents can access `DEP_SQLITE3_LINK_TARGET` (`sqlite3` being the
|
|
|
|
// `links=` value in our Cargo.toml) to get this value. This might be
|
|
|
|
// useful if you need to ensure whatever crypto library sqlcipher relies
|
|
|
|
// on is available, for example.
|
|
|
|
println!("cargo:link-target={}", link_lib);
|
|
|
|
|
2017-03-04 03:57:40 +08:00
|
|
|
// Allow users to specify where to find SQLite.
|
2017-10-24 16:54:48 +08:00
|
|
|
if let Ok(dir) = env::var(format!("{}_LIB_DIR", env_prefix())) {
|
2019-02-05 12:53:57 +08:00
|
|
|
// Try to use pkg-config to determine link commands
|
|
|
|
let pkgconfig_path = Path::new(&dir).join("pkgconfig");
|
|
|
|
env::set_var("PKG_CONFIG_PATH", pkgconfig_path);
|
2019-12-20 03:08:04 +08:00
|
|
|
if pkg_config::Config::new().probe(link_lib).is_err() {
|
2019-02-05 12:53:57 +08:00
|
|
|
// Otherwise just emit the bare minimum link commands.
|
|
|
|
println!("cargo:rustc-link-lib={}={}", find_link_mode(), link_lib);
|
|
|
|
println!("cargo:rustc-link-search={}", dir);
|
|
|
|
}
|
2017-03-04 04:16:49 +08:00
|
|
|
return HeaderLocation::FromEnvironment;
|
2017-03-04 03:57:40 +08:00
|
|
|
}
|
|
|
|
|
2017-05-28 11:35:46 +08:00
|
|
|
if let Some(header) = try_vcpkg() {
|
|
|
|
return header;
|
|
|
|
}
|
|
|
|
|
2017-03-04 03:57:40 +08:00
|
|
|
// See if pkg-config can do everything for us.
|
2018-08-11 18:48:21 +08:00
|
|
|
match pkg_config::Config::new()
|
|
|
|
.print_system_libs(false)
|
|
|
|
.probe(link_lib)
|
|
|
|
{
|
2017-03-04 03:57:40 +08:00
|
|
|
Ok(mut lib) => {
|
|
|
|
if let Some(mut header) = lib.include_paths.pop() {
|
|
|
|
header.push("sqlite3.h");
|
2017-03-04 04:16:49 +08:00
|
|
|
HeaderLocation::FromPath(header.to_string_lossy().into())
|
2017-03-04 03:57:40 +08:00
|
|
|
} else {
|
2017-03-04 04:16:49 +08:00
|
|
|
HeaderLocation::Wrapper
|
2017-03-04 03:57:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(_) => {
|
|
|
|
// No env var set and pkg-config couldn't help; just output the link-lib
|
|
|
|
// request and hope that the library exists on the system paths. We used to
|
2018-10-29 01:16:48 +08:00
|
|
|
// output /usr/lib explicitly, but that can introduce other linking problems;
|
|
|
|
// see https://github.com/jgallagher/rusqlite/issues/207.
|
2018-12-15 09:12:31 +08:00
|
|
|
println!("cargo:rustc-link-lib={}={}", find_link_mode(), link_lib);
|
2017-03-04 04:16:49 +08:00
|
|
|
HeaderLocation::Wrapper
|
2017-02-08 09:37:52 +08:00
|
|
|
}
|
2017-01-24 09:17:14 +08:00
|
|
|
}
|
2017-03-04 03:57:40 +08:00
|
|
|
}
|
|
|
|
|
2017-05-28 19:15:47 +08:00
|
|
|
#[cfg(all(feature = "vcpkg", target_env = "msvc"))]
|
2017-05-28 11:35:46 +08:00
|
|
|
fn try_vcpkg() -> Option<HeaderLocation> {
|
|
|
|
// See if vcpkg can find it.
|
2017-10-24 16:54:48 +08:00
|
|
|
if let Ok(mut lib) = vcpkg::Config::new().probe(link_lib()) {
|
2017-05-28 11:35:46 +08:00
|
|
|
if let Some(mut header) = lib.include_paths.pop() {
|
|
|
|
header.push("sqlite3.h");
|
|
|
|
return Some(HeaderLocation::FromPath(header.to_string_lossy().into()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
2017-05-28 19:15:47 +08:00
|
|
|
#[cfg(not(all(feature = "vcpkg", target_env = "msvc")))]
|
2017-05-28 11:35:46 +08:00
|
|
|
fn try_vcpkg() -> Option<HeaderLocation> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
2017-10-24 16:54:48 +08:00
|
|
|
fn link_lib() -> &'static str {
|
|
|
|
if cfg!(feature = "sqlcipher") {
|
|
|
|
"sqlcipher"
|
|
|
|
} else {
|
|
|
|
"sqlite3"
|
|
|
|
}
|
|
|
|
}
|
2018-10-29 01:16:48 +08:00
|
|
|
}
|
2017-10-24 16:54:48 +08:00
|
|
|
|
2019-04-20 01:22:03 +08:00
|
|
|
#[cfg(not(feature = "buildtime_bindgen"))]
|
2018-10-29 01:16:48 +08:00
|
|
|
mod bindings {
|
|
|
|
use super::HeaderLocation;
|
|
|
|
|
|
|
|
use std::fs;
|
|
|
|
use std::path::Path;
|
|
|
|
|
2020-03-14 14:41:57 +08:00
|
|
|
static PREBUILT_BINDGEN_PATHS: &[&str] = &[
|
2018-10-29 01:16:48 +08:00
|
|
|
"bindgen-bindings/bindgen_3.6.8.rs",
|
|
|
|
#[cfg(feature = "min_sqlite_version_3_6_23")]
|
|
|
|
"bindgen-bindings/bindgen_3.6.23.rs",
|
|
|
|
#[cfg(feature = "min_sqlite_version_3_7_7")]
|
|
|
|
"bindgen-bindings/bindgen_3.7.7.rs",
|
2019-01-06 16:50:35 +08:00
|
|
|
#[cfg(feature = "min_sqlite_version_3_7_16")]
|
|
|
|
"bindgen-bindings/bindgen_3.7.16.rs",
|
2018-10-29 01:16:48 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
pub fn write_to_out_dir(_header: HeaderLocation, out_path: &Path) {
|
|
|
|
let in_path = PREBUILT_BINDGEN_PATHS[PREBUILT_BINDGEN_PATHS.len() - 1];
|
|
|
|
fs::copy(in_path, out_path).expect("Could not copy bindings to output directory");
|
2017-02-08 09:37:52 +08:00
|
|
|
}
|
2018-10-29 01:16:48 +08:00
|
|
|
}
|
2016-06-15 22:34:13 +08:00
|
|
|
|
2018-10-29 01:16:48 +08:00
|
|
|
#[cfg(feature = "buildtime_bindgen")]
|
|
|
|
mod bindings {
|
|
|
|
use super::HeaderLocation;
|
2019-08-17 14:18:37 +08:00
|
|
|
use bindgen::callbacks::{IntKind, ParseCallbacks};
|
2017-03-04 03:57:40 +08:00
|
|
|
|
2018-10-29 01:16:48 +08:00
|
|
|
use std::fs::OpenOptions;
|
|
|
|
use std::io::Write;
|
|
|
|
use std::path::Path;
|
2017-03-04 03:57:40 +08:00
|
|
|
|
2018-10-29 01:16:48 +08:00
|
|
|
#[derive(Debug)]
|
|
|
|
struct SqliteTypeChooser;
|
2017-03-04 03:57:40 +08:00
|
|
|
|
2018-10-29 01:16:48 +08:00
|
|
|
impl ParseCallbacks for SqliteTypeChooser {
|
|
|
|
fn int_macro(&self, _name: &str, value: i64) -> Option<IntKind> {
|
|
|
|
if value >= i32::min_value() as i64 && value <= i32::max_value() as i64 {
|
|
|
|
Some(IntKind::I32)
|
|
|
|
} else {
|
|
|
|
None
|
2017-03-04 03:57:40 +08:00
|
|
|
}
|
|
|
|
}
|
2018-10-29 01:16:48 +08:00
|
|
|
}
|
2017-03-04 03:57:40 +08:00
|
|
|
|
2020-04-10 16:38:55 +08:00
|
|
|
// Are we generating the bundled bindings? Used to avoid emitting things
|
|
|
|
// that would be problematic in bundled builds. This env var is set by
|
|
|
|
// `upgrade.sh`.
|
|
|
|
fn generating_bundled_bindings() -> bool {
|
|
|
|
// Hacky way to know if we're generating the bundled bindings
|
|
|
|
println!("cargo:rerun-if-env-changed=LIBSQLITE3_SYS_BUNDLING");
|
|
|
|
match std::env::var("LIBSQLITE3_SYS_BUNDLING") {
|
|
|
|
Ok(v) if v != "0" => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-29 01:16:48 +08:00
|
|
|
pub fn write_to_out_dir(header: HeaderLocation, out_path: &Path) {
|
|
|
|
let header: String = header.into();
|
|
|
|
let mut output = Vec::new();
|
2019-01-13 19:46:19 +08:00
|
|
|
let mut bindings = bindgen::builder()
|
2018-10-29 01:16:48 +08:00
|
|
|
.header(header.clone())
|
|
|
|
.parse_callbacks(Box::new(SqliteTypeChooser))
|
2019-01-13 19:46:19 +08:00
|
|
|
.rustfmt_bindings(true);
|
|
|
|
|
|
|
|
if cfg!(feature = "unlock_notify") {
|
|
|
|
bindings = bindings.clang_arg("-DSQLITE_ENABLE_UNLOCK_NOTIFY");
|
|
|
|
}
|
|
|
|
if cfg!(feature = "preupdate_hook") {
|
|
|
|
bindings = bindings.clang_arg("-DSQLITE_ENABLE_PREUPDATE_HOOK");
|
|
|
|
}
|
|
|
|
if cfg!(feature = "session") {
|
|
|
|
bindings = bindings.clang_arg("-DSQLITE_ENABLE_SESSION");
|
|
|
|
}
|
|
|
|
|
2020-04-10 16:38:55 +08:00
|
|
|
// 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
|
|
|
|
// amalgamated `sqlite.h`: `stdarg.h`.
|
|
|
|
//
|
|
|
|
// Thankfully, there's almost no case where rust code needs to use
|
|
|
|
// functions taking `va_list` (It's nearly impossible to get a `va_list`
|
|
|
|
// in Rust unless you get passed it by C code for some reason).
|
|
|
|
//
|
|
|
|
// Arguably, we should never be including these, but we include them for
|
|
|
|
// the cases where they aren't totally broken...
|
|
|
|
let target_arch = std::env::var("TARGET").unwrap();
|
|
|
|
let host_arch = std::env::var("HOST").unwrap();
|
|
|
|
let is_cross_compiling = target_arch != host_arch;
|
|
|
|
|
|
|
|
// Note that when generating the bundled file, we're essentially always
|
|
|
|
// cross compiling.
|
|
|
|
if generating_bundled_bindings() || is_cross_compiling {
|
|
|
|
// Get rid of va_list, as it's not
|
|
|
|
bindings = bindings
|
|
|
|
.blacklist_function("sqlite3_vmprintf")
|
|
|
|
.blacklist_function("sqlite3_vsnprintf")
|
|
|
|
.blacklist_function("sqlite3_str_vappendf")
|
|
|
|
.blacklist_type("va_list")
|
|
|
|
.blacklist_type("__builtin_va_list")
|
|
|
|
.blacklist_type("__gnuc_va_list")
|
|
|
|
.blacklist_type("__va_list_tag")
|
|
|
|
.blacklist_item("__GNUC_VA_LIST");
|
|
|
|
}
|
|
|
|
|
2019-01-13 19:46:19 +08:00
|
|
|
bindings
|
2018-10-29 01:16:48 +08:00
|
|
|
.generate()
|
2019-12-20 03:08:04 +08:00
|
|
|
.unwrap_or_else(|_| panic!("could not run bindgen on header {}", header))
|
2018-10-29 01:16:48 +08:00
|
|
|
.write(Box::new(&mut output))
|
|
|
|
.expect("could not write output of bindgen");
|
|
|
|
let mut output = String::from_utf8(output).expect("bindgen output was not UTF-8?!");
|
|
|
|
|
|
|
|
// rusqlite's functions feature ors in the SQLITE_DETERMINISTIC flag when it
|
|
|
|
// can. This flag was added in SQLite 3.8.3, but oring it in in prior
|
|
|
|
// versions of SQLite is harmless. We don't want to not build just
|
|
|
|
// because this flag is missing (e.g., if we're linking against
|
|
|
|
// SQLite 3.7.x), so append the flag manually if it isn't present in bindgen's
|
|
|
|
// output.
|
|
|
|
if !output.contains("pub const SQLITE_DETERMINISTIC") {
|
|
|
|
output.push_str("\npub const SQLITE_DETERMINISTIC: i32 = 2048;\n");
|
|
|
|
}
|
2017-03-04 03:57:40 +08:00
|
|
|
|
2018-10-29 01:16:48 +08:00
|
|
|
let mut file = OpenOptions::new()
|
|
|
|
.write(true)
|
|
|
|
.truncate(true)
|
|
|
|
.create(true)
|
2019-12-20 03:08:04 +08:00
|
|
|
.open(out_path)
|
|
|
|
.unwrap_or_else(|_| panic!("Could not write to {:?}", out_path));
|
2017-03-04 03:57:40 +08:00
|
|
|
|
2018-10-29 01:16:48 +08:00
|
|
|
file.write_all(output.as_bytes())
|
2019-12-20 03:08:04 +08:00
|
|
|
.unwrap_or_else(|_| panic!("Could not write to {:?}", out_path));
|
2017-03-04 03:57:40 +08:00
|
|
|
}
|
2016-06-15 22:34:13 +08:00
|
|
|
}
|