| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
use std::{env, path::PathBuf}; |
| 5 |
|
| 6 |
fn main() { |
| 7 |
println!("cargo:rerun-if-changed=wrapper.h"); |
| 8 |
|
| 9 |
let s2n_tls_sys_dir = PathBuf::from("../../extended/s2n-tls-sys"); |
| 10 |
let s2n_lib_include_path = s2n_tls_sys_dir.join("lib"); |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
let libcrypto_include_path = std::env::vars() |
| 15 |
.find_map(|(k, v)| { |
| 16 |
|
| 17 |
if k.starts_with("DEP_AWS_LC_") && k.ends_with("_INCLUDE") { |
| 18 |
Some(v) |
| 19 |
} else { |
| 20 |
None |
| 21 |
} |
| 22 |
}) |
| 23 |
.expect("No DEP_AWS_LC_*_INCLUDE environment variable found"); |
| 24 |
|
| 25 |
let bindings = bindgen::Builder::default() |
| 26 |
|
| 27 |
.header("wrapper.h") |
| 28 |
.clang_arg(format!("-I{}", s2n_lib_include_path.display())) |
| 29 |
.clang_arg(format!("-I{}/api", s2n_lib_include_path.display())) |
| 30 |
.clang_arg(format!("-I{}", libcrypto_include_path)) |
| 31 |
.size_t_is_usize(true) |
| 32 |
.allowlist_type("s2n_security_policy_selection") |
| 33 |
.allowlist_type("s2n_security_policy") |
| 34 |
.allowlist_type("s2n_cipher_preferences") |
| 35 |
.allowlist_type("s2n_cipher_suite") |
| 36 |
.allowlist_type("s2n_ecc_preferences") |
| 37 |
.allowlist_type("s2n_ecc_named_curve") |
| 38 |
.allowlist_type("s2n_kem_preferences") |
| 39 |
.allowlist_type("s2n_kem_group") |
| 40 |
.allowlist_var("security_policy_selection") |
| 41 |
.generate() |
| 42 |
.expect("Unable to generate bindings"); |
| 43 |
|
| 44 |
|
| 45 |
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); |
| 46 |
bindings |
| 47 |
.write_to_file(out_path.join("bindings.rs")) |
| 48 |
.expect("Couldn't write bindings!"); |
| 49 |
} |