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

wasm-pack + serde + AtomicUsize #1778

Closed
gakonst opened this issue Apr 15, 2020 · 4 comments
Closed

wasm-pack + serde + AtomicUsize #1778

gakonst opened this issue Apr 15, 2020 · 4 comments

Comments

@gakonst
Copy link

gakonst commented Apr 15, 2020

Serialize is not implemented for AtomicUsize in wasm when using wasm-pack.

Example:

  1. Install wasm-pack: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

  2. Add to your Cargo.toml:

[lib]
crate-type = ["cdylib", "lib"]

[dependencies]
serde = { version = "1.0.106", features = ["derive"] }
wasm-bindgen = "0.2.60"
  1. Code:
use std::sync::atomic::AtomicUsize;
use serde::Serialize;

#[derive(Serialize)]
pub struct S(AtomicUsize);
  1. Run wasm-pack build (wasm-pack builds into wasm32-unknown-unknown)

It errors with:

pub struct S(AtomicUsize);
  |              ^^^^^^^^^^^ the trait `_IMPL_SERIALIZE_FOR_S::_serde::Serialize` is not implemented for `std::sync::atomic::AtomicUsize

Could anybody explain to me why/if it is not fundamentally impossible to implement this?

@dtolnay
Copy link
Member

dtolnay commented Apr 15, 2020

This looks like a consequence of #1581. Determining exactly which targets can handle which atomic operations is complicated so we've only started with a conservative set and would need to expand as use cases come up.

@gakonst
Copy link
Author

gakonst commented Apr 16, 2020

@dtolnay thank you for the quick response, your approach makes sense. It seems like wasm32-unknown-unknown has support for Atomics since rust-lang/rust#54017?

@dtolnay
Copy link
Member

dtolnay commented Apr 19, 2020

Sounds good; someone should send a PR to enable the atomic impls on wasm32-unknown-unknown on the correct range of compiler versions.

@dtolnay
Copy link
Member

dtolnay commented Jul 9, 2023

Fixed in serde 1.0.150 by #2337.

@dtolnay dtolnay closed this as completed Jul 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants