xref: /aosp_15_r20/tools/netsim/rust/hostapd-rs/build_cargo.rs (revision cf78ab8cffb8fc9207af348f23af247fb04370a6)
1 // Copyright 2024 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 //! Build script for generating `hostapd` bindings.
16 
17 use bindgen;
18 use std::env;
19 use std::path::PathBuf;
20 
main()21 pub fn main() {
22     println!("cargo:rerun-if-changed=bindings/wrapper.h");
23     println!("cargo:rerun-if-changed=build.rs");
24 
25     let bindings = bindgen::Builder::default()
26         .header("bindings/wrapper.h")
27         .generate()
28         .expect("Unable to generate bindings");
29 
30     let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
31     let out_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap())
32         .join("src")
33         .join("hostapd_sys")
34         .join(target_os);
35 
36     std::fs::create_dir_all(&out_dir).expect("Failed to create output directory");
37 
38     let out_path = out_dir.join("bindings.rs");
39     bindings.write_to_file(out_path).expect("Couldn't write bindings!");
40 }
41