Add Android.bp
The Android.bp file is manually written due to:
1. Binding to Android's existing copy of grpc instead of
the copy that is bundled within the crate.
2. The crates customized grpc_wrap.cc file that provides
additional translation logic.
3. A lot of bindgen customizations in build.rs.
Test: build
Change-Id: I80ae57aa66702d55f2a5985d52d5705bc21c6de1
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..2915827
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,100 @@
+rust_library {
+ name: "libgrpcio_sys",
+ // has rustc warnings
+ host_supported: true,
+ crate_name: "grpcio_sys",
+ srcs: [
+ "src/lib.rs",
+ ":libgrpc_bindgen",
+ ],
+ edition: "2018",
+ features: [
+ "default",
+ "secure",
+ ],
+ rustlibs: [
+ "liblibc",
+ "liblibz_sys",
+ ],
+ shared_libs: [
+ "libgrpc++",
+ "libgrpc_wrap"
+ ],
+}
+
+cc_defaults {
+ name: "libgrpcio_sys_defaults",
+ cflags: [
+ "-xc++",
+ "-std=c++11",
+ "-DGRPC_SYS_SECURE",
+ ],
+ shared_libs: ["libgrpc++"],
+}
+
+cc_library {
+ name: "libgrpc_wrap",
+ defaults: ["libgrpcio_sys_defaults"],
+ host_supported: true,
+ srcs: ["grpc_wrap.cc"],
+}
+
+rust_bindgen {
+ name: "libgrpc_bindgen",
+ defaults: ["libgrpcio_sys_defaults"],
+ host_supported: true,
+ wrapper_src: "android/bindgen_wrapper.hpp",
+ source_stem: "grpc-bindings",
+ crate_name: "grpc_bindgen",
+ bindgen_flags: [
+ "--size_t-is-usize",
+ "--constified-enum-module grpc_status_code",
+ "--default-enum-style rust",
+ "--whitelist-function=\\bgrpc_.*",
+ "--whitelist-function=\\bgpr_.*",
+ "--whitelist-function=gpr_inf_future",
+ "--whitelist-function=\\bgrpcwrap_.*",
+ "--whitelist-var=\\bGRPC_.*",
+ "--whitelist-type=\\bgrpc_.*",
+ "--whitelist-type=\\bgpr_.*",
+ "--whitelist-type=\\bgrpcwrap_.*",
+ "--whitelist-type=\\bcensus_context.*",
+ "--whitelist-type=\\bverify_peer_options.*",
+ "--blacklist-type=(__)?pthread.*",
+ "--blacklist-function=\\bgpr_mu_.*",
+ "--blacklist-function=\\bgpr_cv_.*",
+ "--blacklist-function=\\bgpr_once_.*",
+ "--blacklist-type=gpr_mu",
+ "--blacklist-type=gpr_cv",
+ "--blacklist-type=gpr_once",
+ ]
+}
+// dependent_library ["feature_list"]
+// aho-corasick-0.7.13 "default,std"
+// bindgen-0.51.1
+// bitflags-1.2.1 "default"
+// cc-1.0.60
+// cexpr-0.3.6
+// cfg-if-0.1.10
+// clang-sys-0.28.1 "clang_6_0,gte_clang_3_6,gte_clang_3_7,gte_clang_3_8,gte_clang_3_9,gte_clang_4_0,gte_clang_5_0,gte_clang_6_0,libloading,runtime"
+// cmake-0.1.44
+// glob-0.3.0
+// lazy_static-1.4.0
+// libc-0.2.77 "default,std"
+// libloading-0.5.2
+// libz-sys-1.1.2 "default,libc,static,stock-zlib"
+// memchr-2.3.3 "default,std,use_std"
+// nom-4.2.3 "alloc,default,std,verbose-errors"
+// peeking_take_while-0.1.2
+// pkg-config-0.3.18
+// proc-macro2-1.0.21
+// quote-1.0.7
+// regex-1.3.9 "aho-corasick,default,memchr,perf,perf-cache,perf-dfa,perf-inline,perf-literal,std,thread_local,unicode,unicode-age,unicode-bool,unicode-case,unicode-gencat,unicode-perl,unicode-script,unicode-segment"
+// regex-syntax-0.6.18 "default,unicode,unicode-age,unicode-bool,unicode-case,unicode-gencat,unicode-perl,unicode-script,unicode-segment"
+// rustc-hash-1.1.0 "default,std"
+// same-file-1.0.6
+// shlex-0.1.1
+// thread_local-1.0.1
+// unicode-xid-0.2.1 "default"
+// version_check-0.1.5
+// walkdir-2.3.1
diff --git a/README.android b/README.android
index 671fbcf..8273005 100644
--- a/README.android
+++ b/README.android
@@ -1,5 +1,16 @@
This package is imported to Android and uses Android's external/grpc-grpc
header files and compilation flags to generate bindings.
+The Android.bp file is manually written due to:
+ 1. Binding to Android's existing copy of grpc instead of
+ the copy that is bundled within the crate.
+ 2. The crates customized grpc_wrap.cc file that provides
+ additional translation logic.
+ 3. A lot of bindgen customizations in build.rs.
+
+The following line is added to android/bindgen_wrapper.h. It's unclear why this
+is necessary, but building the grpcio crate fails without it.
+#include <grpc/support/cpu.h>
+
If features are changed for the grpcio-sys crate, please ensure those
-features are changed in the grpcio_bindgen_build module.
+features are changed in the grpcio_bindgen module.
diff --git a/android/bindgen_wrapper.hpp b/android/bindgen_wrapper.hpp
new file mode 100644
index 0000000..6e2274b
--- /dev/null
+++ b/android/bindgen_wrapper.hpp
@@ -0,0 +1,2 @@
+#include <grpc/support/cpu.h>
+#include "../grpc_wrap.cc"
diff --git a/patches/env.diff b/patches/env.diff
new file mode 100644
index 0000000..f6155c5
--- /dev/null
+++ b/patches/env.diff
@@ -0,0 +1,16 @@
+diff --git a/src/lib.rs b/src/lib.rs
+index dc0699c..bd4e4fa 100644
+--- a/src/lib.rs
++++ b/src/lib.rs
+@@ -5,7 +5,10 @@
+ #![allow(non_upper_case_globals)]
+ #[allow(clippy::all)]
+ mod bindings {
+- include!(env!("BINDING_PATH"));
++ //include!(env!("BINDING_PATH"));
++ // ANDROID's build system doesn't support environment variables
++ // so we hardcode the output location of the bindings here.
++ include!(concat!(env!("OUT_DIR"), "/grpc-bindings.rs"));
+ }
+ mod grpc_wrap;
+
diff --git a/src/lib.rs b/src/lib.rs
index dc0699c..bd4e4fa 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -5,7 +5,10 @@
#![allow(non_upper_case_globals)]
#[allow(clippy::all)]
mod bindings {
- include!(env!("BINDING_PATH"));
+ //include!(env!("BINDING_PATH"));
+ // ANDROID's build system doesn't support environment variables
+ // so we hardcode the output location of the bindings here.
+ include!(concat!(env!("OUT_DIR"), "/grpc-bindings.rs"));
}
mod grpc_wrap;