1 /* -*- Mode: rust; rust-indent-offset: 4 -*- */
5 use bindgen::callbacks::*;
9 use std::path::PathBuf;
12 struct PKCS11TypesParseCallbacks;
14 impl ParseCallbacks for PKCS11TypesParseCallbacks {
15 fn int_macro(&self, name: &str, _value: i64) -> Option<IntKind> {
16 if name == "CK_TRUE" || name == "CK_FALSE" {
25 println!("cargo:rerun-if-changed=wrapper.h");
27 let bindings = Builder::default()
29 .allowlist_function("C_GetFunctionList")
30 .allowlist_type("CK_RSA_PKCS_PSS_PARAMS")
31 .allowlist_type("CK_OBJECT_CLASS")
32 .allowlist_type("CK_KEY_TYPE")
33 .allowlist_type("CK_C_INITIALIZE_ARGS_PTR")
34 .allowlist_var("CK_TRUE")
35 .allowlist_var("CK_FALSE")
36 .allowlist_var("CK_UNAVAILABLE_INFORMATION")
37 .allowlist_var("CK_EFFECTIVELY_INFINITE")
38 .allowlist_var("CK_INVALID_HANDLE")
39 .allowlist_var("CKP_PUBLIC_CERTIFICATES_TOKEN")
40 .allowlist_var("CKA_.*")
41 .allowlist_var("CKC_.*")
42 .allowlist_var("CKD_.*")
43 .allowlist_var("CKF_.*")
44 .allowlist_var("CKK_.*")
45 .allowlist_var("CKM_.*")
46 .allowlist_var("CKO_.*")
47 .allowlist_var("CKR_.*")
49 .parse_callbacks(Box::new(PKCS11TypesParseCallbacks))
51 .expect("Unable to generate bindings");
53 let out_path = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR should be set in env"));
55 .write_to_file(out_path.join("bindings.rs"))
56 .expect("Couldn't write bindings!");