Skip to content

Only add implementation for Arc if the target supports it#70

Merged
finnbear merged 4 commits intoSoftbearStudios:mainfrom
nn1ks:fix-arc-impl
Mar 25, 2025
Merged

Only add implementation for Arc if the target supports it#70
finnbear merged 4 commits intoSoftbearStudios:mainfrom
nn1ks:fix-arc-impl

Conversation

@nn1ks
Copy link
Copy Markdown
Contributor

@nn1ks nn1ks commented Mar 24, 2025

Currently the Encode and Decode traits are always implemented for alloc::sync::Arc regardless of whether the Arc type is actually available. When compiling to a target that does not have atomic pointers (e.g. thumbv6m-none-eabi) the compiler emits the following error message:

error[E0433]: failed to resolve: could not find `sync` in `alloc`
   --> src/derive/impls.rs:112:26
    |
112 | impl_smart_ptr!(::alloc::sync::Arc);
    |                          ^^^^ could not find `sync` in `alloc`
    |
note: found an item that was configured out
   --> /nix/store/awlsysagj2w76yjz13w9sqfh5ws4zv73-rust-nightly/lib/rustlib/src/rust/library/alloc/src/lib.rs:228:9
    |
228 | pub mod sync;
    |         ^^^^
note: the item is gated here
   --> /nix/store/awlsysagj2w76yjz13w9sqfh5ws4zv73-rust-nightly/lib/rustlib/src/rust/library/alloc/src/lib.rs:227:1
    |
227 | #[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0433`.
error: could not compile `bitcode` (lib) due to 1 previous error

With this change the traits are only implemented if the Arc type exists.

@finnbear
Copy link
Copy Markdown
Member

finnbear commented Mar 24, 2025

Thanks very much! Is it possible to add a CI step that checks compilation on that target? I'd like to avoid breaking this in the future.

@nn1ks
Copy link
Copy Markdown
Contributor Author

nn1ks commented Mar 24, 2025

I tried to add it but it seems like zstd doesn't work on that target. Should I handle this specific target similiar to miri and add it to the cfg here:

bitcode/Cargo.toml

Lines 35 to 37 in 1604d52

# zstd doesn't compile with miri big-endian.
[target.'cfg(not(miri))'.dev-dependencies]
zstd = "0.13.0"

Or what do you think is the best solution?

@nn1ks
Copy link
Copy Markdown
Contributor Author

nn1ks commented Mar 24, 2025

I had a better idea now: Just run cargo check instead of cargo test since it's a compile error so check is sufficient here :)

@finnbear finnbear merged commit ee2bd76 into SoftbearStudios:main Mar 25, 2025
3 checks passed
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.

2 participants