aboutsummaryrefslogtreecommitdiff
path: root/Android.bp
diff options
context:
space:
mode:
authorChih-Hung Hsieh <chh@google.com>2020-07-29 20:55:10 -0700
committerMatthew Maurer <mmaurer@google.com>2020-07-31 17:20:42 +0000
commit9a627fb93631cf79914d2cf7f3058da40ae8fd96 (patch)
treea91c0514764f14e896506abd108cfb722070c8e7 /Android.bp
parenta78ad196da209ef8df6943088b28adb6a88443af (diff)
downloadlibsqlite3-sys-9a627fb93631cf79914d2cf7f3058da40ae8fd96.tar.gz
Generate target dependent bindings for Rust
* Bindings for external/sqlite are generated with the header file and clang flags used there. * Saved binding files are called bindings.rs and they are compared with build time generated bindgen.rs files to check for any new changes in sqlite or bindgen. * bindings.rs is a better file name used here. libsqlite3-sys has been using bindgen.rs for its include file. To minimize changes to libsqlite3-sys, we named the genrule output files bindgen.rs. * A temporary hack in genrule calls sed to change u32 type to i32 to match current expectation. The sed output is compared (diff -U3) with manually verified and saved bindings.rs before use. Any error in sed or diff will stop a make. After manual verification, the diff -U3 output can be applied to saved bindings.rs. Test: make with both aosp_x86_64-eng and aosp_arm64-eng Test: make with new rusqlite and dependent packages Test: atest -c --include-subdirs external/rust/crates/libsqlite3-sys Change-Id: I14838c2c08f3f966e22d3846aad980c232a2f43e
Diffstat (limited to 'Android.bp')
-rw-r--r--Android.bp200
1 files changed, 200 insertions, 0 deletions
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..e007749
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,200 @@
+// This file is generated by cargo2android.py --device --run --dependencies --test.
+
+// We renamed the shared_libs dependence from libsqlite3 to libsqlite.
+
+rust_library {
+ name: "liblibsqlite3_sys",
+ host_supported: true,
+ crate_name: "libsqlite3_sys",
+ srcs: ["src/lib.rs"],
+ edition: "2018",
+ // Note that the following features are default for this package,
+ // unrelated to the generation of bindings for external/sqlite.
+ // We might need to consider the non-default features for Android.
+ // If you add/change features, please check any impact to bindgen flags.
+ features: [
+ "default",
+ "min_sqlite_version_3_6_8",
+ "pkg-config",
+ "vcpkg",
+ ],
+ shared_libs: [
+ "libsqlite",
+ ],
+ arch: {
+ // depend on external/sqlite/rust bindgen modules
+ // and include the output file from those modules
+ x86: {
+ srcs: [":sqlite3_bindgen_x86"],
+ },
+ x86_64: {
+ srcs: [":sqlite3_bindgen_x86_64"],
+ },
+ arm: {
+ srcs: [":sqlite3_bindgen_arm"],
+ },
+ arm64: {
+ srcs: [":sqlite3_bindgen_arm64"],
+ },
+ },
+}
+
+rust_defaults {
+ name: "libsqlite3-sys_defaults",
+ crate_name: "libsqlite3_sys",
+ srcs: ["src/lib.rs"],
+ test_suites: ["general-tests"],
+ auto_gen_config: true,
+ edition: "2018",
+ features: [
+ "default",
+ "min_sqlite_version_3_6_8",
+ "pkg-config",
+ "vcpkg",
+ ],
+ shared_libs: [
+ "libsqlite",
+ ],
+ arch: {
+ // depend on external/sqlite/rust bindgen modules
+ // and include the output file from those modules
+ x86: {
+ srcs: [":sqlite3_bindgen_x86"],
+ },
+ x86_64: {
+ srcs: [":sqlite3_bindgen_x86_64"],
+ },
+ arm: {
+ srcs: [":sqlite3_bindgen_arm"],
+ },
+ arm64: {
+ srcs: [":sqlite3_bindgen_arm64"],
+ },
+ },
+}
+
+rust_test_host {
+ name: "libsqlite3-sys_host_test_src_lib",
+ defaults: ["libsqlite3-sys_defaults"],
+}
+
+rust_test {
+ name: "libsqlite3-sys_device_test_src_lib",
+ defaults: ["libsqlite3-sys_defaults"],
+}
+
+// dependent_library ["feature_list"]
+// pkg-config-0.3.18
+
+// Extra modules to generate bindings for external/sqlite.
+// Generated file is called bindgen.rs and saved into android/<arch>/bindings.rs.
+
+common_bindgen_flags = " -o $(out) $(in) -- -MD -MF $(depfile)"
+
+// Here is the place to add bindgen flags for sqlite3.
+// The following ignore options are copied from build.rs.
+sqlite3_bindgen_flags =
+ " --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"
+
+// The cflags defined in cc_defaults of external/sqlite/dist/Android.bp
+// should be passed to clang for bindgen.
+// The list of strings used in cflags cannot be easily
+// shared with the command string used in genrule yet,
+// since there is no string join function in .bp.
+sqlite3_bindgen_clang_flags = " -I external/sqlite/dist"
+ + " -DNDEBUG=1"
+ + " -DHAVE_USLEEP=1"
+ + " -DSQLITE_HAVE_ISNAN"
+ + " -DSQLITE_DEFAULT_JOURNAL_SIZE_LIMIT=1048576"
+ + " -DSQLITE_THREADSAFE=2"
+ + " -DSQLITE_TEMP_STORE=3"
+ + " -DSQLITE_POWERSAFE_OVERWRITE=1"
+ + " -DSQLITE_DEFAULT_FILE_FORMAT=4"
+ + " -DSQLITE_DEFAULT_AUTOVACUUM=1"
+ + " -DSQLITE_ENABLE_MEMORY_MANAGEMENT=1"
+ + " -DSQLITE_ENABLE_FTS3"
+ + " -DSQLITE_ENABLE_FTS3_BACKWARDS"
+ + " -DSQLITE_ENABLE_FTS4"
+ + " -DSQLITE_OMIT_BUILTIN_TEST"
+ + " -DSQLITE_OMIT_COMPILEOPTION_DIAGS"
+ + " -DSQLITE_OMIT_LOAD_EXTENSION"
+ + " -DSQLITE_DEFAULT_FILE_PERMISSIONS=0600"
+ + " -DSQLITE_SECURE_DELETE"
+ + " -DSQLITE_ENABLE_BATCH_ATOMIC_WRITE"
+ + " -DBIONIC_IOCTL_NO_SIGNEDNESS_OVERLOAD"
+ + " -DHAVE_POSIX_FALLOCATE=1"
+ // extra -D flags for android targets
+ + " -DUSE_PREAD64"
+ + " -Dfdatasync=fdatasync"
+ + " -DHAVE_MALLOC_H=1"
+ + " -DHAVE_MALLOC_USABLE_SIZE"
+ + " -Wno-unused-parameter"
+
+genrule_defaults {
+ name: "sqlite3_bindgen_defaults",
+ tools: ["bindgen.sh", "bindgen"],
+ depfile: true,
+ srcs: ["android/bindgen.h"],
+ out: ["bindgen.rs"],
+}
+
+// This is a temporary hack to fix bindgen output files,
+// until a newer bindgen can do it with a flag.
+// The default int type for macros are changed
+// from u32 to i32 to work with other existing Rust.
+// Both u32 and i32 values should work with C libsqlite
+// as those macros have values in both i32 and u32 range.
+// See comments in later genrule modules about diff/patch
+// to detect and fix errors.
+bindgen_post_edit_cmd = " sed -i 's/: u32 /: i32 /' $(out) &&"
+
+genrule_default_cmd = "$(location bindgen.sh)"
+ + sqlite3_bindgen_flags
+ + common_bindgen_flags
+ + sqlite3_bindgen_clang_flags
+
+// In these genrule modules, diff -U3 is used to check if the
+// generated files are the same as the saved version.
+// This also catches any change made by bindgen_post_edit_cmd.
+// Any sed command failure or output difference will stop the genrule module.
+// To fix and resume the build, the diff -U3 output in stdout should
+// be saved and passed to the 'patch' command to fix the bindings.rs file.
+// The changes to bindgings.rs should be manually verified and tested.
+genrule {
+ name: "sqlite3_bindgen_x86",
+ defaults: ["sqlite3_bindgen_defaults"],
+ cmd: genrule_default_cmd + " --target=i386 &&"
+ + bindgen_post_edit_cmd
+ + " diff -U3 `dirname $(in)`/x86/bindings.rs $(out)",
+}
+
+genrule {
+ name: "sqlite3_bindgen_x86_64",
+ defaults: ["sqlite3_bindgen_defaults"],
+ cmd: genrule_default_cmd + " --target=x86_64 &&"
+ + bindgen_post_edit_cmd
+ + " diff -U3 `dirname $(in)`/x86_64/bindings.rs $(out)",
+}
+
+genrule {
+ name: "sqlite3_bindgen_arm",
+ defaults: ["sqlite3_bindgen_defaults"],
+ cmd: genrule_default_cmd + " --target=arm &&"
+ + bindgen_post_edit_cmd
+ + " diff -U3 `dirname $(in)`/arm/bindings.rs $(out)",
+}
+
+genrule {
+ name: "sqlite3_bindgen_arm64",
+ defaults: ["sqlite3_bindgen_defaults"],
+ cmd: genrule_default_cmd + " --target=arm64 &&"
+ + bindgen_post_edit_cmd
+ + " diff -U3 `dirname $(in)`/arm64/bindings.rs $(out)",
+}