From e8b31057022f8f767d28196afe6aa71951f9f16f Mon Sep 17 00:00:00 2001 From: Joona Aalto Date: Sat, 22 Mar 2025 21:43:23 +0200 Subject: [PATCH 1/4] Verify `no_std` support in CI --- .github/workflows/ci.yml | 87 ++++++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 35 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6fcebcf..edfc6f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,44 +1,61 @@ name: CI on: - push: - branches: - - main - pull_request: + push: + branches: + - main + pull_request: env: - CARGO_TERM_COLOR: always + CARGO_TERM_COLOR: always jobs: - check: - name: Check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@stable - - name: Run cargo check - run: cargo check + check: + name: Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - name: Run cargo check + run: cargo check - test: - name: Test Suite - strategy: - matrix: - os: [windows-latest, ubuntu-latest, macos-latest] - runs-on: ${{ matrix.os }} - timeout-minutes: 60 - steps: - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@stable - - name: Run cargo test - run: cargo test --all-features + check-compiles-no-std: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + target: + - "x86_64-unknown-none" + - "wasm32v1-none" + - "thumbv6m-none-eabi" + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.target }} + - name: Run cargo check + run: cargo check --no-default-features --features libm --target ${{ matrix.target }} - lints: - name: Lints - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@stable - - name: Run cargo fmt - run: cargo fmt --all -- --check - - name: Run cargo clippy - run: cargo clippy -- -D warnings + test: + name: Test Suite + strategy: + matrix: + os: [windows-latest, ubuntu-latest, macos-latest] + runs-on: ${{ matrix.os }} + timeout-minutes: 60 + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - name: Run cargo test + run: cargo test --all-features + + lints: + name: Lints + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - name: Run cargo fmt + run: cargo fmt --all -- --check + - name: Run cargo clippy + run: cargo clippy -- -D warnings From 4fd5aebd778ab3bfb66366d6e31d16c5dd1a4e61 Mon Sep 17 00:00:00 2001 From: Joona Aalto Date: Sat, 22 Mar 2025 21:43:55 +0200 Subject: [PATCH 2/4] Add more `f32` methods to `clippy.toml` --- clippy.toml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/clippy.toml b/clippy.toml index 5d1d260..f1ad427 100644 --- a/clippy.toml +++ b/clippy.toml @@ -26,4 +26,13 @@ disallowed-methods = [ { path = "f32::asinh", reason = "use ops::asinh instead for libm determinism" }, { path = "f32::acosh", reason = "use ops::acosh instead for libm determinism" }, { path = "f32::atanh", reason = "use ops::atanh instead for libm determinism" }, + # These methods have defined precision, but are only available from the standard library, + # not in core. Using these substitutes allows for no_std compatibility. + { path = "f32::rem_euclid", reason = "use ops::rem_euclid instead for no_std compatibility" }, + { path = "f32::abs", reason = "use ops::abs instead for no_std compatibility" }, + { path = "f32::sqrt", reason = "use ops::sqrt instead for no_std compatibility" }, + { path = "f32::copysign", reason = "use ops::copysign instead for no_std compatibility" }, + { path = "f32::round", reason = "use ops::round instead for no_std compatibility" }, + { path = "f32::floor", reason = "use ops::floor instead for no_std compatibility" }, + { path = "f32::fract", reason = "use ops::fract instead for no_std compatibility" }, ] From 9896f966786697e67899f875fbf93d55e446af31 Mon Sep 17 00:00:00 2001 From: Joona Aalto Date: Sat, 22 Mar 2025 21:44:09 +0200 Subject: [PATCH 3/4] Fix call to `round` --- src/hermite.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hermite.rs b/src/hermite.rs index e80c57e..6009ebf 100644 --- a/src/hermite.rs +++ b/src/hermite.rs @@ -432,7 +432,7 @@ pub fn hermite_quat(qa: Quat, qb: Quat, w0: Vec3, w1: Vec3, t: f32, unwrap: bool // l dot(n, n) = l = dot(p - a, n) let extra_angle = w01_direction.dot(average_w_div_3 - w01_div_3); - w01_div_3 += (extra_angle / TAU).round() * TAU * w01_direction; + w01_div_3 += ops::round(extra_angle / TAU) * TAU * w01_direction; } // Rotate by b1 * dt / 3 at initial velocity, then by b2 * dt / 3 at w01, then by b3 * dt / 3 at final velocity. From cb61514f7e742e88b96593cf56c28bc6c3ad5805 Mon Sep 17 00:00:00 2001 From: Joona Aalto Date: Sat, 22 Mar 2025 22:09:26 +0200 Subject: [PATCH 4/4] Add `critical-section` feature --- .github/workflows/ci.yml | 2 +- Cargo.toml | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index edfc6f1..6e96b9f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,7 @@ jobs: with: targets: ${{ matrix.target }} - name: Run cargo check - run: cargo check --no-default-features --features libm --target ${{ matrix.target }} + run: cargo check --no-default-features --features libm,critical-section --target ${{ matrix.target }} test: name: Test Suite diff --git a/Cargo.toml b/Cargo.toml index ca8b9b9..5b10f27 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,14 +14,17 @@ categories = ["game-development"] [features] default = ["std"] +# Enable data serialization/deserialization using `serde`. +serialize = ["dep:serde", "bevy/serialize"] + # Enable the Rust standard library. std = ["bevy/std"] # Enable `libm` math operations for `no_std` environments and cross-platform determinism. libm = ["bevy/libm"] -# Enable data serialization/deserialization using `serde`. -serialize = ["dep:serde", "bevy/serialize"] +# Rely on `critical-section` for synchronization primitives. +critical-section = ["bevy/critical-section"] [dependencies] bevy = { version = "0.16.0-rc.1", default-features = false }