mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-25 19:01:38 +08:00
Update libsqlite3-sys to run bindgen at build time
This commit is contained in:
parent
eb0a320875
commit
161ac2bf0a
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "libsqlite3-sys"
|
||||
version = "0.6.2"
|
||||
version = "0.7.0"
|
||||
authors = ["John Gallagher <jgallagher@bignerdranch.com>"]
|
||||
repository = "https://github.com/jgallagher/rusqlite"
|
||||
description = "Native bindings to the libsqlite3 library"
|
||||
@ -12,6 +12,7 @@ build = "build.rs"
|
||||
bundled = []
|
||||
|
||||
[build-dependencies]
|
||||
bindgen = "0.21"
|
||||
pkg-config = "0.3"
|
||||
gcc = "0.3"
|
||||
|
||||
|
@ -1,31 +1,74 @@
|
||||
extern crate bindgen;
|
||||
extern crate gcc;
|
||||
extern crate pkg_config;
|
||||
|
||||
use std::env;
|
||||
use bindgen::chooser::{TypeChooser, IntKind};
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct SqliteTypeChooser;
|
||||
|
||||
impl TypeChooser 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn run_bindgen<T: Into<String>>(header: T) {
|
||||
let out_dir = env::var("OUT_DIR").unwrap();
|
||||
let header = header.into();
|
||||
let _ = bindgen::builder()
|
||||
.header(header.clone())
|
||||
.ctypes_prefix("::libc")
|
||||
.type_chooser(Box::new(SqliteTypeChooser))
|
||||
.generate()
|
||||
.expect(&format!("could not run bindgen on header {}", header))
|
||||
.write_to_file(Path::new(&out_dir).join("bindgen.rs"));
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "bundled"))]
|
||||
fn main() {
|
||||
use std::env;
|
||||
|
||||
// Allow users to specify where to find SQLite.
|
||||
match env::var("SQLITE3_LIB_DIR") {
|
||||
Ok(dir) => {
|
||||
if let Ok(dir) = env::var("SQLITE3_LIB_DIR") {
|
||||
let mut header = env::var("SQLITE3_INCLUDE_DIR")
|
||||
.expect("SQLITE3_INCLUDE_DIR must be set if SQLITE3_LIB_DIR is set");
|
||||
header.push_str("/sqlite3.h");
|
||||
run_bindgen(header);
|
||||
println!("cargo:rustc-link-lib=sqlite3");
|
||||
println!("cargo:rustc-link-search={}", dir);
|
||||
return;
|
||||
}
|
||||
|
||||
// See if pkg-config can do everything for us.
|
||||
match pkg_config::Config::new().print_system_libs(false).probe("sqlite3") {
|
||||
Ok(mut lib) => {
|
||||
if let Some(mut header) = lib.include_paths.pop() {
|
||||
header.push("sqlite3.h");
|
||||
run_bindgen(header.to_string_lossy());
|
||||
} else {
|
||||
run_bindgen("wrapper.h");
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
// See if pkg-config can do everything for us.
|
||||
if !pkg_config::Config::new().print_system_libs(false).probe("sqlite3").is_ok() {
|
||||
// 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
|
||||
// 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");
|
||||
run_bindgen("wrapper.h");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(feature = "bundled")]
|
||||
fn main() {
|
||||
run_bindgen("sqlite3/sqlite3.h");
|
||||
|
||||
gcc::Config::new()
|
||||
.file("sqlite3/sqlite3.c")
|
||||
.flag("-DSQLITE_CORE")
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,25 +1,13 @@
|
||||
// bindgen.rs was created with bindgen 0.15.0 against sqlite3 3.8.10
|
||||
|
||||
#![allow(non_snake_case)]
|
||||
#![allow(non_snake_case, non_camel_case_types)]
|
||||
|
||||
extern crate libc;
|
||||
|
||||
pub use self::bindgen::*;
|
||||
pub use self::error::*;
|
||||
|
||||
use std::mem;
|
||||
use libc::c_int;
|
||||
|
||||
mod bindgen;
|
||||
mod error;
|
||||
|
||||
// SQLite datatype constants.
|
||||
pub const SQLITE_INTEGER : c_int = 1;
|
||||
pub const SQLITE_FLOAT : c_int = 2;
|
||||
pub const SQLITE_TEXT : c_int = 3;
|
||||
pub const SQLITE_BLOB : c_int = 4;
|
||||
pub const SQLITE_NULL : c_int = 5;
|
||||
|
||||
pub fn SQLITE_STATIC() -> sqlite3_destructor_type {
|
||||
Some(unsafe { mem::transmute(0isize) })
|
||||
}
|
||||
@ -28,10 +16,6 @@ pub fn SQLITE_TRANSIENT() -> sqlite3_destructor_type {
|
||||
Some(unsafe { mem::transmute(-1isize) })
|
||||
}
|
||||
|
||||
pub const SQLITE_CONFIG_LOG: c_int = 16;
|
||||
pub const SQLITE_UTF8: c_int = 1;
|
||||
pub const SQLITE_DETERMINISTIC: c_int = 0x800;
|
||||
|
||||
/// Run-Time Limit Categories
|
||||
#[repr(C)]
|
||||
pub enum Limit {
|
||||
@ -61,3 +45,5 @@ pub enum Limit {
|
||||
/// The maximum number of auxiliary worker threads that a single prepared statement may start.
|
||||
SQLITE_LIMIT_WORKER_THREADS = 11,
|
||||
}
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/bindgen.rs"));
|
||||
|
1
libsqlite3-sys/wrapper.h
Normal file
1
libsqlite3-sys/wrapper.h
Normal file
@ -0,0 +1 @@
|
||||
#include "sqlite3.h"
|
Loading…
Reference in New Issue
Block a user