-
Notifications
You must be signed in to change notification settings - Fork 288
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
1.0.1 does not compile for arm-thumb-v6m targets (Cortex-M0) #461
Comments
This is because those targets do not support atomic CAS. See also rust-lang/rust#51953. The feature to handle this correctly on the library side is unstable, and some crates support it via the unstable feature flag (cfg-target-has-atomic feature in futures-rs, nightly feature in crossbeam, etc.). Technically bytes can do the same, but it may not be very helpful as Bytes, BytesMut, etc. are not available on those platforms. (If crates that depend on bytes are using it, the compile will fail anyway.) |
@henrikssn I have created a patch to support those targets (https://github.com/taiki-e/bytes/tree/cfg_target_has_atomic). Could you try if it solves the problem in your project? (in the way described below)
[patch.crates-io]
bytes = { git = "https://github.com/taiki-e/bytes", branch = "cfg_target_has_atomic" }
RUSTFLAGS="--cfg=bytes_unstable" cargo build |
Works like a charm! The packages I depend only use |
Is it possible to do a similar magic to allow |
while the patch allows compilation it now requires nightly, doesn't it? Would it instead be possible to just add a feature flag for |
atomic CAS (compare and swap) cannot be used in thumbv6m-none-eabi and
Adding an enabled by default feature that enables There is a way to avoid using unstable features, but there are some problems.
I don't think it's possible without breaking changes. |
If it never compiled, I don't think it would be a breaking change to support Thoughts? |
Separate create wouldn't help me since my hypothetical bytes dependence
would be transitive. What I really wanted to use was prost.
…On Fri, Feb 12, 2021, 11:39 Carl Lerche ***@***.***> wrote:
If it *never* compiled, I don't think it would be a breaking change to
support Bytes as a !Send and !Sync type on some platforms. That said, I'm
not sure if we *want* to do that :) It would *probably* be better to
support compilation of bytes on those platforms w/o the type entirely and
someone could implement a single-threaded Bytes type in a separate crate.
Thoughts?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#461 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAIN7S7OO7G2FN4IYBG7C2TS6VYWLANCNFSM4V77THFA>
.
|
I don't think this is preferable. This can make crates that currently manually implement |
Updated #467 to support stable Rust. |
Maybe I'm missing something, then I apologize upfront. Could using the following polyfill help in any way? |
That is unsound on multi-core systems. |
Right, but what about adding it as an optional feature? In this case, single thread applications (including interrupts) could make safe use of Bytes/BytesMut, which would be a huge benefit for systems like Cortex M0. |
Supporting it as an optional dependency is a bad idea if enabling it could cause unsoundness. One of the approachs to handle such cases soundly is to use the optional cfg as my portable-atomic crate does.
This prevents them from accidentally being compiled against a multi-core target unless the end-user explicitly guarantees that the target is single core. |
Thanks, makes absolute sense. Wow, what an awesome crate! My naive draft would be the following extension of your PR #467 #[cfg(not(all(test, loom)))]
pub(crate) mod sync {
pub(crate) mod atomic {
#[cfg(not(bytes_no_atomic_cas))]
pub(crate) use core::sync::atomic::{fence, AtomicPtr, AtomicUsize, Ordering};
#[cfg(bytes_no_atomic_cas)]
pub(crate) use core::sync::atomic::{fence, Ordering};
#[cfg(bytes_no_atomic_cas)]
pub(crate) use portable_atomic::{AtomicUsize, AtomicPtr}; |
@marius-meissner
I was hesitant to use this with bytes because of tokio's strict dependency policy and the fact that there were few users at the time, but now that crates like @carllerche @Darksonn: Any objection to adding an optional dependency (portable-atomic) to support these targets? I'm the (only) maintainer of that crate and can add others from the tokio core team as backup maintainers if needed. Also, since it is an optional dependency for no-std users, it is unlikely that it will actually appear in tokio's dependency tree. |
I think it would be fine to add it as an optional dependency. Maybe call it something like |
Are there any updates in regard to support arm-thumb-v6m targets, or rather targets that not support atomic CAS? I would love to use prost and with this bytes on a Raspberry Pi Pico (Cortex-M0+). Would adding portable-atomic as an optional dependency be an option? I currently needed to create a fork and add it to get prost and bytes working on the Pi Pico. Thanks for any insights. |
We have a few different atomic operations. There are increments and decrements for the refcount, and there is a CAS in the promotable representation. If it's only the CAS that is problematic, maybe we could apply #739 on platforms that don't support CAS? |
We have a few different atomic operations. There are increments and decrements for the refcount, and there is a CAS in the promotable representation. If it's only the CAS that is problematic, maybe we could apply #739 on platforms that don't support CAS? |
Also with #739 applied, there are still errors when compiling for arm-thumb-v6m targets
|
Okay so even atomic addition and subtraction are missing. |
Sorry for the late reply, somehow missed yours. Yes, I think most of the atomic operations are missing or rather all the ones with
as they are all generated by the same macro |
You can reproduce by cloning cortex-m-quickstart and setting target accordingly in .cargo/config
The text was updated successfully, but these errors were encountered: