Skip to content

Instantly share code, notes, and snippets.

@matteha
Forked from AllenDang/gccemacs.md
Last active August 12, 2020 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matteha/1ae5df9086445a497047930f283cf116 to your computer and use it in GitHub Desktop.
Save matteha/1ae5df9086445a497047930f283cf116 to your computer and use it in GitHub Desktop.
Build gccemacs on MacOS catalina with gcc 10 installed by homebrew.

Build gccemacs on MacOS catalina

It's a hard time to make gccemacs work on MacOS catalina. I've met countless problems by following every tutorials I can get from google. Fortunately I finally get it work!

Hope this tutorial could help you.

GCC with libgccjit enabled

cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula

Edit gcc.rb like this

@@ -53,7 +53,7 @@ class Gcc < Formula
     #  - Ada, which requires a pre-existing GCC Ada compiler to bootstrap
     #  - Go, currently not supported on macOS
     #  - BRIG
-    languages = %w[c c++ objc obj-c++ fortran]
+    languages = %w[c c++ objc obj-c++ fortran jit]

     osmajor = `uname -r`.split(".").first
     pkgversion = "Homebrew GCC #{pkg_version} #{build.used_options*" "}".strip
@@ -73,6 +73,7 @@ class Gcc < Formula
       --with-system-zlib
       --with-pkgversion=#{pkgversion}
       --with-bugurl=https://github.com/Homebrew/homebrew-core/issues
+      --enable-host-shared
     ]

     # Xcode 10 dropped 32-bit support

Build gcc by homebrew HOMEBREW_NO_AUTO_UPDATE=1 brew install gcc --build-from-source --force

Get gccemacs source code

Clone https://github.com/emacs-mirror/emacs and checkout feature/native-comp branch.

Build using this script

Create a build.sh outside emacs source code folder.

# native-comp optimization
export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:${PATH}"
export CFLAGS="-I/usr/local/Cellar/gcc/10.1.0/include"
export LDFLAGS="-L/usr/local/Cellar/gcc/10.1.0/lib/gcc/10 -I/usr/local/Cellar/gcc/10.1.0/include"
export LIBRARY_PATH="/usr/local/Cellar/gcc/10.1.0/lib/gcc/10:${LIBRARY_PATH:-}"
export CC="/usr/bin/clang"

cd emacs || exit

git clean -xfd

./autogen.sh

./configure \
     --disable-dependency-tracking \
     --disable-silent-rules \
     --enable-locallisppath=/usr/local/share/emacs/28.0.50/site-lisp \
     --prefix=/usr/local/opt/gccemacs \
     --without-dbus \
     --without-imagemagick \
     --with-mailutils \
     --with-ns \
     --disable-ns-self-contained \
     --with-cairo \
     --with-modules \
     --with-xml2 \
     --with-gnutls \
     --with-json \
     --with-rsvg \
     --with-nativecomp

# Ensure /usr/local/opt/gccemacs exists
rm -rf /usr/local/opt/gccemacs
mkdir /usr/local/opt/gccemacs

# Ensure the directory to which we will dump Emacs exists and has the correct
# permissions set.
libexec=/usr/local/libexec/emacs/28.0.50
if [ ! -d $libexec ]; then
  sudo mkdir -p $libexec
  sudo chown $USER $libexec
fi

make -j4
make install 

rm -rf "/Applications/Emacs.app"
mv nextstep/Emacs.app "/Applications/"

cd /usr/local/bin || exit
rm emacs
rm emacsclient
ln -s /usr/local/opt/gccemacs/bin/emacs .
ln -s /usr/local/opt/gccemacs/bin/emacsclient .


cd /Applications/Emacs.app/Contents || exit
ln -s /usr/local/opt/gccemacs/share/emacs/28.0.50/lisp .

cd /usr/local     
sudo ln -s /usr/local/opt/gccemacs/share/emacs/28.0.50/lisp lisp

To use Spacemacs

No special actions are needed.

To use Doom

Latest doom already support to compile all modules with native-comp.

Update to latest version.

To do so, upgrade doom to latest version. doom upgrade

Compile all modules

After that, do doom sync to compile all modules.

Generate local env file

Run doom env to generate local env file.

It's done.

Open emacs and feel the performance boost. Enjoy!

and add

~/.emacs.d/.local/straight/build/zmq/eln-x86_64-apple-darwin19.5.0-89a730c11dec204e/emacs-zmq-x86_64-apple-darwin17.4.0git:(develop) mv emacs-zmq.so.dylib emacs-zmq.dylib
~/.emacs.d/.local/straight/build/zmq/eln-x86_64-apple-darwin19.5.0-89a730c11dec204e/emacs-zmq-x86_64-apple-darwin17.4.0git:(develop) ls -latrh total 3824 -rwxr-xr-x 1 admin staff 954K Aug 12 11:53 emacs-zmq.dylib drwxr-xr-x 4 admin staff 128B Aug 12 11:54 . -rwxr-xr-x 1 admin staff 954K Aug 12 11:55 emacs-zmq.so drwxr-xr-x 5 admin staff 160B Aug 12 11:55 ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment