M1 Macs, Rust & WASM
17.04.2024 13:35
Getting setup for compiling Rust to WASM and serving w/ Trunk on M1 Mac.
-
Install
wasm32-unknown-unknown
target withrustup
$ rustup target add wasm32-unknown-unknown
-
Install
wasm-bindgen-cli
$ cargo install --locked wasm-bindgen-cli
-
Test compiling a project w/ the new wasm target
$ cargo build --target wasm32-unknown-unknown
If this fails due to No available targets are compatible with triple “wasm32-unknown-unknown” #103, install an updated version of
clang
via Homebrew.Original version:
$ clang --version Apple clang version 15.0.0 (clang-1500.3.9.4) Target: arm64-apple-darwin23.1.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Update via Homebrew
$ brew install llvm
Use newer version from Brew
export PATH="/opt/homebrew/opt/llvm/bin:$PATH" export CC=/opt/homebrew/opt/llvm/bin/clang export AR=/opt/homebrew/opt/llvm/bin/llvm-ar
Updated version:
$ clang --version Homebrew clang version 17.0.6 Target: arm64-apple-darwin23.1.0 Thread model: posix InstalledDir: /opt/homebrew/opt/llvm/bin
References
No available targets are compatible with triple “wasm32-unknown-unknown” #103
Unrelated project installation w/ notes on LLVM/Clang install