Erlang and Elixir on Apple Silicon/M1 Chip

Also another update from me then :slight_smile:

Most intellij products are updated to M1 versions days ago, so now you can also use their intellij + elixir plugin native on the M1 machines. They came up in the intellij toolbox under a different name next to the old ones e.g. ‘Intellij IDEA Ultimate for Apple Silicon’.

VSCode(+elixirLS) was already working native if you use the ‘exploration’ / insiders build (see https://code.visualstudio.com/insiders/ small download link for ARM64).

4 Likes

I spoke too soon. It would appear that comeonin will compile with an older intel version of elixir (1.10.4-otp-23 in my case) Erlang (23.0.3 in my case), but fails on bcrypt when compiling on the latest elixir 1.11.2-otp-23 Erlang 23.2.1 for apple silicon.

Continuing investigation.

My particular issue was a VSCode architecture mismatch.

Posting the solution here in case anyone else experiences this side effect like I did.

2 Likes

Just wanna say this tutotial is awesome.

1 Like

Very smooth fully native M1 Arm installation now via latest Homebrew and asdf-vm; be sure to install the Erlang dependencies autoconf and wxmac before installing Erlang, as specified in the asdf-erlang instructions.

Of note: the scheduler sees all 8 cores, including the low-power ones:

Erlang/OTP 23 [erts-11.1.7] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]

so it might be interesting to learn how that performs in practice.

6 Likes

Not sure if anyone’s seen this yet, but I’ve installed elixir 1.9 and erlang/otp 23 and almost all elixir compilation errors are swallowed and only a single stack-less “argument error” is spat out, ie:

== Compilation error in file test/support/factory.ex ==
** (ArgumentError) argument error

Even when I compile on the same machine in docker, the compilation errors are reported correctly, so it might actually be a Big Sur issue, but I have no idea as to the root cause.

Hopefully this is of use/interest to someone.

How I got Elixir/Phoenix working on an Apple M1

[MacBook Pro (M1 2020), chip Apple M1, MacOS Big Sur 11.3.1]

I installed the latest Elixir/OTP with Homebrew

$ brew install elixir

but found that my Phoenix projects wouldn’t run.

Eg. GitHub - pdxrod/article_editor
failed with

** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started

So I tried starting with a simpler project,

This had a different issue, to do with Mongo and its Elixir driver

{:mongodb, "~> 0.5.1"}

https://hexdocs.pm/mongodb/readme.html

The latest Elixir downloaded by Homebrew was 1.12.1, with Erlang/OTP 24. My project was created using Elixir 1.11.2, with Erlang/OTP 23.

The MongoDb driver 0.5.1 uses crypto.hmac/2, and OTP 24 wants crypto.hmac/3, so the project wouldn’t compile and run.

** (UndefinedFunctionError) function :crypto.hmac/3 is undefined or private

Attempts to upgrade plug_crypto, as recommended here, made no difference.

I couldn’t figure out how to downgrade Elixir and Erlang using Homebrew, asdf, kiex, kurl or exenv. So I deleted all copies of both, and switched to using Macports.

sudo port install erlang @23.1
sudo port install elixir @1.11.2

mix deps.get
mix phx.server

Bingo!

This tells you how to install a given version of something with Macports

I installed Macports by finding MacPorts-2.7.1-11-BigSur.pkg here
Release MacPorts 2.7.1 · macports/macports-base · GitHub downloading and double-clicking on it.

Downgrading to Elixir 1.11 isn’t a permanent solution, so I’m going to look into other Mongo drivers, so see if any of them work with 1.12.

1 Like

The crypto error can be easily addressed too, in case you want to submit a pull request. Here is how it was handled in plug_crypto: Use crypto new API (#20) · elixir-plug/plug_crypto@cf901bd · GitHub

2 Likes

For anyone wanting to run Elixir 1.11 and OTP 23 this guide worked well for me on an M1 Max in Monterey.

I made sure to install the latest homebrew, then asdf and plugins. Its key to do this from native terminal and NOT a rosetta terminal.

1 Like

Could you please clarify, is Elixir and Erlang runs natively on M1? So no rosetta involved? And it means that it uses full CPU potential?
Thanks!

It does, I’ve set up Erlang 24.1.3 and Elixir .1.12.3 on both the MacBook pro 13inch M1 and the 14inch M1Max with no issues using asdf-vm

1 Like

Depends on what you mean by “full potential”. BEAM do not support JIT on ARM64, so better performance of the CPU can be eaten by interpreting BEAM code instead of JITing.

1 Like

it does on master and it is glorious. :smile:

11 Likes

I need to get my hands on M1 later and test that out.

1 Like

When??

I just got my M1 MBP today and was slightly disappointed at the Elixir compile times (which is the main language I work with).

On the other hand… holy crap, a small Rust project went from 45s to 10s… :flushed:

To get that kind of decrease in Elixir compile times… would be like heaven!

OTP 25 is still 6+ months out, but you can use the JIT right now if you build it with kerl. Runs great!

2 Likes

Hello! I tried installing Erlang/OTP with kerl and Elixir with kiex and didn’t notice any difference. How can I tell it’s working? I just installed 24.1.4 though… should I be giving kerl a Github url and branch?

Thanks for the help!

Yes, the instruction I linked is for using a branch. Use master from the official OTP repo.

1 Like

Heh, well using master works, I can see the [jit] tag when starting up repl. Unfortunately, one of my projects compiled fine, but another crashes during compilation. So back to 24.1.4 for now.

Yeah I’m seeing similarly disappointing times on my new M1 (max) mac pro. For whatever reason I only really see the two efficiency cores doing work while compiling, there is next to 0 activity on the performance cores, and I can’t really figure out why. iex shows [smp:10:10] [ds:10:10:10] so it should have enough schedulers.

I mean, I’m getting roughly the same compile time as my previous MBP (intel) w/ 8 Intel cores so it’s still impressive, but I’d really like to get the 8 performance M1 cores in the mix.