Skip to content

Commit 4d51c5d

Browse files
committed
feat: add no-std and baremetal features
Manual copy of changes done in: https://github.com/malishav/rust-psa-crypto/tree/baremetal Signed-off-by: Geovane Fedrecheski <[email protected]>
1 parent da081a5 commit 4d51c5d

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

Diff for: psa-crypto-sys/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ static = []
2424
interface = ["bindgen"]
2525
operations = ["interface"]
2626
prefix = []
27+
no-std = []
28+
baremetal = ["no-std"]

Diff for: psa-crypto-sys/build.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,17 @@ mod common {
8181
));
8282
}
8383

84+
let mbedtls_mode = if cfg!(feature = "baremetal") {
85+
"crypto_baremetal"
86+
} else {
87+
"crypto"
88+
};
89+
8490
// Configure the MbedTLS build for making Mbed Crypto
8591
if !::std::process::Command::new(mbedtls_config)
8692
.arg("--write")
8793
.arg(&(out_dir + "/config.h"))
88-
.arg("crypto")
94+
.arg(mbedtls_mode)
8995
.status()
9096
.map_err(|_| Error::new(ErrorKind::Other, "configuring mbedtls failed"))?
9197
.success()
@@ -136,6 +142,8 @@ mod common {
136142
.blocklist_type("max_align_t")
137143
.generate_comments(false)
138144
.size_t_is_usize(true)
145+
.use_core()
146+
.ctypes_prefix("::core::ffi")
139147
.generate()
140148
.map_err(|_| {
141149
Error::new(
@@ -251,12 +259,17 @@ mod operations {
251259
}
252260

253261
// Build the MbedTLS libraries
254-
let mbed_build_path = Config::new(&mbedtls_dir)
262+
let mut mbed_build = Config::new(&mbedtls_dir);
263+
let mbed_build = mbed_build
255264
.cflag(format!("-I{}", out_dir))
256265
.cflag("-DMBEDTLS_CONFIG_FILE='<config.h>'")
257266
.define("ENABLE_PROGRAMS", "OFF")
258-
.define("ENABLE_TESTING", "OFF")
259-
.build();
267+
.define("ENABLE_TESTING", "OFF");
268+
269+
#[cfg(feature = "baremetal")]
270+
let mbed_build = mbed_build.define("CMAKE_TRY_COMPILE_TARGET_TYPE", "STATIC_LIBRARY");
271+
272+
let mbed_build_path = mbed_build.build();
260273

261274
Ok(mbed_build_path)
262275
}

Diff for: psa-crypto-sys/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//! You can find the API
88
//! [here](https://developer.arm.com/architectures/security-architectures/platform-security-architecture/documentation).
99
10+
#![cfg_attr(feature = "no-std", no_std)]
1011
// This one is hard to avoid.
1112
#![allow(clippy::multiple_crate_versions)]
1213
#![allow(clippy::missing_safety_doc)]

Diff for: psa-crypto/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ operations = ["psa-crypto-sys/operations", "interface"]
2828
interface = ["psa-crypto-sys/interface"]
2929
prefix = ["psa-crypto-sys/prefix"]
3030
std = []
31+
no-std = ["psa-crypto-sys/no-std"]
32+
baremetal = ["no-std", "psa-crypto-sys/baremetal"]

0 commit comments

Comments
 (0)