Skip to content

no_std compatibility #703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
121 changes: 71 additions & 50 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,81 @@
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
- uses: Swatinem/rust-cache@v2
- name: Run cargo check
run: cargo check
check:
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Run cargo check
run: cargo check

docs:
name: Check Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Run cargo doc
run: cargo doc --workspace --no-deps --document-private-items --keep-going
env:
RUSTDOCFLAGS: "-D warnings"
check-compiles-no-std:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target:
- "x86_64-unknown-none"
- "wasm32v1-none"
- "thumbv6m-none-eabi"
dimensions:
- "2d"
- "3d"
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- name: Run cargo check
run: cargo check -p avian${{ matrix.dimensions }} --no-default-features --features "${{ matrix.dimensions }} f32 parry-f32 libm" --target ${{ matrix.target }}

test:
name: Test Suite
strategy:
matrix:
# TODO: Add ubuntu-latest back. It had CI storage issues, so it's left out for now.
os: [windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Run cargo test
run: cargo test --no-default-features --features enhanced-determinism,collider-from-mesh,serialize,debug-plugin,avian2d/2d,avian3d/3d,avian2d/f64,avian3d/f64,default-collider,parry-f64,bevy_scene,bevy_picking,diagnostic_ui
docs:
name: Check Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Run cargo doc
run: cargo doc --workspace --no-deps --document-private-items --keep-going
env:
RUSTDOCFLAGS: "-D warnings"

lints:
name: Lints
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Run cargo fmt
run: cargo fmt --all -- --check
- name: Run cargo clippy
run: cargo clippy -- -D warnings
test:
name: Test Suite
strategy:
matrix:
# TODO: Add ubuntu-latest back. It had CI storage issues, so it's left out for now.
os: [windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Run cargo test
run: cargo test --no-default-features --features std,enhanced-determinism,collider-from-mesh,serialize,debug-plugin,avian2d/2d,avian3d/3d,avian2d/f64,avian3d/f64,default-collider,parry-f64,bevy_scene,bevy_picking,diagnostic_ui

lints:
name: Lints
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Run cargo fmt
run: cargo fmt --all -- --check
- name: Run cargo clippy
run: cargo clippy -- -D warnings
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ std_instead_of_core = "warn"

[profile.dev]
opt-level = 1 # Use slightly better optimization, so examples work

[patch.crates-io]
nalgebra = { git = "https://github.com/Jondolf/nalgebra", branch = "glam-no-default-features" }
78 changes: 78 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
disallowed-methods = [
# f32
{ path = "f32::powi", reason = "use math_ops::FloatPow::squared, math_ops::FloatPow::cubed, or math_ops::powf instead for libm determinism" },
{ path = "f32::log", reason = "use math_ops::ln, math_ops::log2, or math_ops::log10 instead for libm determinism" },
{ path = "f32::abs_sub", reason = "deprecated and deeply confusing method" },
{ path = "f32::powf", reason = "use math_ops::powf instead for libm determinism" },
{ path = "f32::exp", reason = "use math_ops::exp instead for libm determinism" },
{ path = "f32::exp2", reason = "use math_ops::exp2 instead for libm determinism" },
{ path = "f32::ln", reason = "use math_ops::ln instead for libm determinism" },
{ path = "f32::log2", reason = "use math_ops::log2 instead for libm determinism" },
{ path = "f32::log10", reason = "use math_ops::log10 instead for libm determinism" },
{ path = "f32::cbrt", reason = "use math_ops::cbrt instead for libm determinism" },
{ path = "f32::hypot", reason = "use math_ops::hypot instead for libm determinism" },
{ path = "f32::sin", reason = "use math_ops::sin instead for libm determinism" },
{ path = "f32::cos", reason = "use math_ops::cos instead for libm determinism" },
{ path = "f32::tan", reason = "use math_ops::tan instead for libm determinism" },
{ path = "f32::asin", reason = "use math_ops::asin instead for libm determinism" },
{ path = "f32::acos", reason = "use math_ops::acos instead for libm determinism" },
{ path = "f32::atan", reason = "use math_ops::atan instead for libm determinism" },
{ path = "f32::atan2", reason = "use math_ops::atan2 instead for libm determinism" },
{ path = "f32::sin_cos", reason = "use math_ops::sin_cos instead for libm determinism" },
{ path = "f32::exp_m1", reason = "use math_ops::exp_m1 instead for libm determinism" },
{ path = "f32::ln_1p", reason = "use math_ops::ln_1p instead for libm determinism" },
{ path = "f32::sinh", reason = "use math_ops::sinh instead for libm determinism" },
{ path = "f32::cosh", reason = "use math_ops::cosh instead for libm determinism" },
{ path = "f32::tanh", reason = "use math_ops::tanh instead for libm determinism" },
{ path = "f32::asinh", reason = "use math_ops::asinh instead for libm determinism" },
{ path = "f32::acosh", reason = "use math_ops::acosh instead for libm determinism" },
{ path = "f32::atanh", reason = "use math_ops::atanh instead for libm determinism" },
# f64
{ path = "f64::powi", reason = "use math_ops::FloatPow::squared, math_ops::FloatPow::cubed, or math_ops::powf instead for libm determinism" },
{ path = "f64::log", reason = "use math_ops::ln, math_ops::log2, or math_ops::log10 instead for libm determinism" },
{ path = "f64::abs_sub", reason = "deprecated and deeply confusing method" },
{ path = "f64::powf", reason = "use math_ops::powf instead for libm determinism" },
{ path = "f64::exp", reason = "use math_ops::exp instead for libm determinism" },
{ path = "f64::exp2", reason = "use math_ops::exp2 instead for libm determinism" },
{ path = "f64::ln", reason = "use math_ops::ln instead for libm determinism" },
{ path = "f64::log2", reason = "use math_ops::log2 instead for libm determinism" },
{ path = "f64::log10", reason = "use math_ops::log10 instead for libm determinism" },
{ path = "f64::cbrt", reason = "use math_ops::cbrt instead for libm determinism" },
{ path = "f64::hypot", reason = "use math_ops::hypot instead for libm determinism" },
{ path = "f64::sin", reason = "use math_ops::sin instead for libm determinism" },
{ path = "f64::cos", reason = "use math_ops::cos instead for libm determinism" },
{ path = "f64::tan", reason = "use math_ops::tan instead for libm determinism" },
{ path = "f64::asin", reason = "use math_ops::asin instead for libm determinism" },
{ path = "f64::acos", reason = "use math_ops::acos instead for libm determinism" },
{ path = "f64::atan", reason = "use math_ops::atan instead for libm determinism" },
{ path = "f64::atan2", reason = "use math_ops::atan2 instead for libm determinism" },
{ path = "f64::sin_cos", reason = "use math_ops::sin_cos instead for libm determinism" },
{ path = "f64::exp_m1", reason = "use math_ops::exp_m1 instead for libm determinism" },
{ path = "f64::ln_1p", reason = "use math_ops::ln_1p instead for libm determinism" },
{ path = "f64::sinh", reason = "use math_ops::sinh instead for libm determinism" },
{ path = "f64::cosh", reason = "use math_ops::cosh instead for libm determinism" },
{ path = "f64::tanh", reason = "use math_ops::tanh instead for libm determinism" },
{ path = "f64::asinh", reason = "use math_ops::asinh instead for libm determinism" },
{ path = "f64::acosh", reason = "use math_ops::acosh instead for libm determinism" },
{ path = "f64::atanh", reason = "use math_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.
# f32
{ path = "f32::rem_euclid", reason = "use math_ops::rem_euclid instead for no_std compatibility" },
{ path = "f32::abs", reason = "use math_ops::abs instead for no_std compatibility" },
{ path = "f32::sqrt", reason = "use math_ops::sqrt instead for no_std compatibility" },
{ path = "f32::copysign", reason = "use math_ops::copysign instead for no_std compatibility" },
{ path = "f32::round", reason = "use math_ops::round instead for no_std compatibility" },
{ path = "f32::floor", reason = "use math_ops::floor instead for no_std compatibility" },
{ path = "f32::ceil", reason = "use math_ops::ceil instead for no_std compatibility" },
{ path = "f32::fract", reason = "use math_ops::fract instead for no_std compatibility" },
# f64
{ path = "f64::rem_euclid", reason = "use math_ops::rem_euclid instead for no_std compatibility" },
{ path = "f64::abs", reason = "use math_ops::abs instead for no_std compatibility" },
{ path = "f64::sqrt", reason = "use math_ops::sqrt instead for no_std compatibility" },
{ path = "f64::copysign", reason = "use math_ops::copysign instead for no_std compatibility" },
{ path = "f64::round", reason = "use math_ops::round instead for no_std compatibility" },
{ path = "f64::floor", reason = "use math_ops::floor instead for no_std compatibility" },
{ path = "f64::ceil", reason = "use math_ops::ceil instead for no_std compatibility" },
{ path = "f64::fract", reason = "use math_ops::fract instead for no_std compatibility" },
]
67 changes: 48 additions & 19 deletions crates/avian2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ categories = ["game-development", "science", "simulation"]

[features]
default = [
"std",
"2d",
"f32",
"parry-f32",
Expand All @@ -28,15 +29,14 @@ f64 = []
debug-plugin = ["bevy/bevy_gizmos", "bevy/bevy_render"]
simd = ["parry2d?/simd-stable", "parry2d-f64?/simd-stable"]
parallel = [
"std",
"dep:thread_local",
"bevy/multi_threaded",
"parry2d?/parallel",
"parry2d-f64?/parallel",
]
enhanced-determinism = [
"dep:libm",
"bevy_math/libm",
"bevy_heavy/libm",
"libm",
"parry2d?/enhanced-determinism",
"parry2d-f64?/enhanced-determinism",
]
Expand Down Expand Up @@ -65,6 +65,23 @@ bevy_diagnostic = []
# Enables the `PhysicsDiagnosticsUiPlugin` for visualizing physics diagnostics data with a debug UI.
diagnostic_ui = ["bevy_diagnostic", "bevy/bevy_ui"]

# Enable the Rust standard library.
std = [
"bevy/std",
"bevy_heavy/std",
"bevy_transform_interpolation/std",
"parry2d?/std",
"parry2d-f64?/std",
]

# Enable `libm` math operations for `no_std` environments and cross-platform determinism.
libm = [
"dep:libm",
"bevy/libm",
"bevy_heavy/libm",
"bevy_transform_interpolation/libm",
]

[lib]
name = "avian2d"
path = "../../src/lib.rs"
Expand All @@ -73,23 +90,36 @@ bench = false

[dependencies]
avian_derive = { path = "../avian_derive", version = "0.2" }
bevy = { version = "0.16.0-rc", default-features = false, features = [
"std",
"bevy_log",
bevy = { version = "0.16.0-rc", default-features = false }
bevy_math = { version = "0.16.0-rc", default-features = false }
bevy_heavy = { git = "https://github.com/Jondolf/bevy_heavy", default-features = false, features = [
"2d",
"3d",
"bevy_reflect",
] }
bevy_math = { version = "0.16.0-rc" }
bevy_heavy = { git = "https://github.com/Jondolf/bevy_heavy" }
bevy_transform_interpolation = { git = "https://github.com/Jondolf/bevy_transform_interpolation" }
bevy_transform_interpolation = { git = "https://github.com/Jondolf/bevy_transform_interpolation", default-features = false }
libm = { version = "0.2", optional = true }
parry2d = { version = "0.17", optional = true }
parry2d-f64 = { version = "0.17", optional = true }
nalgebra = { version = "0.33", features = ["convert-glam029"], optional = true }
serde = { version = "1", features = ["derive"], optional = true }
derive_more = "1"
arrayvec = "0.7"
itertools = "0.13"
bitflags = "2.5.0"
thread_local = { version = "1.1", optional = true }
parry2d = { version = "0.19", optional = true, default-features = false, features = [
"required-features",
"alloc",
] }
parry2d-f64 = { version = "0.19", optional = true, default-features = false, features = [
"required-features",
"alloc",
] }
nalgebra = { version = "0.33", default-features = false, features = [
"convert-glam029",
], optional = true }
serde = { version = "1", default-features = false, features = [
"derive",
], optional = true }
derive_more = { version = "1", default-features = false }
log = { version = "0.4", default-features = false }
arrayvec = { version = "0.7", default-features = false }
hashbrown = { version = "0.15", default-features = false }
itertools = { version = "0.13", default-features = false }
bitflags = { version = "2.5.0", default-features = false }
thread_local = { version = "1.1", default-features = false, optional = true }

[dev-dependencies]
examples_common_2d = { path = "../examples_common_2d" }
Expand All @@ -98,7 +128,6 @@ bevy_math = { version = "0.16.0-rc", features = ["approx"] }
bevy_heavy = { git = "https://github.com/Jondolf/bevy_heavy", features = [
"approx",
] }
glam = { version = "0.29", features = ["bytemuck"] }
approx = "0.5"
bytemuck = "1.19"
criterion = { version = "0.5", features = ["html_reports"] }
Expand Down
Loading
Loading