bevy/crates/bevy_ecs/src
Zachary Harrold 76e9bf9c99
Automatically enable portable-atomic when required (#17570)
# Objective

- Contributes to #15460
- Reduce quantity and complexity of feature gates across Bevy

## Solution

- Used `target_has_atomic` configuration variable to automatically
detect impartial atomic support and automatically switch to
`portable-atomic` over the standard library on an as-required basis.

## Testing

- CI

## Notes

To explain the technique employed here, consider getting `Arc` either
from `alloc::sync` _or_ `portable-atomic-util`. First, we can inspect
the `alloc` crate to see that you only have access to `Arc` _if_
`target_has_atomic = "ptr"`. We add a target dependency for this
particular configuration _inverted_:

```toml
[target.'cfg(not(target_has_atomic = "ptr"))'.dependencies]
portable-atomic-util = { version = "0.2.4", default-features = false }
```

This ensures we only have the dependency when it is needed, and it is
entirely excluded from the dependency graph when it is not. Next, we
adjust our configuration flags to instead of checking for `feature =
"portable-atomic"` to instead check for `target_has_atomic = "ptr"`:

```rust
// `alloc` feature flag hidden for brevity

#[cfg(not(target_has_atomic = "ptr"))]
use portable_atomic_util as arc;

#[cfg(target_has_atomic = "ptr")]
use alloc::sync as arc;

pub use arc::{Arc, Weak};
```

The benefits of this technique are three-fold:

1. For platforms without full atomic support, the functionality is
enabled automatically.
2. For platforms with atomic support, the dependency is never included,
even if a feature was enabled using `--all-features` (for example)
3. The `portable-atomic` feature no longer needs to virally spread to
all user-facing crates, it's instead something handled within
`bevy_platform_support` (with some extras where other dependencies also
need their features enabled).
2025-02-24 20:52:46 +00:00
..
entity Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
event Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
identifier Harden proc macro path resolution and add integration tests. (#17330) 2025-02-09 19:45:45 +00:00
observer Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
query Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
reflect Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
relationship Add EntityDoesNotExistError, replace cases of Entity as an error, do some easy Resultification (#17855) 2025-02-16 21:59:46 +00:00
schedule Use explicitly added ApplyDeferred stages when computing automatically inserted sync points. (#16782) 2025-02-24 20:51:34 +00:00
storage Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
system Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
world Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
archetype.rs Move hashbrown and foldhash out of bevy_utils (#17460) 2025-01-23 16:46:08 +00:00
batching.rs Fix *most* clippy lints (#15906) 2024-10-14 20:52:35 +00:00
bundle.rs Encapsulate cfg(feature = "track_location") in a type. (#17602) 2025-02-10 21:21:20 +00:00
change_detection.rs Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
component.rs Automatically enable portable-atomic when required (#17570) 2025-02-24 20:52:46 +00:00
entity_disabling.rs Allow users to register their own disabling components / default query filters (#17768) 2025-02-11 18:25:32 +00:00
hierarchy.rs Improve the docs for ChildOf and Children (#17886) 2025-02-17 01:46:11 +00:00
intern.rs Move hashbrown and foldhash out of bevy_utils (#17460) 2025-01-23 16:46:08 +00:00
label.rs Fix issue with define_label! instantiation in a 3rd party crate (#17958) 2025-02-21 06:13:36 +00:00
lib.rs Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
name.rs Harden proc macro path resolution and add integration tests. (#17330) 2025-02-09 19:45:45 +00:00
removal_detection.rs Harden proc macro path resolution and add integration tests. (#17330) 2025-02-09 19:45:45 +00:00
resource.rs Move Resource trait to its own file (#17469) 2025-01-21 19:47:08 +00:00
result.rs feat(ecs): configurable error handling for fallible systems (#17753) 2025-02-11 18:36:08 +00:00
spawn.rs Improved Spawn APIs and Bundle Effects (#17521) 2025-02-09 23:32:56 +00:00
traversal.rs Relationships (non-fragmenting, one-to-many) (#17398) 2025-01-18 22:20:30 +00:00