1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Note] Compile Rust to WebAssembly on Mac

Posted at

Install necessary modules from Homebrew

  • cmake
  • emscripten
$brew install cmake emscripten

After installing emscripten, you can see text like following on console.

Manually set LLVM_ROOT to
  /usr/local/opt/emscripten/libexec/llvm/bin
  and comment out BINARYEN_ROOT
  in ~/.emscripten after running `emcc` for the first time.

Modified ~/.emscripten

I modified my ~/.emscripten like this after calling emcc once.

# this helps projects using emscripten find it
EMSCRIPTEN_ROOT = os.path.expanduser(os.getenv('EMSCRIPTEN', '/usr/local/Cellar/emscripten/1.37.27/libexec')) # directory
#LLVM_ROOT = os.path.expanduser(os.getenv('LLVM', '/usr/bin')) # directory
LLVM_ROOT = os.path.expanduser(os.getenv('LLVM', '/usr/local/opt/emscripten/libexec/llvm/bin')) # directory

# Manually set LLVM_ROOT to
#   /usr/local/opt/emscripten/libexec/llvm/bin
#   and comment out BINARYEN_ROOT
#   in ~/.emscripten after running `emcc` for the first time.
#
# BINARYEN_ROOT = os.path.expanduser(os.getenv('BINARYEN', '')) # if not set, we will use it from ports

# If not specified, defaults to sys.executable.

Compile

In root directory of your project, run following.

# compile a specific file.
rustc --target=wasm32-unknown-emscripten src/main.rs -o dist/main.js

# build you project into wasm
cargo build --target=wasm32-unknown-emscripten
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?