Merge pull request #1360 from gwenn/SQLITE_DETERMINISTIC

Simplify bindgen generation
This commit is contained in:
gwenn 2023-07-08 11:39:47 +02:00 committed by GitHub
commit 4196c2b496
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -487,7 +487,6 @@ mod bindings {
use super::HeaderLocation; use super::HeaderLocation;
use bindgen::callbacks::{IntKind, ParseCallbacks}; use bindgen::callbacks::{IntKind, ParseCallbacks};
use std::fs;
use std::path::Path; use std::path::Path;
use super::win_target; use super::win_target;
@ -522,7 +521,6 @@ mod bindings {
pub fn write_to_out_dir(header: HeaderLocation, out_path: &Path) { pub fn write_to_out_dir(header: HeaderLocation, out_path: &Path) {
let header: String = header.into(); let header: String = header.into();
let mut output = Vec::new();
let mut bindings = bindgen::builder() let mut bindings = bindgen::builder()
.default_macro_constant_type(bindgen::MacroTypeVariation::Signed) .default_macro_constant_type(bindgen::MacroTypeVariation::Signed)
.disable_nested_struct_naming() .disable_nested_struct_naming()
@ -631,21 +629,7 @@ mod bindings {
.layout_tests(false) .layout_tests(false)
.generate() .generate()
.unwrap_or_else(|_| panic!("could not run bindgen on header {}", header)) .unwrap_or_else(|_| panic!("could not run bindgen on header {}", header))
.write(Box::new(&mut output)) .write_to_file(out_path)
.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");
}
fs::write(out_path, output.as_bytes())
.unwrap_or_else(|_| panic!("Could not write to {:?}", out_path)); .unwrap_or_else(|_| panic!("Could not write to {:?}", out_path));
} }
} }