Skip to content

Commit

Permalink
feat: add no-std and baremetal features
Browse files Browse the repository at this point in the history
Manual copy of changes done in:
https://github.com/malishav/rust-psa-crypto/tree/baremetal

Signed-off-by: Geovane Fedrecheski <[email protected]>
  • Loading branch information
geonnave committed Nov 28, 2023
1 parent da081a5 commit 2e08c80
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions psa-crypto-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ static = []
interface = ["bindgen"]
operations = ["interface"]
prefix = []
no-std = []
baremetal = ["no-std"]
21 changes: 17 additions & 4 deletions psa-crypto-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,17 @@ mod common {
));
}

let mbedtls_mode = if cfg!(feature = "baremetal") {
"crypto_baremetal"
} else {
"crypto"
};

// Configure the MbedTLS build for making Mbed Crypto
if !::std::process::Command::new(mbedtls_config)
.arg("--write")
.arg(&(out_dir + "/config.h"))
.arg("crypto")
.arg(mbedtls_mode)
.status()
.map_err(|_| Error::new(ErrorKind::Other, "configuring mbedtls failed"))?
.success()
Expand Down Expand Up @@ -136,6 +142,8 @@ mod common {
.blocklist_type("max_align_t")
.generate_comments(false)
.size_t_is_usize(true)
.use_core()
.ctypes_prefix("::core::ffi")
.generate()
.map_err(|_| {
Error::new(
Expand Down Expand Up @@ -251,12 +259,17 @@ mod operations {
}

// Build the MbedTLS libraries
let mbed_build_path = Config::new(&mbedtls_dir)
let mut mbed_build = Config::new(&mbedtls_dir);
let mbed_build = mbed_build
.cflag(format!("-I{}", out_dir))
.cflag("-DMBEDTLS_CONFIG_FILE='<config.h>'")
.define("ENABLE_PROGRAMS", "OFF")
.define("ENABLE_TESTING", "OFF")
.build();
.define("ENABLE_TESTING", "OFF");

#[cfg(feature = "baremetal")]
let mbed_build = mbed_build.define("CMAKE_TRY_COMPILE_TARGET_TYPE", "STATIC_LIBRARY");

let mbed_build_path = mbed_build.build();

Ok(mbed_build_path)
}
Expand Down
2 changes: 2 additions & 0 deletions psa-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ operations = ["psa-crypto-sys/operations", "interface"]
interface = ["psa-crypto-sys/interface"]
prefix = ["psa-crypto-sys/prefix"]
std = []
no-std = ["psa-crypto-sys/no-std"]
baremetal = ["no-std", "psa-crypto-sys/baremetal"]
1 change: 1 addition & 0 deletions psa-crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//! for a more complete description of operations and types.
//! This abstraction is built on top of the `psa-crypto-sys` crate.
#![cfg_attr(feature = "no-std", no_std)]
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(renamed_and_removed_lints, unknown_lints)]
#![deny(
Expand Down

0 comments on commit 2e08c80

Please sign in to comment.