On Mac, I sometimes run a prebuilt binary and sometimes compile my own. For Apple M1 (ARM) I started by using the x86 binaries from emacsformacosx.com but I wanted to try compiling a native ARM version too. I saw that the work branch of Mitsuharu Yamamoto's Mac port has M1 patches applied, so I decided to try it.

Screenshot of Emacs 27 compiled on Apple ARM M1

Make sure /opt/homebrew/bin (ARM homebrew) is earlier in your path than /usr/local/bin (Intel homebrew).

brew install coreutils pkg-config libxml2 jansson gnutls autoconf gnu-sed
git clone --depth 1 --single-branch --branch work \
cd emacs-mac

and then build:

make clean
find . -name \*.elc -exec rm '{}' ';'

./configure \
     --with-mac-metal --with-xml2 --without-imagemagick --with-json \
     --with-modules --without-makeinfo \
     --prefix=$EMACSAPP/Emacs.app/Contents/MacOS \
     --enable-mac-app=$EMACSAPP --enable-mac-self-contained
make -j3
mac/Emacs.app/Contents/MacOS/Emacs -q # test it
make install

You should see it bring up a window with:

This is GNU Emacs 27.1 (build 1, aarch64-apple-darwin20.1.0, Carbon Version 164 AppKit 2022.1)
 of 2020-11-30
Copyright (C) 2020 Free Software Foundation, Inc.


As various packages were made available in Homebrew, the situation improved.

  • [2020-11-30] Other parts of homebrew weren't complete enough for me to compile modules like vterm, so I temporarily switched back to emacsformacosx.com emacs
  • [2020-12-01] The emacsformacosx.com version flickrs a lot when using Rust + LSP + posframe, due to this issue, so I switched back to the Mac Port, but compiled for x86.
  • [2020-12-03] I had some issues with *.elc files from previous compiles not being recompiled so I ended up deleting all the *.elc files in the emacs build folder, and that resolved the problem.
  • [2020-12-05] I also had to recompile all the *.elc files in elpa modules, with (byte-recompile-directory "~/.emacs.d/elpa" 0 t).
  • [2020-12-07] I switched back to the ARM version, which works now. It seems faster but I don't know a good way to measure.
  • [2020-12-13] Modules like vterm seem to work now.
  • [2021-01-07] I learned that Homebrew emacs, emacs-plus, and railwaycat emacs now work on arm. I'm happy with the version I compiled, but these would be the first things to try if you don't want to compile your own.

Labels: , ,


Anonymous wrote at Tuesday, December 1, 2020 at 6:13:00 AM PST

How long did it take to compile and install?

Did it feel any faster than the Intel version?

Could you run any comparative benchmark?

Amit wrote at Tuesday, December 1, 2020 at 1:31:00 PM PST

It took around 30 seconds to compile (!) but didn't feel faster than the Intel version, and I'm back on the Intel emulation version. Everything else I'm running right now (like homebrew and rust) are Intel emulation so it was easier to stick to that for now.

Amit wrote at Wednesday, December 9, 2020 at 4:04:00 AM PST

@Anonymous: I ran

(benchmark-run-compiled 100 (cl-loop for i below (* 1000 1000) sum i))

Intel version from emacsformacosx.com: 2.54s
Intel version compiled myself: 2.70s
ARM version compiled myself: 1.73s

Anonymous wrote at Tuesday, January 19, 2021 at 5:49:00 PM PST

Hello, thank you for taking the time to write this blog.

I followed the same steps as you but appear to be getting an error at the `make -j3` stage.

I haven't been able to find much info about this error, any idea how to get around it?

CCLD temacs
/opt/homebrew/bin/gmkdir -p ../etc
/Library/Developer/CommandLineTools/usr/bin/make -C ../lisp update-subdirs
cp -f temacs bootstrap-emacs
rm -f bootstrap-emacs.pdmp
./temacs --batch -l loadup --temacs=pbootstrap
make[1]: *** [bootstrap-emacs.pdmp] Killed: 9
make: *** [src] Error 2
make -j3 59.16s user 4.50s system 270% cpu 23.539 total```

For further info, I'm running this on an M1 MacBook Air that arrived today, I'm gonna try updating the OS and re-running.

Anonymous wrote at Tuesday, January 19, 2021 at 6:05:00 PM PST

Never mind, I retraced my steps and spotted a mistake (cloned the repo myself earlier, then came across the tutorial - I didn't clone the same branch as you). It works now! Thanks again for sharing your steps on this blog.

Amit wrote at Monday, January 25, 2021 at 2:36:00 PM PST

Anonymous: glad you got it working! I think the main branch doesn't have the ARM patches yet.

HACnyc wrote at Sunday, April 18, 2021 at 7:25:00 PM PDT

I'm having the same problem with ./temacs getting killed. I looked at the crash report and it's due to a code sign invalid error. When I run that failing command inside "lldb" it actually runs fine, then typing make I get the same killed 9 for the next thing it tries to run `EMACSLOADPATH= '../src/bootstrap-emacs' -batch --no-site-file --no-site-lisp --eval '(setq load-prefer-newer t)' -f batch-byte-compile international/titdic-cnv.el`

I wonder how I can convince the system to not keep killing these processes, and why they aren't "signed" correctly (just building a test program with `gcc -o foo foo.c` runs fine.

HACnyc wrote at Sunday, April 18, 2021 at 7:44:00 PM PDT

Found the issue. The code was not being signed b/c:

Configured for 'aarch64-apple-darwin20.3.0'.

and in one of the Makefiles it was expecting that to start with 'arm-apple-darwin' to enable 'codesign -s - ..'

I changed the makefile, and got past the issue.