1diff --git a/android/bindgen_cmd/Android.bp b/android/bindgen_cmd/Android.bp 2new file mode 100644 3index 0000000..9189742 4--- /dev/null 5+++ b/android/bindgen_cmd/Android.bp 6@@ -0,0 +1,29 @@ 7+package { 8+ // See: http://go/android-license-faq 9+ // A large-scale-change added 'default_applicable_licenses' to import 10+ // all of the 'license_kinds' from "external_rust_crates_bindgen_license" 11+ // to get the below license kinds: 12+ // SPDX-license-identifier-Apache-2.0 13+ default_applicable_licenses: ["external_rust_crates_bindgen_license"], 14+} 15+ 16+rust_library_host { 17+ name: "libbindgen_cmd", 18+ host_cross_supported: false, 19+ crate_name: "bindgen_cmd", 20+ srcs: ["src/lib.rs"], 21+ edition: "2018", 22+ features: [ 23+ "clap", 24+ "runtime", 25+ "which", 26+ "which-rustfmt", 27+ ], 28+ rustlibs: [ 29+ "libbindgen", 30+ "libbindgen_cli", 31+ "libclap", 32+ "libenv_logger", 33+ ], 34+ compile_multilib: "first", 35+} 36diff --git a/android/bindgen_cmd/src/lib.rs b/android/bindgen_cmd/src/lib.rs 37new file mode 100644 38index 0000000..d33da7f 39--- /dev/null 40+++ b/android/bindgen_cmd/src/lib.rs 41@@ -0,0 +1,50 @@ 42+// Copyright 2020, The Android Open Source Project 43+// 44+// Licensed under the Apache License, Version 2.0 (the "License"); 45+// you may not use this file except in compliance with the License. 46+// You may obtain a copy of the License at 47+// 48+// http://www.apache.org/licenses/LICENSE-2.0 49+// 50+// Unless required by applicable law or agreed to in writing, software 51+// distributed under the License is distributed on an "AS IS" BASIS, 52+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 53+// See the License for the specific language governing permissions and 54+// limitations under the License. 55+ 56+//! This is a helper crate for using bindgen as a library from within 57+//! Android's build system. Some functionality (such as the type selection 58+//! heuristic) is not available on the command line, and so the library 59+//! interface may be necessary. Bindgen also needs to receive configuration 60+//! from Soong however to find appropriate headers, set global cflags, etc. 61+//! 62+//! This crate provides the ability to run a hooked version of the command 63+//! line bindgen tool, with the ability to call a user-provided transformation 64+//! on the the builder before it is used. 65+ 66+use bindgen; 67+use bindgen_cli; 68+use std::env; 69+ 70+/// Takes in a function describing adjustments to make to a builder 71+/// initialized by the command line. `build(|x| x)` is equivalent to 72+/// running bindgen. When converting a build.rs, you will want to convert the 73+/// additional configuration they do into a function, then pass it to `build` 74+/// inside your main function. 75+pub fn build<C: FnOnce(bindgen::Builder) -> bindgen::Builder>(configure: C) { 76+ env_logger::init(); 77+ 78+ match bindgen_cli::builder_from_flags(env::args()) { 79+ Ok((builder, output, _)) => { 80+ configure(builder) 81+ .generate() 82+ .expect("Unable to generate bindings") 83+ .write(output) 84+ .expect("Unable to write output"); 85+ } 86+ Err(error) => { 87+ eprintln!("{}", error); 88+ std::process::exit(1); 89+ } 90+ }; 91+} 92