Skip to content
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

core: add portable-atomic support #3199

Merged
merged 3 commits into from
Mar 31, 2025
Merged

Conversation

bushrat011899
Copy link
Contributor

Motivation

Solution

  • Added portable-atomic-util as an optional dependency gated behind a new feature, portable-atomic to tracing-core
  • When portable-atomic is enabled, switched uses of Arc and Weak away from alloc::sync to portable_atomic_util.
  • Added workaround for a lack of support for unsized coercion in custom types. I've included a comment linking to this issue explaining the missing functionality.

Notes

I'm currently working on no_std support for the Bevy Game Engine, which includes targeting embedded devices without full native support for atomics, such as the RP2040 Raspberry Pi Pico. Using portable-atomic, users can provide a fallback implementation for atomics to libraries (typically through critical-section), allowing libraries to depend on atomics even on unsupported platforms. This PR would allow using tracing on more platforms without sacrificing ergonomics or performance on existing ones.

This is my first time contributing to tracing, so please reach out if there's anything I can do to help with reviewing and merging this change!

Copy link

@BD103 BD103 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me!

Copy link
Contributor

@hds hds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this change! Looks good!

@hds hds changed the title Add portable-atomic support to tracing-core core: add portable-atomic support Mar 31, 2025
@hds hds merged commit 7a3ddfb into tokio-rs:master Mar 31, 2025
55 checks passed
hds pushed a commit that referenced this pull request Apr 10, 2025
This PR expands [`portable-atomic`](https://docs.rs/portable-atomic/)
utilisation within Tracing, improving platform support without breaking
the existing public API.

## Motivation

Since #3199 was merged, it's now possible to bring more tracing crates
to atomically challenged platforms through `portable-atomic`.
Additionally, CI is not currently setup to ensure this feature behaves
as expected (allowing compilation on platforms with incomplete atomic
support).

## Solution

- Added `portable-atomic` support to:
  - `tracing`
  - `tracing-futures`
  - `tracing-serde`
  - `tracing-subscriber`
- Added `no_std` support to:
  - `tracing-macros`
  - `tracing-futures`
- Added CI task to catch regressions in `portable-atomic` _and_ `no_std`
  support.

## Notes

- A `critical-section` feature is also added to make CI testing and
  usage of `tracing`/etc. on atomically challenged platforms simpler.
- No additional dependencies are included in this PR, optional or
  otherwise. Instances of including `portable-atomic` as a dependency
  only occur when it would have already been included transitively via
  `tracing-core`'s `portable-atomic-util` dependency.
- I checked all instances of replacing `core::sync::atomic` with
  `portable-atomic` to ensure the public API was unaffected. As such,
  this is not a breaking change, since it simply adds `portable-atomic`
  and `critical-section` features.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

portable-atomic support for alloc::sync in tracing-core
4 participants