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:
John Gallagher 2017-02-08 21:41:34 -05:00
parent 644166fa5b
commit 5dbfa2850e
3 changed files with 29 additions and 9 deletions

View File

@ -29,16 +29,12 @@ script:
- cargo test - cargo test
- cargo test --features backup - cargo test --features backup
- cargo test --features blob - cargo test --features blob
- cargo test --features functions
- cargo test --features limits - cargo test --features limits
- cargo test --features load_extension - cargo test --features load_extension
- cargo test --features trace - 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 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"
# 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"

View File

@ -68,7 +68,7 @@ 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.8.3 or later. 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)

View File

@ -3,6 +3,8 @@ extern crate gcc;
extern crate pkg_config; extern crate pkg_config;
use std::env; use std::env;
use std::io::Write;
use std::fs::OpenOptions;
use bindgen::chooser::{TypeChooser, IntKind}; use bindgen::chooser::{TypeChooser, IntKind};
use std::path::Path; use std::path::Path;
@ -22,13 +24,35 @@ impl TypeChooser for SqliteTypeChooser {
fn run_bindgen<T: Into<String>>(header: T) { fn run_bindgen<T: Into<String>>(header: T) {
let out_dir = env::var("OUT_DIR").unwrap(); let out_dir = env::var("OUT_DIR").unwrap();
let header = header.into(); let header = header.into();
let _ = bindgen::builder() let mut output = Vec::new();
bindgen::builder()
.header(header.clone()) .header(header.clone())
.ctypes_prefix("::libc") .ctypes_prefix("::libc")
.type_chooser(Box::new(SqliteTypeChooser)) .type_chooser(Box::new(SqliteTypeChooser))
.generate() .generate()
.expect(&format!("could not run bindgen on header {}", header)) .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"))] #[cfg(not(feature = "bundled"))]