Read this first: http://akrl.sdf.org/gccemacs.html
For that you need to compile gcc (duh). I edited Homebrew's gcc formula:
diff --git a/Formula/gcc.rb b/Formula/gcc.rb
index 1bd636d496..03ad124218 100644
--- a/Formula/gcc.rb
+++ b/Formula/gcc.rb
@@ -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
(easy way to apply this is to cd into /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
and
run pbpaste | git apply -
after copying the diff into clipboard 😄)
(or whereever is your Homebrew library set up)
- giflib
- jpeg
- libtiff
- gnutls
And XQuartz, because GCC is not able to parse Objective-C dialect changes what Apple has done for now and thus Apple Cocoa support is not available. (See: https://lists.gnu.org/archive/html/emacs-devel/2019-08/msg00056.html)
Clone https://github.com/emacs-mirror/emacs and checkout feature/native-comp
branch
Here's the script I used (note to adjust package versions if needed):
libs=(
/usr/local/Cellar/gcc/9.2.0_2
/usr/local/Cellar/giflib/5.2.1
/usr/local/Cellar/jpeg/9c
/usr/local/Cellar/libtiff/4.1.0
/usr/local/Cellar/gnutls/3.6.10
# Required by gnutls
/usr/local/Cellar/nettle/3.4.1
/usr/local/Cellar/libtasn1/4.15.0
/usr/local/Cellar/p11-kit/0.23.18.1
)
export PATH="/usr/local/Cellar/gcc/9.2.0_2/bin:${PATH}"
export CC="gcc-9"
export CPP="cpp-9"
CFLAGS=""
LDFLAGS=""
PKG_CONFIG_PATH=""
for dir in "${libs[@]}"; do
CFLAGS="${CFLAGS}-I${dir}/include "
LDFLAGS="${LDFLAGS}-L${dir}/lib "
PKG_CONFIG_PATH="${PKG_CONFIG_PATH}${dir}/lib/pkgconfig:"
done
export CPPFLAGS="${CFLAGS}"
export CFLAGS
export LDFLAGS
export PKG_CONFIG_PATH
./configure \
--prefix="${HOME}"/gccemacs \
--with-nativecomp \
--without-ns
Save it into build.sh
Then run:
sh build.sh && make bootstrap && make install
And result is in ~/gccemacs
. Add ~/gccemacs/bin
into PATH and start experimenting with el native building
I've also run into an issue where Emacs seems to create a problematic (non-zero size) eln file for
cl-lib
sometimes. After exiting Emacs and attempting to restart, I get the following error:If I delete
~/.emacs.d/eln-cache/28.0.50-x86_64-apple-darwin19.6.0-24f1b3501916c3935f73bd09c228268f/cl-lib-388247404020ff233a151179ccaf7d0e-fa297bdec2c84d1f0a3a03da76744f30.eln
, Emacs starts successfully.I've pushed the eln file and the original
cl-lib.el
file here:https://github.com/schellj/emacs-native-comp-debug/blob/problematic-cl-lib/eln-cache/28.0.50-x86_64-apple-darwin19.6.0-24f1b3501916c3935f73bd09c228268f/cl-lib-388247404020ff233a151179ccaf7d0e-fa297bdec2c84d1f0a3a03da76744f30.eln
https://github.com/schellj/emacs-native-comp-debug/blob/problematic-cl-lib/cl-lib.el
PS - Is there a better place to report issues like this @AndreaCorallo ?