mirror of
https://github.com/isar/rusqlite.git
synced 2025-09-14 19:52:19 +08:00
Merge remote-tracking branch 'remotes/jgallagher/master' into vtab
This commit is contained in:
@@ -4,17 +4,21 @@ fn main() {
|
||||
|
||||
#[cfg(feature = "bundled")]
|
||||
mod build {
|
||||
extern crate gcc;
|
||||
extern crate cc;
|
||||
use std::{env, fs};
|
||||
use std::path::Path;
|
||||
|
||||
pub fn main() {
|
||||
if cfg!(feature = "sqlcipher") {
|
||||
panic!("Builds with bundled SQLCipher are not supported");
|
||||
}
|
||||
|
||||
let out_dir = env::var("OUT_DIR").unwrap();
|
||||
let out_path = Path::new(&out_dir).join("bindgen.rs");
|
||||
fs::copy("sqlite3/bindgen_bundled_version.rs", out_path)
|
||||
.expect("Could not copy bindings to output directory");
|
||||
|
||||
gcc::Config::new()
|
||||
cc::Build::new()
|
||||
.file("sqlite3/sqlite3.c")
|
||||
.flag("-DSQLITE_CORE")
|
||||
.flag("-DSQLITE_DEFAULT_FOREIGN_KEYS=1")
|
||||
@@ -58,8 +62,9 @@ mod build {
|
||||
fn from(header: HeaderLocation) -> String {
|
||||
match header {
|
||||
HeaderLocation::FromEnvironment => {
|
||||
let mut header = env::var("SQLITE3_INCLUDE_DIR")
|
||||
.expect("SQLITE3_INCLUDE_DIR must be set if SQLITE3_LIB_DIR is set");
|
||||
let prefix = env_prefix();
|
||||
let mut header = env::var(format!("{}_INCLUDE_DIR", prefix))
|
||||
.expect(&format!("{}_INCLUDE_DIR must be set if {}_LIB_DIR is set", prefix, prefix));
|
||||
header.push_str("/sqlite3.h");
|
||||
header
|
||||
}
|
||||
@@ -76,9 +81,11 @@ mod build {
|
||||
|
||||
// Prints the necessary cargo link commands and returns the path to the header.
|
||||
fn find_sqlite() -> HeaderLocation {
|
||||
let link_lib = link_lib();
|
||||
|
||||
// Allow users to specify where to find SQLite.
|
||||
if let Ok(dir) = env::var("SQLITE3_LIB_DIR") {
|
||||
println!("cargo:rustc-link-lib=sqlite3");
|
||||
if let Ok(dir) = env::var(format!("{}_LIB_DIR", env_prefix())) {
|
||||
println!("cargo:rustc-link-lib={}", link_lib);
|
||||
println!("cargo:rustc-link-search={}", dir);
|
||||
return HeaderLocation::FromEnvironment;
|
||||
}
|
||||
@@ -88,7 +95,7 @@ mod build {
|
||||
}
|
||||
|
||||
// See if pkg-config can do everything for us.
|
||||
match pkg_config::Config::new().print_system_libs(false).probe("sqlite3") {
|
||||
match pkg_config::Config::new().print_system_libs(false).probe(link_lib) {
|
||||
Ok(mut lib) => {
|
||||
if let Some(mut header) = lib.include_paths.pop() {
|
||||
header.push("sqlite3.h");
|
||||
@@ -102,7 +109,7 @@ mod build {
|
||||
// request and hope that the library exists on the system paths. We used to
|
||||
// output /usr/lib explicitly, but that can introduce other linking problems; see
|
||||
// https://github.com/jgallagher/rusqlite/issues/207.
|
||||
println!("cargo:rustc-link-lib=sqlite3");
|
||||
println!("cargo:rustc-link-lib={}", link_lib);
|
||||
HeaderLocation::Wrapper
|
||||
}
|
||||
}
|
||||
@@ -111,7 +118,7 @@ mod build {
|
||||
#[cfg(all(feature = "vcpkg", target_env = "msvc"))]
|
||||
fn try_vcpkg() -> Option<HeaderLocation> {
|
||||
// See if vcpkg can find it.
|
||||
if let Ok(mut lib) = vcpkg::Config::new().probe("sqlite3") {
|
||||
if let Ok(mut lib) = vcpkg::Config::new().probe(link_lib()) {
|
||||
if let Some(mut header) = lib.include_paths.pop() {
|
||||
header.push("sqlite3.h");
|
||||
return Some(HeaderLocation::FromPath(header.to_string_lossy().into()));
|
||||
@@ -125,6 +132,22 @@ mod build {
|
||||
None
|
||||
}
|
||||
|
||||
fn env_prefix() -> &'static str {
|
||||
if cfg!(feature = "sqlcipher") {
|
||||
"SQLCIPHER"
|
||||
} else {
|
||||
"SQLITE3"
|
||||
}
|
||||
}
|
||||
|
||||
fn link_lib() -> &'static str {
|
||||
if cfg!(feature = "sqlcipher") {
|
||||
"sqlcipher"
|
||||
} else {
|
||||
"sqlite3"
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "buildtime_bindgen"))]
|
||||
mod bindings {
|
||||
use super::HeaderLocation;
|
||||
@@ -205,7 +228,7 @@ mod build {
|
||||
// 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:") {
|
||||
if !output.contains("pub const SQLITE_DETERMINISTIC") {
|
||||
output.push_str("\npub const SQLITE_DETERMINISTIC: i32 = 2048;\n");
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user