Debian Codegraph @

crt/s2n/bindings/rust/standard/s2n-tls-sys-internal/build.rs

raw symbols SCIP
1 // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 // SPDX-License-Identifier: Apache-2.0
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 // Get the libcrypto headers path from aws-lc-sys, because clang needs them
13 // to run bindgen for s2n-tls.
14 let libcrypto_include_path = std::env::vars()
15 .find_map(|(k, v)| {
16 // find the include path, e.g. "DEP_AWS_LC_0_35_0_INCLUDE"
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 // The input header we would like to generate bindings for
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 // Write the bindings to the $OUT_DIR/bindings.rs file
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 }