-
Notifications
You must be signed in to change notification settings - Fork 67
Description
Impact
It seems this error means that anyone running Apple silicon (M1+ laptops) is currently unable to build/transpile a wasm component and run it in the browser.
Brief
v0.21.0 introduces issues building on M1, M2 Macbook Pros and results in errors calling into a WASM component in the browser. The expression of the error can be found below.
Rewrote this issue to account for all we learned up to this point...
Original jco issue: bytecodealliance/jco#634
Original zulip discussion: https://bytecodealliance.zulipchat.com/#narrow/channel/409526-jco/topic/Sudden.20transpiled.20wasm.20component.20error.20in.20browser/with/514479119
Minimal env that reproduces the problem (for MBPs it seems):
https://github.com/James-Mart/minimal-transpile
We tracked the problem down to cargo-component v0.21.0. On my M1, I can solve the problem 2 ways
- downgrade to cargo-component v0.20.0 and recompile OR
- get the compiled WASM from someone else's computer who was able to build it on a system that doesn't see this error.
Observations
- The is a build-time problem. Results follow build products when swapped between machines, i.e., errors aren't environment-tied; they are build product related.
- Apple Macbook Pros see the problem (M1, M2) aarch64; Lnux doesn't (Windows linux subsystem) amd64
- This problem does not appear/disappear based on Rust version (I tried all rust versions that supported Rust ed. 2024 / WASM preview1).
- wit-bindgen-rt version didn't have an impact
What's it look like?
In the referenced minimal env linked above, with cargo-component v0.20.0 (and various Rust versions), I see 2 different errors:
- when the wasm calls println!(), I see the following
> wasm.core.wasm:0x4da7 Uncaught RuntimeError: unreachable
at wasm.wasm.__rust_start_panic (wasm.core.wasm:0x4da7)
at wasm.wasm.rust_panic (wasm.core.wasm:0x4c1e)
at wasm.wasm._ZN3std9panicking20rust_panic_with_hook17h79071f5fb265d1d9E (wasm.core.wasm:0x4bf1)
at wasm.wasm._ZN3std9panicking19begin_panic_handler28_$u7b$$u7b$closure$u7d$$u7d$17h410c57f452410813E (wasm.core.wasm:0x3c9f)
at wasm.wasm._ZN3std3sys9backtrace26__rust_end_short_backtrace17h514500abf2a2d0caE (wasm.core.wasm:0x3c0b)
at wasm.wasm.rust_begin_unwind (wasm.core.wasm:0x4585)
at wasm.wasm._ZN4core9panicking9panic_fmt17he306018bf71f8e67E (wasm.core.wasm:0x9562)
at wasm.wasm._ZN3std2io5stdio6_print17h4ef99727a983bb66E (wasm.core.wasm:0x325e)
at wasm.wasm.hello (wasm.core.wasm:0x2c6)
at Module.Be (wasm.js:1:17452)
- when the wasm calls into rand and returns the result (no call to println!()), I get the following in the browser console
> assertion failed at adapter line
Ie @ wasm.js:1
$indirect-wasi:io/streams@0.2.3-[method]output-stream.blocking-write-and-flush @ wit-component:shim-f1fd1512:0x16a
$_ZN22wasi_snapshot_preview18bindings4wasi2io7streams12OutputStream24blocking_write_and_flush17h4f9b86b3d19bf6d5E @ wasm.core2.wasm:0x1154
$_ZN22wasi_snapshot_preview16macros5print17h319e9b3e6f2e5d09E @ wasm.core2.wasm:0x9ee
$_ZN22wasi_snapshot_preview16macros11assert_fail17h67fe26dc6b70f78bE @ wasm.core2.wasm:0x585
$cabi_import_realloc @ wasm.core2.wasm:0x641
Ee @ wasm.js:1
$indirect-wasi:random/random@0.2.3-get-random-bytes @ wit-component:shim-f1fd1512:0x176
$random_get @ wasm.core2.wasm:0x181a
$adapt-wasi_snapshot_preview1-random_get @ wit-component:shim-f1fd1512:0xb8
$_ZN3std3sys12thread_local6statik20LazyStorage$LT$T$GT$10initialize17h9d56f353d90c9518E @ wasm.core.wasm:0x1b09
$_ZN4rand4rngs6thread3rng17h1309d710195068edE @ wasm.core.wasm:0x1d18
$hello @ wasm.core.wasm:0x1641
Ze @ wasm.js:1
handleClick @ App.tsx:22
> 3 [repeated callstacks skipped]
> 7
> 6
> Uncaught RuntimeError: unreachable
at wit-component:adapter:wasi_snapshot_preview1._ZN22wasi_snapshot_preview16macros11assert_fail17h67fe26dc6b70f78bE (wasm.core2.wasm:0x58b)
at wit-component:adapter:wasi_snapshot_preview1.cabi_import_realloc (wasm.core2.wasm:0x641)
at Ee (wasm.js:1:16790)
at wit-component:shim.indirect-wasi:random/random@0.2.3-get-random-bytes (wit-component:shim-f1fd1512:0x176)
at wit-component:adapter:wasi_snapshot_preview1.random_get (wasm.core2.wasm:0x181a)
at wit-component:shim.adapt-wasi_snapshot_preview1-random_get (wit-component:shim-f1fd1512:0xb8)
at wasm.wasm._ZN3std3sys12thread_local6statik20LazyStorage$LT$T$GT$10initialize17h9d56f353d90c9518E (wasm.core.wasm:0x1b09)
at wasm.wasm._ZN4rand4rngs6thread3rng17h1309d710195068edE (wasm.core.wasm:0x1d18)
at wasm.wasm.hello (wasm.core.wasm:0x1641)
at Module.Ze (wasm.js:1:17825)