mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-25 10:31:37 +08:00
Merge pull request #232 from jgallagher/run-bindgen-at-build-time
Run bindgen at build time
This commit is contained in:
commit
e92a0ef30b
53
.travis.yml
53
.travis.yml
@ -1,19 +1,40 @@
|
|||||||
language: rust
|
|
||||||
sudo: false
|
sudo: false
|
||||||
|
|
||||||
|
language: rust
|
||||||
|
|
||||||
|
rust:
|
||||||
|
- stable
|
||||||
|
- beta
|
||||||
|
- nightly
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
allow_failures:
|
||||||
|
- rust: nightly
|
||||||
|
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources:
|
||||||
|
- llvm-toolchain-precise-3.9
|
||||||
|
- ubuntu-toolchain-r-test
|
||||||
|
packages:
|
||||||
|
- llvm-3.9-dev
|
||||||
|
- libclang-3.9-dev
|
||||||
|
|
||||||
|
env:
|
||||||
|
- LIBCLANG_PATH=/usr/lib/llvm-3.9/lib
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- cargo build
|
- cargo build
|
||||||
- cargo build --features bundled
|
- cargo build --features bundled
|
||||||
- cargo test
|
- cargo test
|
||||||
- cargo test --features backup
|
- cargo test --features backup
|
||||||
- cargo test --features blob
|
- cargo test --features blob
|
||||||
- cargo test --features limits
|
- cargo test --features functions
|
||||||
- cargo test --features load_extension
|
- cargo test --features limits
|
||||||
- cargo test --features trace
|
- cargo test --features load_extension
|
||||||
- cargo test --features functions
|
- cargo test --features trace
|
||||||
- cargo test --features chrono
|
- cargo test --features chrono
|
||||||
- cargo test --features serde_json
|
- cargo test --features serde_json
|
||||||
- cargo test --features bundled
|
- cargo test --features bundled
|
||||||
- cargo test --features "backup blob chrono functions load_extension serde_json trace"
|
- cargo test --features "backup blob chrono functions limits load_extension serde_json trace"
|
||||||
- cargo test --features "backup blob chrono functions limits load_extension serde_json trace"
|
- cargo test --features "backup blob chrono functions limits load_extension serde_json trace bundled"
|
||||||
- cargo test --features "backup blob chrono functions limits load_extension serde_json trace bundled"
|
|
||||||
|
@ -41,7 +41,7 @@ regex = "0.2"
|
|||||||
|
|
||||||
[dependencies.libsqlite3-sys]
|
[dependencies.libsqlite3-sys]
|
||||||
path = "libsqlite3-sys"
|
path = "libsqlite3-sys"
|
||||||
version = "0.6.1"
|
version = "0.7.0"
|
||||||
|
|
||||||
[[test]]
|
[[test]]
|
||||||
name = "config_log"
|
name = "config_log"
|
||||||
|
@ -68,10 +68,12 @@ features](http://doc.crates.io/manifest.html#the-features-section). They are:
|
|||||||
allows use of SQLite's online backup API.
|
allows use of SQLite's online backup API.
|
||||||
* [`functions`](http://jgallagher.github.io/rusqlite/rusqlite/functions/index.html)
|
* [`functions`](http://jgallagher.github.io/rusqlite/rusqlite/functions/index.html)
|
||||||
allows you to load Rust closures into SQLite connections for use in queries.
|
allows you to load Rust closures into SQLite connections for use in queries.
|
||||||
|
Note: This feature requires SQLite 3.7.3 or later.
|
||||||
* [`trace`](http://jgallagher.github.io/rusqlite/rusqlite/trace/index.html)
|
* [`trace`](http://jgallagher.github.io/rusqlite/rusqlite/trace/index.html)
|
||||||
allows hooks into SQLite's tracing and profiling APIs.
|
allows hooks into SQLite's tracing and profiling APIs.
|
||||||
* [`blob`](http://jgallagher.github.io/rusqlite/rusqlite/blob/index.html)
|
* [`blob`](http://jgallagher.github.io/rusqlite/rusqlite/blob/index.html)
|
||||||
gives `std::io::{Read, Write, Seek}` access to SQL BLOBs.
|
gives `std::io::{Read, Write, Seek}` access to SQL BLOBs. Note: This feature
|
||||||
|
requires SQLite 3.7.4 or later.
|
||||||
* [`limits`](http://jgallagher.github.io/rusqlite/rusqlite/struct.Connection.html#method.limit)
|
* [`limits`](http://jgallagher.github.io/rusqlite/rusqlite/struct.Connection.html#method.limit)
|
||||||
allows you to set and retrieve SQLite's per connection limits.
|
allows you to set and retrieve SQLite's per connection limits.
|
||||||
* `chrono` implements [`FromSql`](http://jgallagher.github.io/rusqlite/rusqlite/types/trait.FromSql.html)
|
* `chrono` implements [`FromSql`](http://jgallagher.github.io/rusqlite/rusqlite/types/trait.FromSql.html)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
environment:
|
environment:
|
||||||
TARGET: 1.14.0-x86_64-pc-windows-gnu
|
TARGET: 1.15.0-x86_64-pc-windows-gnu
|
||||||
MSYS2_BITS: 64
|
MSYS2_BITS: 64
|
||||||
install:
|
install:
|
||||||
- ps: Start-FileDownload "https://static.rust-lang.org/dist/rust-${env:TARGET}.exe"
|
- ps: Start-FileDownload "https://static.rust-lang.org/dist/rust-${env:TARGET}.exe"
|
||||||
@ -8,9 +8,12 @@ install:
|
|||||||
- if defined MSYS2_BITS set PATH=%PATH%;C:\msys64\mingw%MSYS2_BITS%\bin
|
- if defined MSYS2_BITS set PATH=%PATH%;C:\msys64\mingw%MSYS2_BITS%\bin
|
||||||
- rustc -V
|
- rustc -V
|
||||||
- cargo -V
|
- cargo -V
|
||||||
- ps: Start-FileDownload 'http://sqlite.org/2016/sqlite-dll-win64-x64-3100200.zip'
|
- ps: Start-FileDownload 'https://sqlite.org/2017/sqlite-dll-win64-x64-3160200.zip'
|
||||||
- cmd: 7z e sqlite-dll-win64-x64-3100200.zip -y > nul
|
- cmd: 7z e sqlite-dll-win64-x64-3160200.zip -y > nul
|
||||||
|
- ps: Start-FileDownload 'https://sqlite.org/2017/sqlite-amalgamation-3160200.zip'
|
||||||
|
- cmd: 7z e sqlite-amalgamation-3160200.zip -y > nul
|
||||||
- SET SQLITE3_LIB_DIR=%APPVEYOR_BUILD_FOLDER%
|
- SET SQLITE3_LIB_DIR=%APPVEYOR_BUILD_FOLDER%
|
||||||
|
- SET SQLITE3_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%
|
||||||
|
|
||||||
build: false
|
build: false
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "libsqlite3-sys"
|
name = "libsqlite3-sys"
|
||||||
version = "0.6.2"
|
version = "0.7.0"
|
||||||
authors = ["John Gallagher <jgallagher@bignerdranch.com>"]
|
authors = ["John Gallagher <jgallagher@bignerdranch.com>"]
|
||||||
repository = "https://github.com/jgallagher/rusqlite"
|
repository = "https://github.com/jgallagher/rusqlite"
|
||||||
description = "Native bindings to the libsqlite3 library"
|
description = "Native bindings to the libsqlite3 library"
|
||||||
@ -12,6 +12,7 @@ build = "build.rs"
|
|||||||
bundled = []
|
bundled = []
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
bindgen = "0.21"
|
||||||
pkg-config = "0.3"
|
pkg-config = "0.3"
|
||||||
gcc = "0.3"
|
gcc = "0.3"
|
||||||
|
|
||||||
|
@ -1,31 +1,98 @@
|
|||||||
|
extern crate bindgen;
|
||||||
extern crate gcc;
|
extern crate gcc;
|
||||||
extern crate pkg_config;
|
extern crate pkg_config;
|
||||||
|
|
||||||
|
use std::env;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::fs::OpenOptions;
|
||||||
|
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 mut output = Vec::new();
|
||||||
|
bindgen::builder()
|
||||||
|
.header(header.clone())
|
||||||
|
.ctypes_prefix("::libc")
|
||||||
|
.type_chooser(Box::new(SqliteTypeChooser))
|
||||||
|
.generate()
|
||||||
|
.expect(&format!("could not run bindgen on header {}", header))
|
||||||
|
.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");
|
||||||
|
}
|
||||||
|
|
||||||
|
let path = Path::new(&out_dir).join("bindgen.rs");
|
||||||
|
|
||||||
|
let mut file = OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.truncate(true)
|
||||||
|
.create(true)
|
||||||
|
.open(path.clone())
|
||||||
|
.expect(&format!("Could not write to {:?}", path));
|
||||||
|
|
||||||
|
file.write_all(output.as_bytes()).expect(&format!("Could not write to {:?}", path));
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "bundled"))]
|
#[cfg(not(feature = "bundled"))]
|
||||||
fn main() {
|
fn main() {
|
||||||
use std::env;
|
|
||||||
|
|
||||||
// Allow users to specify where to find SQLite.
|
// Allow users to specify where to find SQLite.
|
||||||
match env::var("SQLITE3_LIB_DIR") {
|
if let Ok(dir) = env::var("SQLITE3_LIB_DIR") {
|
||||||
Ok(dir) => {
|
let mut header = env::var("SQLITE3_INCLUDE_DIR")
|
||||||
println!("cargo:rustc-link-lib=sqlite3");
|
.expect("SQLITE3_INCLUDE_DIR must be set if SQLITE3_LIB_DIR is set");
|
||||||
println!("cargo:rustc-link-search={}", dir);
|
header.push_str("/sqlite3.h");
|
||||||
}
|
run_bindgen(header);
|
||||||
Err(_) => {
|
println!("cargo:rustc-link-lib=sqlite3");
|
||||||
// See if pkg-config can do everything for us.
|
println!("cargo:rustc-link-search={}", dir);
|
||||||
if !pkg_config::Config::new().print_system_libs(false).probe("sqlite3").is_ok() {
|
return;
|
||||||
// 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
|
// See if pkg-config can do everything for us.
|
||||||
// https://github.com/jgallagher/rusqlite/issues/207.
|
match pkg_config::Config::new().print_system_libs(false).probe("sqlite3") {
|
||||||
println!("cargo:rustc-link-lib=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(_) => {
|
||||||
|
// 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")]
|
#[cfg(feature = "bundled")]
|
||||||
fn main() {
|
fn main() {
|
||||||
|
run_bindgen("sqlite3/sqlite3.h");
|
||||||
|
|
||||||
gcc::Config::new()
|
gcc::Config::new()
|
||||||
.file("sqlite3/sqlite3.c")
|
.file("sqlite3/sqlite3.c")
|
||||||
.flag("-DSQLITE_CORE")
|
.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, non_camel_case_types)]
|
||||||
|
|
||||||
#![allow(non_snake_case)]
|
|
||||||
|
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
pub use self::bindgen::*;
|
|
||||||
pub use self::error::*;
|
pub use self::error::*;
|
||||||
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use libc::c_int;
|
|
||||||
|
|
||||||
mod bindgen;
|
|
||||||
mod error;
|
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 {
|
pub fn SQLITE_STATIC() -> sqlite3_destructor_type {
|
||||||
Some(unsafe { mem::transmute(0isize) })
|
Some(unsafe { mem::transmute(0isize) })
|
||||||
}
|
}
|
||||||
@ -28,10 +16,6 @@ pub fn SQLITE_TRANSIENT() -> sqlite3_destructor_type {
|
|||||||
Some(unsafe { mem::transmute(-1isize) })
|
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
|
/// Run-Time Limit Categories
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub enum Limit {
|
pub enum Limit {
|
||||||
@ -61,3 +45,5 @@ pub enum Limit {
|
|||||||
/// The maximum number of auxiliary worker threads that a single prepared statement may start.
|
/// The maximum number of auxiliary worker threads that a single prepared statement may start.
|
||||||
SQLITE_LIMIT_WORKER_THREADS = 11,
|
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"
|
@ -195,7 +195,7 @@ pub fn error_from_sqlite_code(code: c_int, message: Option<String>) -> Error {
|
|||||||
Error::SqliteFailure(ffi::Error::new(code), message)
|
Error::SqliteFailure(ffi::Error::new(code), message)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn error_from_handle(db: *mut ffi::Struct_sqlite3, code: c_int) -> Error {
|
pub fn error_from_handle(db: *mut ffi::sqlite3, code: c_int) -> Error {
|
||||||
let message = if db.is_null() {
|
let message = if db.is_null() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -499,7 +499,7 @@ impl Connection {
|
|||||||
/// on the rusqlite repository](https://github.com/jgallagher/rusqlite/issues) and describe
|
/// on the rusqlite repository](https://github.com/jgallagher/rusqlite/issues) and describe
|
||||||
/// your use case. This function is unsafe because it gives you raw access to the SQLite
|
/// your use case. This function is unsafe because it gives you raw access to the SQLite
|
||||||
/// connection, and what you do with it could impact the safety of this `Connection`.
|
/// connection, and what you do with it could impact the safety of this `Connection`.
|
||||||
pub unsafe fn handle(&self) -> *mut ffi::Struct_sqlite3 {
|
pub unsafe fn handle(&self) -> *mut ffi::sqlite3 {
|
||||||
self.db.borrow().db()
|
self.db.borrow().db()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -521,7 +521,7 @@ impl fmt::Debug for Connection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct InnerConnection {
|
struct InnerConnection {
|
||||||
db: *mut ffi::Struct_sqlite3,
|
db: *mut ffi::sqlite3,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Old name for `OpenFlags`. `SqliteOpenFlags` is deprecated.
|
/// Old name for `OpenFlags`. `SqliteOpenFlags` is deprecated.
|
||||||
@ -601,7 +601,7 @@ impl InnerConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn db(&self) -> *mut ffi::Struct_sqlite3 {
|
fn db(&self) -> *mut ffi::sqlite3 {
|
||||||
self.db
|
self.db
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user