Components built on apple silicon don't run in browser

未关闭
#398 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
rust, wasm

调研方向

从链接的最小转译环境开始,使用 cargo-component v0.21.0 在 Apple silicon 上复现浏览器故障。比较损坏的和正常工作的 Build 工件,并查看原始 jco issue 和 Zulip discussion,了解已经确立的调查方向。完成的标准是识别并修复架构特定的 Build 问题,使生成的组件能够在浏览器中运行。

由索引模型根据 Issue 内容生成。

描述

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: https://github.com/bytecodealliance/jco/issues/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:

  1. 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)
  1. 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/[email protected][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/[email protected]	@	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/[email protected] (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)

Build artifacts

build-artifacts.broken.zip
build-artifacts.working.zip

主要语言
Rust
星标
593
派生
68
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

bytecodealliance/cargo-component 的其他 Issue

查看 bytecodealliance/cargo-component 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。