Skip to content

Commit

Permalink
Make ESP-IDF support optional
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Oct 4, 2024
1 parent 50fef2d commit 9e97b8a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,20 @@ jobs:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="rdrand"
run: cargo build -Z build-std=core --target=${{ matrix.target }}

build-esp-idf:
name: ESP-IDF Build
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly # Required to build libcore
with:
components: rust-src
- uses: Swatinem/rust-cache@v2
- nv:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="esp_idf"
run: cargo build -Z build-std=core --target=riscv32imc-esp-espidf


build-no-atomics:
name: No Atomics Build
runs-on: ubuntu-22.04
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jobs:
- name: iOS (apple-other.rs)
run: cargo clippy -Zbuild-std=core --target x86_64-apple-ios
- name: ESP-IDF (espidf.rs)
env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="esp_idf"
run: cargo clippy -Zbuild-std=core --target riscv32imc-esp-espidf
- name: Fuchsia (fuchsia.rs)
run: cargo clippy -Zbuild-std=core --target x86_64-unknown-fuchsia
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ std = []
[lints.rust.unexpected_cfgs]
level = "warn"
check-cfg = [
'cfg(getrandom_backend, values("custom", "rdrand", "linux_getrandom", "wasm_js"))',
'cfg(getrandom_backend, values("custom", "rdrand", "linux_getrandom", "wasm_js", "esp_idf"))',
'cfg(getrandom_browser_test)',
]

Expand Down
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@
//! - `wasm_js`: use Web or Node.js APIs. Can be enabled only for OS-less
//! (i.e. `target_os = "unknown"`) WASM targets.
//! - `rdrand`: use RDRAND instruction. Can be enabled only for x86 and x86-64 targets.
//! - `esp_idf`: use [`esp_fill_random`]. Note that without a proper hardware configuration
//! it may return poor quality entropy. Can be enabled only for ESP-IDF trgets.
//! - `custom`: use "custom" backend defined by an extern function.
//! See the "custom implementations" section for more information.
//!
Expand Down Expand Up @@ -266,6 +268,10 @@ cfg_if! {
)))]
compile_error!("`wasm_js` backend can be enabled only on OS-less WASM targets!");
#[path = "js.rs"] mod imp;
} else if #[cfg(getrandom_backend = "esp_idf")] {
#[cfg(not(target_os = "espidf"))]
compile_error!("`esp_idf` backend can be enabled only for ESP-IDF targets!");
#[path = "espidf.rs"] mod imp;
} else if #[cfg(any(
target_os = "haiku",
target_os = "redox",
Expand Down Expand Up @@ -361,8 +367,6 @@ cfg_if! {
#[path = "vxworks.rs"] mod imp;
} else if #[cfg(target_os = "solid_asp3")] {
#[path = "solid.rs"] mod imp;
} else if #[cfg(target_os = "espidf")] {
#[path = "espidf.rs"] mod imp;
} else if #[cfg(all(windows, target_vendor = "win7"))] {
#[path = "windows7.rs"] mod imp;
} else if #[cfg(windows)] {
Expand Down

0 comments on commit 9e97b8a

Please sign in to comment.