From 50d1a428dcde83a71ff79f5bd3a591a941e75150 Mon Sep 17 00:00:00 2001 From: chrysn Date: Fri, 12 Apr 2024 14:25:21 +0200 Subject: [PATCH] random: Make available as riot_rs::random; rename laze feature to match --- Cargo.lock | 1 + examples/random/Cargo.toml | 7 +++---- examples/random/laze.yml | 2 +- examples/random/src/main.rs | 2 +- laze-project.yml | 6 +++++- src/riot-rs/Cargo.toml | 3 +++ src/riot-rs/src/lib.rs | 3 +++ 7 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 559adf91c..2cf695a5e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2375,6 +2375,7 @@ dependencies = [ "riot-rs-debug", "riot-rs-embassy", "riot-rs-macros", + "riot-rs-random", "riot-rs-rt", "riot-rs-threads", "static_cell", diff --git a/examples/random/Cargo.toml b/examples/random/Cargo.toml index 7bc791234..fe2987f00 100644 --- a/examples/random/Cargo.toml +++ b/examples/random/Cargo.toml @@ -6,10 +6,9 @@ edition.workspace = true publish = false [dependencies] -# not enabling riot-rs/hwrng even though it's currently needed -- laze takes -# care of that. -riot-rs = { path = "../../src/riot-rs", features = ["threading"] } +# Enabling the feature "random" is somewhat redundant with laze.yml's selects: +# random, but helps with interactive tools. +riot-rs = { path = "../../src/riot-rs", features = ["threading", "random"] } riot-rs-boards = { path = "../../src/riot-rs-boards" } -riot-rs-random = { version = "0.1.0", path = "../../src/riot-rs-random" } rand = { version = "0.8.5", default-features = false } diff --git a/examples/random/laze.yml b/examples/random/laze.yml index 667cd8551..9a7c82f97 100644 --- a/examples/random/laze.yml +++ b/examples/random/laze.yml @@ -2,4 +2,4 @@ apps: - name: random selects: - ?release - - rng + - random diff --git a/examples/random/src/main.rs b/examples/random/src/main.rs index 89333a3f6..f2c272a47 100644 --- a/examples/random/src/main.rs +++ b/examples/random/src/main.rs @@ -8,7 +8,7 @@ use riot_rs::debug::println; #[riot_rs::thread(autostart)] fn main() { use rand::Rng as _; - let mut rng = riot_rs_random::get_rng(); + let mut rng = riot_rs::random::get_rng(); let value = rng.gen_range(1..=6); diff --git a/laze-project.yml b/laze-project.yml index ca53586bd..22c45845c 100644 --- a/laze-project.yml +++ b/laze-project.yml @@ -514,11 +514,15 @@ modules: FEATURES: - riot-rs/hwrng - - name: rng + - name: random help: A system-wide RNG is available depends: # could later alternatively depend on mutable config storage - hwrng + env: + global: + FEATURES: + - riot-rs/random - name: sw/benchmark help: provided if a target supports `benchmark()` diff --git a/src/riot-rs/Cargo.toml b/src/riot-rs/Cargo.toml index 976309521..e0ed9fb11 100644 --- a/src/riot-rs/Cargo.toml +++ b/src/riot-rs/Cargo.toml @@ -16,6 +16,7 @@ riot-rs-buildinfo = { path = "../riot-rs-buildinfo" } riot-rs-debug = { workspace = true } riot-rs-embassy = { path = "../riot-rs-embassy" } riot-rs-macros = { path = "../riot-rs-macros" } +riot-rs-random = { path = "../riot-rs-random", optional = true } riot-rs-rt = { path = "../riot-rs-rt" } riot-rs-threads = { path = "../riot-rs-threads", optional = true } static_cell = { workspace = true } @@ -44,6 +45,8 @@ threading = [ ## Enables support for timeouts in the internal executor---required to use ## `embassy_time::Timer`. time = ["riot-rs-embassy/time"] +## Enables the riot-rs-random module. +random = ["riot-rs-random"] ## Enables seeding the random number generator from hardware. hwrng = ["riot-rs-embassy/hwrng"] diff --git a/src/riot-rs/src/lib.rs b/src/riot-rs/src/lib.rs index ce516d039..cc0124290 100644 --- a/src/riot-rs/src/lib.rs +++ b/src/riot-rs/src/lib.rs @@ -14,6 +14,9 @@ pub use riot_rs_bench as bench; pub use riot_rs_buildinfo as buildinfo; pub use riot_rs_debug as debug; pub use riot_rs_embassy::{self as embassy, define_peripherals, group_peripherals}; +#[cfg(feature = "random")] +#[doc(inline)] +pub use riot_rs_random as random; pub use riot_rs_rt as rt; // Attribute macros