Stream: general

Topic: ✔ Improving cargo-wasi's use of wasm-opt on Apple Silicon


view this post on Zulip Jeff Charles (Jun 24 2022 at 15:46):

:wave: @Alex Crichton I'm interested in making a code contribution to cargo-wasi to address wasm-opt not working out-of-the-box on Apple Silicon. We've had a few devs on Apple silicon express some frustration with the current workflow of downloading wasm-opt separately and needing to use the WASM_OPT environment variable. I can see a couple approaches that could address the issue:

  1. Use binaryen's Rust bindings to run the appropriate optimization passes. We use this approach in Javy. This enables running the optimization passes on any platform that cargo-wasi supports and avoids needing to handle missing dylibs when downloading the wasm-opt binary.
  2. Adjust how wasm-opt is downloaded such that the missing dylib is available on the path that wasm-opt is expecting it on, download a newer version of wasm-opt, and then adjust the logic that checks if wasm-opt can be downloaded to include Apple silicon. This would be split into separate PRs.

I'd prefer (1) but am open to (2). I'm also open to other suggestions!

A lightweight Cargo subcommand to build Rust code for the `wasm32-wasi` target - GitHub - bytecodealliance/cargo-wasi: A lightweight Cargo subcommand to build Rust code for the `wasm32-wasi` target
JS to WebAssembly toolchain. Contribute to Shopify/javy development by creating an account on GitHub.

view this post on Zulip Alex Crichton (Jun 24 2022 at 17:43):

Hello! Personally I'd prefer to stick to using the CLI if possible, it's pretty hairy linking with C++ code and distributing that so stick to precompiled artifacts from elsewhere is my preerred route.

view this post on Zulip Jeff Charles (Jun 24 2022 at 17:59):

To clarify for approach (1), we'd be using the binaryen crate which handles the linking rather than implementing the linking in cargo-wasi itself. That crate has the same license as cargo-wasi. We've been using it in Javy to run wasm-opt optimizations and have not noticed any pain or hairiness around linking or distribution. You can see how we interact with it in the code section I linked.

view this post on Zulip Alex Crichton (Jun 24 2022 at 18:07):

I've historically used the binaryen crate actually but I would still prefer to use precompiled binaries from binaryen itself. Shipping C++ is nontrivial all the complexity still has to go somewhere even if it's all encapsulated in a different crate (and I'm not sure if that crate encapsulates everything)

view this post on Zulip Jeff Charles (Jun 24 2022 at 18:23):

Alright, I'll get started on approach (2). Thank you for providing your feedback on the approaches :smile:! Thinking more about this, I'll probably start by opening a dedicated PR to have cargo-wasi download a newer version of wasm-opt that includes a release with Apple silicon support, and then do the other work for approach (2) separately, as I'm working on a computer with a Apple silicon processor.

view this post on Zulip Alex Crichton (Jun 24 2022 at 18:31):

sounds good!

view this post on Zulip Notification Bot (Jun 24 2022 at 18:32):

Jeff Charles has marked this topic as resolved.


Last updated: Nov 22 2024 at 17:03 UTC