Skip to content

Commit ea9f07f

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
1 parent da081a5 commit ea9f07f

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

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"]

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
}

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"]

psa-crypto/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//! for a more complete description of operations and types.
1010
//! This abstraction is built on top of the `psa-crypto-sys` crate.
1111
12+
#![cfg_attr(feature = "no-std", no_std)]
1213
#![cfg_attr(not(feature = "std"), no_std)]
1314
#![allow(renamed_and_removed_lints, unknown_lints)]
1415
#![deny(

0 commit comments

Comments
 (0)