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

std compilation error when compiling for wasm32-wasi with -C target-feature=+atomics,+bulk-memory #109727

Closed
tomaka opened this issue Mar 29, 2023 · 0 comments · Fixed by #110587
Labels
C-bug Category: This is a bug. O-wasm Target: WASM (WebAssembly), http://webassembly.org/ T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@tomaka
Copy link
Contributor

tomaka commented Mar 29, 2023

In order to reproduce:

cargo new hello-world
cd hello-world
RUSTFLAGS="-C target-features=+atomics,+bulk-memory" cargo +nightly build -Z build-std=std --target=wasm32-wasi

This leads to:

   Compiling std v0.0.0 (/home/tomaka/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std)
error[E0308]: mismatched types
  --> /home/tomaka/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/wasi/../unsupported/once.rs:63:28
   |
63 |                       inner: OnceState {
   |  ____________________________^
64 | |                         poisoned: state == State::Poisoned,
65 | |                         set_state_to: Cell::new(State::Complete),
66 | |                     },
   | |_____________________^ expected `OnceState`, found a different `OnceState`
   |
   = note: `OnceState` and `OnceState` have similar names, but are actually distinct types
note: `OnceState` is defined in module `crate::sys::wasi::once` of the current crate
  --> /home/tomaka/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/wasi/../unsupported/once.rs:8:1
   |
8  | pub struct OnceState {
   | ^^^^^^^^^^^^^^^^^^^^
note: `OnceState` is defined in module `crate::sys_common::once::futex` of the current crate
  --> /home/tomaka/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys_common/once/futex.rs:31:1
   |
31 | pub struct OnceState {
   | ^^^^^^^^^^^^^^^^^^^^

error[E0616]: field `set_state_to` of struct `sys_common::once::futex::OnceState` is private
  --> /home/tomaka/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/wasi/../unsupported/once.rs:69:60
   |
69 | ...p_to = f_state.inner.set_state_to.get();
   |                         ^^^^^^^^^^^^ private field

Some errors have detailed explanations: E0308, E0616.
For more information about an error, try `rustc --explain E0308`.
error: could not compile `std` due to 2 previous errors

This happens with both nightly-2023-03-28 and nightly-2023-02-08.

@tomaka tomaka added the C-bug Category: This is a bug. label Mar 29, 2023
@jyn514 jyn514 added O-wasm Target: WASM (WebAssembly), http://webassembly.org/ T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 29, 2023
@bors bors closed this as completed in 3fbaf78 Apr 26, 2023
thomcc pushed a commit to tcdi/postgrestd that referenced this issue Jul 18, 2023
Fix `std` compilation error for wasi+atomics

Fix rust-lang/rust#109727

It seems that the `unsupported/once.rs` module isn't meant to exist at the same time as the `futex` module, as they have conflicting definitions.

I've solved this by defining the `once` module only if `not(target_feature = "atomics")`.
The `wasm32-unknown-unknown` target [similarly only defines the `once` module if `not(target_feature = "atomics")`](https://github.com/tomaka/rust/blob/01c4f319276da912dd2be768ae0ce9857ad6bb63/library/std/src/sys/wasm/mod.rs#L69-L70).

As show in [this block of code](https://github.com/tomaka/rust/blob/01c4f319276da912dd2be768ae0ce9857ad6bb63/library/std/src/sys_common/once/mod.rs#L10-L34), the `sys::once` module doesn't need to exist if `all(target_arch = "wasm32", target_feature = "atomics")`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. O-wasm Target: WASM (WebAssembly), http://webassembly.org/ T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants