From f8ba20e8a7f658ce1d979b6b2bed8a3f66a0c6ef Mon Sep 17 00:00:00 2001 From: Bill Roberts Date: Wed, 20 Dec 2023 14:09:57 -0600 Subject: [PATCH] psa-crypto-sys: dedup build.rs De-duplicate the build configuration for mbedtls. Signed-off-by: Bill Roberts --- psa-crypto-sys/build.rs | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/psa-crypto-sys/build.rs b/psa-crypto-sys/build.rs index 8282ad1..3ca9c23 100644 --- a/psa-crypto-sys/build.rs +++ b/psa-crypto-sys/build.rs @@ -137,34 +137,21 @@ mod common { let out_dir = env::var("OUT_DIR").unwrap(); - #[cfg(not(feature = "prefix"))] - let shim_bindings = bindgen::Builder::default() + // Common shim builder settings + let shim_builder = bindgen::Builder::default() .clang_arg(format!("-I{}", out_dir)) .clang_arg(format!("-DMBEDTLS_CONFIG_FILE={}", mbed_conf)) .clang_arg(format!("-I{}", mbed_include_dir)) .header("src/c/shim.h") .blocklist_type("max_align_t") .generate_comments(false) - .size_t_is_usize(true) - .generate() - .map_err(|_| { - Error::new( - ErrorKind::Other, - "Unable to generate bindings to mbed crypto", - ) - })?; + .size_t_is_usize(true); #[cfg(feature = "prefix")] - let shim_bindings = bindgen::Builder::default() - .clang_arg(format!("-I{}", out_dir)) - .clang_arg(format!("-DMBEDTLS_CONFIG_FILE={}", mbed_conf)) - .clang_arg(format!("-I{}", mbed_include_dir)) - .header("src/c/shim.h") - .blocklist_type("max_align_t") - .generate_comments(false) - .size_t_is_usize(true) - .parse_callbacks(Box::new(RenameCallbacks {})) - .generate() + shim_builder.parse_callbacks(Box::new(RenameCallbacks {})); + + // Build the bindings + let shim_bindings = shim_builder.generate() .map_err(|_| { Error::new( ErrorKind::Other,