Skip to content

Commit

Permalink
psa-crypto-sys: dedup build.rs
Browse files Browse the repository at this point in the history
De-duplicate the build configuration for mbedtls.

Signed-off-by: Bill Roberts <[email protected]>
  • Loading branch information
billatarm committed Dec 20, 2023
1 parent e8cec13 commit f8ba20e
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions psa-crypto-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f8ba20e

Please sign in to comment.