On Mac, I sometimes run a prebuilt binary and sometimes compile my own. For Apple M1 (ARM) I am 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 already has 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).

EMACSAPP=/tmp/Applications
brew install coreutils pkg-config libxml2 jansson gnutls autoconf gnu-sed
git clone --depth 1 --single-branch --branch work \
    https://bitbucket.org/mituharu/emacs-mac.git
cd emacs-mac
./autogen.sh

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.

Updates

  • [2020-11-30] I've gone back to the emacsformacosx.com version for now because I've run into various issues, including modules (like vterm) not working.
  • [2020-12-01] The emacsformacosx.com version flickrs a lot when using Rust + LSP + posframe, due to this issue, so I'm now using the Mitsuharu version 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] Even though I removed the *.elc files from built-in modules, I had weird issues with the elpa modules, so I forced recompilation of everything with (byte-recompile-directory "~/.emacs.d/elpa" 0 t).
  • [2020-12-07] I was able to switch back to the ARM version. Recompiling elc resolved the issues I had previously, except I still am not using modules. The ARM version seems faster but I don't know a good way to measure.
  • [2020-12-13] When compiling the vterm module, Emacs crashed in dlopen, but it seemed to work when I started Emacs again. So modules … seem to work?
  • [2021-01-07] I learned that Homebrew emacs works on arm, and Homebrew emacs-plus also works on arm. I haven't tried either because I'm happy with the version I compiled. But I think these would be the first things to try if you don't want to compile your own.

Labels: , ,

3 comments:

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