index rss mastodon twitter github linkedin email
Álvaro Ramírez

Álvaro Ramírez

16 August 2020 Trying out gccemacs on macOS

UPDATE: I'm no longer using these steps. See Emacs plus –with-native-comp for an easier alternative.

Below are the instructions I use to build Andrea Corallo's gccemacs on macOS. It is based on Allen Dang's handy instructions plus some changes of my own.

Install gcc and libgccjit via homebrew

brew install gcc libgccjit

Save configure script



set -o nounset
set -o errexit

# Configures Emacs for building native comp support

readonly GCC_DIR="$(realpath $(brew --prefix libgccjit))"
[[ -d $GCC_DIR ]] ||  { echo "${GCC_DIR} not found"; exit 1; }

readonly SED_DIR="$(realpath $(brew --prefix gnu-sed))"
[[ -d $SED_DIR ]] ||  { echo "${SED_DIR} not found"; exit 1; }

readonly GCC_INCLUDE_DIR=${GCC_DIR}/include
[[ -d $GCC_INCLUDE_DIR ]] ||  { echo "${GCC_INCLUDE_DIR} not found"; exit 1; }

readonly GCC_LIB_DIR=${GCC_DIR}/lib/gcc/10
[[ -d $GCC_LIB_DIR ]] ||  { echo "${GCC_LIB_DIR} not found"; exit 1; }

export PATH="${SED_DIR}/libexec/gnubin:${PATH}"

echo "Environment"
echo "-----------"
echo PATH: $PATH
echo "-----------"


./configure \
     --prefix="$PWD/nextstep/" \
     --enable-locallisppath="${PWD}/nextstep/" \
     --with-mailutils \
     --with-ns \
     --with-imagemagick \
     --with-cairo \
     --with-modules \
     --with-xml2 \
     --with-gnutls \
     --with-json \
     --with-rsvg \
     --with-native-compilation \
     --disable-silent-rules \
     --disable-ns-self-contained \

Make it executable

chmod +x

Clone Emacs source

git clone --branch master gccemacs

Configure build

cd gccemacs

Native lisp compiler found?

Verify native lisp compiler is found:

Does Emacs have native lisp compiler?                   yes


Put those cores to use. Find out how many you got with:

sysctl hw.logicalcpu
hw.logicalcpu: 4

Ok so build with:

cp -r lisp nextstep/
cp -r native-lisp nextstep/
make install

Note: Using NATIVE_FAST_BOOT=1 significantly improves build time (totalling between 20-30 mins, depending on your specs). Without it, the build can take hours.

The macOS app build (under nextstep/ is ready, but read on before launching.

Remove ~/emacs.d

You likely want to start with a clean install, byte-compiling all packages with the latest Emacs version. In any case, rename ~/emacs.d (for backup?) or remove ~/emacs.d.

init.el config

Ensure exec-path includes the script's "–prefix=" value, LIBRARY_PATH points to gcc's lib dir, and finally set comp-deferred-compilation. I wrapped the snippet in my exec-path-from-shell config, but setting early in init.el should be enough.

(use-package exec-path-from-shell
  :ensure t
  (if (and (fboundp 'native-comp-available-p)
        (message "Native comp is available")
        ;; Using since it was compiled with
        ;; ./configure --prefix="$PWD/nextstep/"
        (add-to-list 'exec-path (concat invocation-directory "bin") t)
        (setenv "LIBRARY_PATH" (concat (getenv "LIBRARY_PATH")
                                       (when (getenv "LIBRARY_PATH")
                                       ;; This is where Homebrew puts gcc libraries.
                                       (car (file-expand-wildcards
                                             (expand-file-name "~/homebrew/opt/gcc/lib/gcc/*")))))
        ;; Only set after LIBRARY_PATH can find gcc libraries.
        (setq comp-deferred-compilation t))
    (message "Native comp is *not* available")))


You're good to go. Open via finder or shell:

open nextstep/

Deferred compilation logs

After setting comp-deferred-compilation (in init.el config section), .elc files should be asyncronously compiled. Function definition should be updated to native compiled equivalent.

Look out for an Async-native-compile-log buffer. Should have content like:

Compiling .emacs.d/elpa/moody-20200514.1946/moody.el...
Compiling .emacs.d/elpa/minions-20200522.1052/minions.el...
Compiling .emacs.d/elpa/persistent-scratch-20190922.1046/persistent-scratch.el...
Compiling .emacs.d/elpa/which-key-20200721.1927/which-key.el...

Can also check for .eln files:

find ~/.emacs.d -iname *.eln | wc -l

UPDATE1: Added Symlink section for update 11.

UPDATE2: Noted using NATIVE_FAST_BOOT makes the build much faster.

UPDATE3: Removed symlinks and copied content instead. This simplifies things. Inspired by Ian Wahbe's

UPDATE4: Removed homebrew recipe patching. Thanks to Dmitry Shishkin's instructions.

UPDATE5: Use new flag –with-native-compilation and master branch.