diff options
| -rw-r--r-- | embassy/Cargo.toml | 5 | ||||
| -rw-r--r-- | embassy/src/rand.rs | 15 | ||||
| -rw-r--r-- | examples/.cargo/config (renamed from .cargo/config) | 0 | ||||
| -rwxr-xr-x | test-build.sh | 5 |
4 files changed, 23 insertions, 2 deletions
diff --git a/embassy/Cargo.toml b/embassy/Cargo.toml index 0e4c801bb..08d273dbb 100644 --- a/embassy/Cargo.toml +++ b/embassy/Cargo.toml | |||
| @@ -5,7 +5,7 @@ authors = ["Dario Nieuwenhuis <[email protected]>"] | |||
| 5 | edition = "2018" | 5 | edition = "2018" |
| 6 | 6 | ||
| 7 | [features] | 7 | [features] |
| 8 | std = ["futures/std"] | 8 | std = ["futures/std", "rand_core"] |
| 9 | defmt-trace = [] | 9 | defmt-trace = [] |
| 10 | defmt-debug = [] | 10 | defmt-debug = [] |
| 11 | defmt-info = [] | 11 | defmt-info = [] |
| @@ -16,6 +16,9 @@ defmt-error = [] | |||
| 16 | defmt = { version = "0.1.3", optional = true } | 16 | defmt = { version = "0.1.3", optional = true } |
| 17 | log = { version = "0.4.11", optional = true } | 17 | log = { version = "0.4.11", optional = true } |
| 18 | 18 | ||
| 19 | # std-only | ||
| 20 | rand_core = { version = "0.5.1", optional = true, features = ["std"] } | ||
| 21 | |||
| 19 | cortex-m = "0.6.4" | 22 | cortex-m = "0.6.4" |
| 20 | futures = { version = "0.3.5", default-features = false } | 23 | futures = { version = "0.3.5", default-features = false } |
| 21 | pin-project = { version = "1.0.2", default-features = false } | 24 | pin-project = { version = "1.0.2", default-features = false } |
diff --git a/embassy/src/rand.rs b/embassy/src/rand.rs index 7e3788380..6e78c24ae 100644 --- a/embassy/src/rand.rs +++ b/embassy/src/rand.rs | |||
| @@ -4,6 +4,9 @@ pub trait Rand { | |||
| 4 | fn rand(&self, buf: &mut [u8]); | 4 | fn rand(&self, buf: &mut [u8]); |
| 5 | } | 5 | } |
| 6 | 6 | ||
| 7 | #[cfg(feature = "std")] | ||
| 8 | static mut RAND: Option<&'static dyn Rand> = Some(&if_std::Rand); | ||
| 9 | #[cfg(not(feature = "std"))] | ||
| 7 | static mut RAND: Option<&'static dyn Rand> = None; | 10 | static mut RAND: Option<&'static dyn Rand> = None; |
| 8 | 11 | ||
| 9 | pub unsafe fn set_rand(rand: &'static dyn Rand) { | 12 | pub unsafe fn set_rand(rand: &'static dyn Rand) { |
| @@ -13,3 +16,15 @@ pub unsafe fn set_rand(rand: &'static dyn Rand) { | |||
| 13 | pub fn rand(buf: &mut [u8]) { | 16 | pub fn rand(buf: &mut [u8]) { |
| 14 | unsafe { unwrap!(RAND, "No rand set").rand(buf) } | 17 | unsafe { unwrap!(RAND, "No rand set").rand(buf) } |
| 15 | } | 18 | } |
| 19 | |||
| 20 | #[cfg(feature = "std")] | ||
| 21 | mod if_std { | ||
| 22 | use rand_core::{OsRng, RngCore}; | ||
| 23 | |||
| 24 | pub(crate) struct Rand; | ||
| 25 | impl super::Rand for Rand { | ||
| 26 | fn rand(&self, buf: &mut [u8]) { | ||
| 27 | OsRng.fill_bytes(buf) | ||
| 28 | } | ||
| 29 | } | ||
| 30 | } | ||
diff --git a/.cargo/config b/examples/.cargo/config index 3f319ae55..3f319ae55 100644 --- a/.cargo/config +++ b/examples/.cargo/config | |||
diff --git a/test-build.sh b/test-build.sh index ae603b289..52bf7bb7b 100755 --- a/test-build.sh +++ b/test-build.sh | |||
| @@ -5,7 +5,10 @@ set -euxo pipefail | |||
| 5 | # examples | 5 | # examples |
| 6 | (cd examples; cargo build --target thumbv7em-none-eabi --bins) | 6 | (cd examples; cargo build --target thumbv7em-none-eabi --bins) |
| 7 | 7 | ||
| 8 | # embassy | 8 | # embassy std |
| 9 | (cd embassy; cargo build --features log,std) | ||
| 10 | |||
| 11 | # embassy embedded | ||
| 9 | (cd embassy; cargo build --target thumbv7em-none-eabi) | 12 | (cd embassy; cargo build --target thumbv7em-none-eabi) |
| 10 | (cd embassy; cargo build --target thumbv7em-none-eabi --features log) | 13 | (cd embassy; cargo build --target thumbv7em-none-eabi --features log) |
| 11 | (cd embassy; cargo build --target thumbv7em-none-eabi --features defmt) | 14 | (cd embassy; cargo build --target thumbv7em-none-eabi --features defmt) |
