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 Jan 3, 2024
1 parent 50c95e3 commit 899e219
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions psa-crypto-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,40 +140,27 @@ 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 mut shim_builder = bindgen::Builder::default()

Check failure on line 144 in psa-crypto-sys/build.rs

View workflow job for this annotation

GitHub Actions / All tests: rustc MSRV

variable does not need to be mutable

Check failure on line 144 in psa-crypto-sys/build.rs

View workflow job for this annotation

GitHub Actions / All tests: rustc stable

variable does not need to be mutable
.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()
.map_err(|_| {
Error::new(
ErrorKind::Other,
"Unable to generate bindings to mbed crypto",
)
})?;
{
shim_builder = shim_builder.parse_callbacks(Box::new(RenameCallbacks {}));
}
// Build the bindings
let shim_bindings = shim_builder.generate().map_err(|_| {
Error::new(
ErrorKind::Other,
"Unable to generate bindings to mbed crypto",
)
})?;

let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
shim_bindings.write_to_file(out_path.join("shim_bindings.rs"))?;
Expand Down

0 comments on commit 899e219

Please sign in to comment.