From 9e97b8aa0def176d448d17c52539ee1ab4b1a340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Fri, 4 Oct 2024 21:27:16 +0300 Subject: [PATCH] Make ESP-IDF support optional --- .github/workflows/tests.yml | 14 ++++++++++++++ .github/workflows/workspace.yml | 2 ++ Cargo.toml | 2 +- src/lib.rs | 8 ++++++-- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 024b2723..491d7f5f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 diff --git a/.github/workflows/workspace.yml b/.github/workflows/workspace.yml index a51d034a..a230e1c9 100644 --- a/.github/workflows/workspace.yml +++ b/.github/workflows/workspace.yml @@ -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 diff --git a/Cargo.toml b/Cargo.toml index ed10e1ea..9a1ca11e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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)', ] diff --git a/src/lib.rs b/src/lib.rs index 0a9cbfac..a99088ff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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. //! @@ -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", @@ -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)] {