Chain Compilation on M1 Chip
This page is about issues we encountered when trying to build the chain.
Unfortunately, having issues with compiling substrate chains on computers with an Apple Silicon chip is quite common. When trying to
cargo buildyour chain, you might encounter errors mentioning
wasmtime-runtime. This is because the built-in clang compiler on macOS does not really support wasm compilation.
In the following, we describe one way to make it work on a Mac running an M1 chip. The first set of steps is trying to make it work with the 'normal' binaries. If these do not fix the issue, we fall back to the intel binaries.
brew install llvm
cargo install wasm-pack
- 4.Set environment variables to point to the llvm installation of brew.
export CC=/opt/homebrew/opt/llvm/bin/clangConsider adding these to your shell environment (e.g.
~/.zshrc) so that they are also set when rebooting your computer.
- 5.Check if the compilation now works. If it still does not, reboot your computer and try again. Don't forget to
cargo cleanbefore trying to recompile.
If you still have the same issue after following the instructions for installing the proper silicon binaries, try the following steps to install brew and llvm with the intel binaries instead. To do this, we install a second version of
brewthat is configured for intel binaries. The steps are taken from this guide.
# Download the brew tarball
curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
# Move it to another location
sudo mv homebrew /usr/local/homebrew
# Export path in zshrc
echo "export PATH=$HOME/bin:/usr/local/bin:$PATH" >> ~/.zshrc
echo "alias axbrew='arch -x86_64 /usr/local/homebrew/bin/brew'" >> ~/.zshrc
You can now install packages with
axbrew install package-name. So to install llvm and cmake, use
axbrew install llvm cmake
You now need to set different environment variables. Use:
and now retry the compilation with
cargo build. If this fixed the errors, consider adding the env variables to your shell environment with:
echo "export AR=/usr/local/homebrew/opt/llvm/bin/llvm-ar" >> ~/.zshrc
echo "export CC=/usr/local/homebrew/opt/llvm/bin/clang" >> ~/.zshrc