Apple Silicon Development Set up for Rust

Chris O'Brian
4 min readNov 26, 2020

Apple Silicon is now generally available and many are wondering what the development experience is like on the new processor with languages such as Rust. In this article I’ll go over all the steps involved in getting a working development environment for Rust on the Mac mini M1 using Visual Studio Code Exploration as the IDE.

Pre-Requisites:

  • Git is installed
  • A device running on Apple Silicon

Table of Contents

  • Downloading and setting up Rust
  • Creating aliases for building, running, and installing
  • Installing Visual Studio Code Exploration
  • Installing the Rust and Rust Analyzer plugin
  • Configuring the Rust Analyzer plugin

Downloading and Setting up Rust

Rust has a vibrant and wonderful community, and they have had a tracking issue for compatibility with Apple Silicon since the end of June 2020. The progress toward this goal is nothing short of amazing. So let’s get started!

First thing first! Let’s go ahead and download rust using the instructions from shepmaster. Since we are on an Apple Silicon device you’ll need to install rustup and the native toolchain for apple’s new architecture.

arch --x86_64 \
sh <(curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs) \
--default-host aarch64-apple-darwin \
--default-toolchain nightly

Creating aliases for building, running, and installing using Cargo

While the instructions say that you should be able to run cargo build, I found that I could only build basic projects and suffered from the code signing problem that is listed as the first porting note.

The suggestion of setting the RUSTCenvironment variable for building, installing and running worked to build 90% of other projects, so I created aliases for them. You can choose whatever alias you’d like, I just kept it very short. You’ll put these aliases in ~/.bash_profile. If you’re using macOS Catalina or greater you’ll want to place them in the ~/.zshrc.

alias cb="RUSTC=$(rustup which rustc) $(rustup which cargo) build"
alias ci="RUSTC=$(rustup which rustc) $(rustup which cargo) install"
alias cr="RUSTC=$(rustup which rustc) $(rustup which cargo) run”

Installing Visual Studio Code Exploration

Now that we have Rust installed, let’s get our IDE setup. I chose to use Visual Studio Code Exploration for this as the setup seemed to be pretty straightforward.

Visual Studio Code Insiders is pretty much equivalent to a nightly build and has a native version for Apple Silicon. Some updates may be broken, but it will get us started since there isn’t a stable version of Visual Studio Code for Apple Silicon yet.

Go to the Visual Studio Code Insiderspage on your Apple Silicon device and click on the small blue box that is labeled ARM64 Experimental located underneath the larger blue box labeled Download for Mac. Go through the normal installation process.

Installing the Rust and Rust Analyzer plugins

Excellent! We have our IDE installed. The next step is to configure it for Rust development. We’ll get started by opening up Visual Studio Code Exploration.

When the application opens:

  • Press command-shift-p to open the command palette.
  • Choose Extensions: Install extensionsfrom the menu.
  • In the search bar, search for rust.
  • Install the Rust Extension Packand the rust-analyzerplugins from the marketplace.

If you have an existing rust project and open it in Visual Studio

Code Exploration you’ll get code completion but you’ll see errors with the Rust Analyzer plugin stating that there is no native binary for your architecture and therefore you won’t see errors or warnings in your code. Let’s fix that!

Configuring the Rust Analyzer plugin

On to the fun part! Since there is no pre-compiled binary for the Apple Silicon Architecture, we’ll need to build our own. Having everything from the previous steps working correctly there should be no problem building the binary from the source. Let’s get the binary ready.

  • Clone the Rust Analyzer repository.
  • cd into the project directory
  • Use the cargo build alias that you set up earlier to build the binary using the --release option.
  • You should now have a release version of the binary in the target/release directory of the Rust Analyzer project.

Now that we have a binary compiled for the Apple Silicon Architecture we can configure Visual Studio Code Explorer’s Rust Analyzer plugin to use it.

  • Open the command pallet using command-shift-p.
  • Type settings and select the Preferences: Open Settings (UI).
  • In the search bar for settings type Rust-analyzer: Server Path.
  • Select Edit in settings.json under the Rust> Rust-analyzer: Server Path option.
  • Enter the path to the rust analyzer binary that you just built.
  • Save the configuration.
  • Close and reopen Visual Studio Code Exploration.

Conclusion

That’s it! Now when we create or open a new project in Visual Studio Code Exploration the Rust Analyzer plugin will no longer error out on startup, and we should have code completion and get feedback from Rust Analyzer.

Happy Coding!

Links:

Rust Analyzer

Rust Support for macOS on Apple Silicon

Visual Studio Code Insiders

--

--