mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-26 03:11:36 +08:00
Manually insert SQLITE_DETERMINISTIC flag in bindgen output if needed.
See comment in libsqlite3-sys/build.rs for details - adding this flag is harmless if it's not present in the header, and not having it can break builds against older SQLite versions.
This commit is contained in:
parent
644166fa5b
commit
5dbfa2850e
@ -29,16 +29,12 @@ script:
|
||||
- cargo test
|
||||
- cargo test --features backup
|
||||
- cargo test --features blob
|
||||
- cargo test --features functions
|
||||
- cargo test --features limits
|
||||
- cargo test --features load_extension
|
||||
- cargo test --features trace
|
||||
- cargo test --features chrono
|
||||
- cargo test --features serde_json
|
||||
- cargo test --features bundled
|
||||
- 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"
|
||||
|
||||
# Travis CI runs on Ubuntu precise, which has SQLite 3.7.x. Our `functions` feature requires
|
||||
# 3.8.3, so omit tests for functions by itself and combined with other features. It is still
|
||||
# tested above when combined with the `bundled` feature.
|
||||
# - cargo test --features functions
|
||||
# - cargo test --features "backup blob chrono functions limits load_extension serde_json trace"
|
||||
|
@ -68,7 +68,7 @@ features](http://doc.crates.io/manifest.html#the-features-section). They are:
|
||||
allows use of SQLite's online backup API.
|
||||
* [`functions`](http://jgallagher.github.io/rusqlite/rusqlite/functions/index.html)
|
||||
allows you to load Rust closures into SQLite connections for use in queries.
|
||||
Note: This feature requires SQLite 3.8.3 or later.
|
||||
Note: This feature requires SQLite 3.7.3 or later.
|
||||
* [`trace`](http://jgallagher.github.io/rusqlite/rusqlite/trace/index.html)
|
||||
allows hooks into SQLite's tracing and profiling APIs.
|
||||
* [`blob`](http://jgallagher.github.io/rusqlite/rusqlite/blob/index.html)
|
||||
|
@ -3,6 +3,8 @@ extern crate gcc;
|
||||
extern crate pkg_config;
|
||||
|
||||
use std::env;
|
||||
use std::io::Write;
|
||||
use std::fs::OpenOptions;
|
||||
use bindgen::chooser::{TypeChooser, IntKind};
|
||||
use std::path::Path;
|
||||
|
||||
@ -22,13 +24,35 @@ impl TypeChooser for SqliteTypeChooser {
|
||||
fn run_bindgen<T: Into<String>>(header: T) {
|
||||
let out_dir = env::var("OUT_DIR").unwrap();
|
||||
let header = header.into();
|
||||
let _ = bindgen::builder()
|
||||
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_to_file(Path::new(&out_dir).join("bindgen.rs"));
|
||||
.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"))]
|
||||
|
Loading…
Reference in New Issue
Block a user