Skip to content

Commit 6a7a471

Browse files
authored
Check no_std compatibility in CI and fix remaining use of std (#9)
# Objective It can be easy to accidentally break `no_std` compatibility. We should check it in CI! We're also missing some `f32` method lints in `clippy.toml`, and are still actually using `std::f32::round` in one place. ## Solution Add `no_std` checks to CI, and add the remaining `f32` method lints to `clippy.toml`. Through this I also discovered that we need a `critical-section` feature for Bevy in some `no_std` environments. The check is based on [`no_std` library example](https://github.com/bevyengine/bevy/tree/0244a841b78ea9a995880fea6733da21a6c0fea2/examples/no_std/library).
1 parent 694dddd commit 6a7a471

File tree

4 files changed

+67
-38
lines changed

4 files changed

+67
-38
lines changed

.github/workflows/ci.yml

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,61 @@
11
name: CI
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
pull_request:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
88

99
env:
10-
CARGO_TERM_COLOR: always
10+
CARGO_TERM_COLOR: always
1111

1212
jobs:
13-
check:
14-
name: Check
15-
runs-on: ubuntu-latest
16-
steps:
17-
- uses: actions/checkout@v4
18-
- uses: dtolnay/rust-toolchain@stable
19-
- name: Run cargo check
20-
run: cargo check
13+
check:
14+
name: Check
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: dtolnay/rust-toolchain@stable
19+
- name: Run cargo check
20+
run: cargo check
2121

22-
test:
23-
name: Test Suite
24-
strategy:
25-
matrix:
26-
os: [windows-latest, ubuntu-latest, macos-latest]
27-
runs-on: ${{ matrix.os }}
28-
timeout-minutes: 60
29-
steps:
30-
- uses: actions/checkout@v4
31-
- uses: dtolnay/rust-toolchain@stable
32-
- name: Run cargo test
33-
run: cargo test --all-features
22+
check-compiles-no-std:
23+
runs-on: ubuntu-latest
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
target:
28+
- "x86_64-unknown-none"
29+
- "wasm32v1-none"
30+
- "thumbv6m-none-eabi"
31+
steps:
32+
- uses: actions/checkout@v4
33+
- uses: dtolnay/rust-toolchain@stable
34+
with:
35+
targets: ${{ matrix.target }}
36+
- name: Run cargo check
37+
run: cargo check --no-default-features --features libm,critical-section --target ${{ matrix.target }}
3438

35-
lints:
36-
name: Lints
37-
runs-on: ubuntu-latest
38-
steps:
39-
- uses: actions/checkout@v4
40-
- uses: dtolnay/rust-toolchain@stable
41-
- name: Run cargo fmt
42-
run: cargo fmt --all -- --check
43-
- name: Run cargo clippy
44-
run: cargo clippy -- -D warnings
39+
test:
40+
name: Test Suite
41+
strategy:
42+
matrix:
43+
os: [windows-latest, ubuntu-latest, macos-latest]
44+
runs-on: ${{ matrix.os }}
45+
timeout-minutes: 60
46+
steps:
47+
- uses: actions/checkout@v4
48+
- uses: dtolnay/rust-toolchain@stable
49+
- name: Run cargo test
50+
run: cargo test --all-features
51+
52+
lints:
53+
name: Lints
54+
runs-on: ubuntu-latest
55+
steps:
56+
- uses: actions/checkout@v4
57+
- uses: dtolnay/rust-toolchain@stable
58+
- name: Run cargo fmt
59+
run: cargo fmt --all -- --check
60+
- name: Run cargo clippy
61+
run: cargo clippy -- -D warnings

Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@ categories = ["game-development"]
1414
[features]
1515
default = ["std"]
1616

17+
# Enable data serialization/deserialization using `serde`.
18+
serialize = ["dep:serde", "bevy/serialize"]
19+
1720
# Enable the Rust standard library.
1821
std = ["bevy/std"]
1922

2023
# Enable `libm` math operations for `no_std` environments and cross-platform determinism.
2124
libm = ["bevy/libm"]
2225

23-
# Enable data serialization/deserialization using `serde`.
24-
serialize = ["dep:serde", "bevy/serialize"]
26+
# Rely on `critical-section` for synchronization primitives.
27+
critical-section = ["bevy/critical-section"]
2528

2629
[dependencies]
2730
bevy = { version = "0.16.0-rc.1", default-features = false }

clippy.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,13 @@ disallowed-methods = [
2626
{ path = "f32::asinh", reason = "use ops::asinh instead for libm determinism" },
2727
{ path = "f32::acosh", reason = "use ops::acosh instead for libm determinism" },
2828
{ path = "f32::atanh", reason = "use ops::atanh instead for libm determinism" },
29+
# These methods have defined precision, but are only available from the standard library,
30+
# not in core. Using these substitutes allows for no_std compatibility.
31+
{ path = "f32::rem_euclid", reason = "use ops::rem_euclid instead for no_std compatibility" },
32+
{ path = "f32::abs", reason = "use ops::abs instead for no_std compatibility" },
33+
{ path = "f32::sqrt", reason = "use ops::sqrt instead for no_std compatibility" },
34+
{ path = "f32::copysign", reason = "use ops::copysign instead for no_std compatibility" },
35+
{ path = "f32::round", reason = "use ops::round instead for no_std compatibility" },
36+
{ path = "f32::floor", reason = "use ops::floor instead for no_std compatibility" },
37+
{ path = "f32::fract", reason = "use ops::fract instead for no_std compatibility" },
2938
]

src/hermite.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ pub fn hermite_quat(qa: Quat, qb: Quat, w0: Vec3, w1: Vec3, t: f32, unwrap: bool
432432
// l dot(n, n) = l = dot(p - a, n)
433433

434434
let extra_angle = w01_direction.dot(average_w_div_3 - w01_div_3);
435-
w01_div_3 += (extra_angle / TAU).round() * TAU * w01_direction;
435+
w01_div_3 += ops::round(extra_angle / TAU) * TAU * w01_direction;
436436
}
437437

438438
// Rotate by b1 * dt / 3 at initial velocity, then by b2 * dt / 3 at w01, then by b3 * dt / 3 at final velocity.

0 commit comments

Comments
 (0)