Compiling Emacs 29 With Tree-Sitter

I started a new job recently and took the opportunity to install a new version of Emacs. Emacs 29 includes tree-sitter and built-in eglot support, which I’ll write about some other time. In this post, I just want to document how I compiled Emacs on an M2 macos device.

First I cloned the Emacs repo to my machine and checked out the desired branch:

$ git clone git://git.savannah.gnu.org/emacs.git
$ git checkout emacs-29

Next I installed some prereqs using homebrew:

$ brew install gnutls gcc libgccjit texinfo tree-sitter jansson \
   librsvg imagemagick jpeg giflib libpng libtiff

The first four of these were needed to get Emacs to compile at all. You need to install tree-sitter first, if you want to compile Emacs with tree-sitter support. You need jansson if you want to compile Emacs with native json support, which apparently is essential if you want fast language-server support. I’m not sure how necessary the image stuff is, but I included them.

Next I built Emacs. I had to specify the compiler to make sure to use the right version:

$ CC=gcc-12 ./autogen.sh
$ CPPFLAGS="-I/opt/homebrew/opt/jpeg/include" \
    LDFLAGS="-L/opt/homebrew/opt/jpeg/lib" \
    ./configure --with-native-compilation=aot --with-tree-sitter \
    --with-gif --with-png --with-jpeg --with-rsvg --with-tiff \
    --with-imagemagick --with-x-toolkit=gtk3 --with-xwidgets
$ make

I built with ahead-of-time native compilation, which took about an hour.

You can test things out with:

$ src/emacs -Q

which will open up the new Emacs. Next make sure there is no existing Emacs.app in your Applications folder, then:

$ make install
$ mv nextstep/Emacs.app /Applications

That’s it!

Subscribe to Adventures in Why

* indicates required
Bob Wilson
Bob Wilson
Data Scientist

The views expressed on this blog are Bob’s alone and do not necessarily reflect the positions of current or previous employers.

Related