Generate bindings rather than using prebuilts
In order to pass some of the configuration that Android.bp has, we need
to pass in a function. Now that bindgen-as-a-library support has landed
in the build system, use it for libsqlite3-sys to avoid needing to
regenerate bindings.
Bug: 161816141
Test: mma
Change-Id: I53d4108f5e6ab0d6e47e8d6d1b24a93b1c66a7fe
diff --git a/android/build.rs b/android/build.rs
new file mode 100644
index 0000000..bced585
--- /dev/null
+++ b/android/build.rs
@@ -0,0 +1,43 @@
+use bindgen_cmd;
+use bindgen::callbacks::{IntKind, ParseCallbacks};
+
+#[derive(Debug)]
+struct SqliteTypeChooser;
+
+impl ParseCallbacks 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 main() {
+ bindgen_cmd::build(|mut builder| {
+ builder = builder
+ .parse_callbacks(Box::new(SqliteTypeChooser))
+ .rustfmt_bindings(true)
+ .blacklist_function("sqlite3_vmprintf")
+ .blacklist_function("sqlite3_vsnprintf")
+ .blacklist_function("sqlite3_str_vappendf")
+ .blacklist_type("va_list")
+ .blacklist_type("__builtin_va_list")
+ .blacklist_type("__gnuc_va_list")
+ .blacklist_type("__va_list_tag")
+ .blacklist_item("__GNUC_VA_LIST");
+
+ if cfg!(feature = "unlock_notify") {
+ builder = builder.clang_arg("-DSQLITE_ENABLE_UNLOCK_NOTIFY");
+ }
+ if cfg!(feature = "preupdate_hook") {
+ builder = builder.clang_arg("-DSQLITE_ENABLE_PREUPDATE_HOOK");
+ }
+ if cfg!(feature = "session") {
+ builder = builder.clang_arg("-DSQLITE_ENABLE_SESSION");
+ }
+
+ builder
+ })
+}