blob: cb9c65ba5189119b08628f76a716b2f483dcc835 [file] [log] [blame]
Matthew Maurercf0037d2024-10-09 21:38:29 +00001/*
2 * Copyright (C) 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use std::env;
18use std::path::PathBuf;
19
20fn main() {
21 let ndk_home = PathBuf::from(env::var("ANDROID_NDK_HOME").unwrap());
22 let toolchain = ndk_home.join("toolchains/llvm/prebuilt/linux-x86_64/");
23 let sysroot = toolchain.join("sysroot");
24 let bindings = bindgen::Builder::default()
25 .clang_arg(format!("--sysroot={}", sysroot.display()))
26 // TODO figure out what the "standard" #define is and use that instead
27 .header("BinderBindings.hpp")
28 .parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
29 // Keep in sync with libbinder_ndk_bindgen_flags.txt
30 .default_enum_style(bindgen::EnumVariation::Rust { non_exhaustive: true })
31 .constified_enum("android::c_interface::consts::.*")
32 .allowlist_type("android::c_interface::.*")
33 .allowlist_type("AStatus")
34 .allowlist_type("AIBinder_Class")
35 .allowlist_type("AIBinder")
36 .allowlist_type("AIBinder_Weak")
37 .allowlist_type("AIBinder_DeathRecipient")
38 .allowlist_type("AParcel")
39 .allowlist_type("binder_status_t")
40 .blocklist_function("vprintf")
41 .blocklist_function("strtold")
42 .blocklist_function("_vtlog")
43 .blocklist_function("vscanf")
44 .blocklist_function("vfprintf_worker")
45 .blocklist_function("vsprintf")
46 .blocklist_function("vsnprintf")
47 .blocklist_function("vsnprintf_filtered")
48 .blocklist_function("vfscanf")
49 .blocklist_function("vsscanf")
50 .blocklist_function("vdprintf")
51 .blocklist_function("vasprintf")
52 .blocklist_function("strtold_l")
53 .allowlist_function(".*")
54 .generate()
55 .expect("Couldn't generate bindings");
56 let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
57 bindings.write_to_file(out_path.join("bindings.rs")).expect("Couldn't write bindings.");
58 println!("cargo::rustc-link-lib=binder_ndk");
59}