In this article we will see various steps to test/try emacs-28 with native compilation support on Ubuntu 20.04LTS. We will not touch existing emacs installed using apt on the Ubuntu, but will manually compile another version of emacs-28 with native-compilation support (called gccemacs henceforth) in the ~/opt/emacs-native folder. These two versions of emacs (already installed and gccemacs) will use different config files (init.el) and user-directories (~/.emacs.d) using chemacs2, so that they don't interfere with each other. Using this approach users can try gccemacs without breaking their stable emacs config.
Please help us improving this wiki by reporting any bugs/issues in the wiki github repo.
check for any errors during ./configure step, you may be missing some libraries, which need to be installed using apt.
mkdir -p ~/opt
mkdir -p ~/opt/emacs-native
cd ~/opt
sudo add-apt-repository ppa:ubuntu-toolchain-r/ppa
sudo apt install gcc-10 g++-10 libgccjit0 libgccjit-10-dev libjansson4 libjansson-dev
sudo apt install libxpm-dev libgif-dev libtiff-dev libgnutls28-dev libmagick++-dev
git clone git://git.sv.gnu.org/emacs.git gccemacs
cd gccemacs
git checkout master
export CC=/usr/bin/gcc-10 CXX=/usr/bin/gcc-10
./autogen.sh
./configure --with-cairo --with-modules --without-compress-install --with-x-toolkit=no --with-gnutls --without-gconf --without-xwidgets --without-toolkit-scroll-bars --without-xaw3d --without-gsettings --with-mailutils --with-native-compilation --with-json --with-harfbuzz --with-imagemagick --with-jpeg --with-png --with-rsvg --with-tiff --with-wide-int --with-xft --with-xml2 --with-xpm CFLAGS="-O3 -mtune=native -march=native -fomit-frame-pointer" prefix=~/opt/emacs-native
make -j2 NATIVE_FULL_AOT=1
make install
[ -f ~/.emacs ] && mv ~/.emacs ~/.emacs.bak
[ -d ~/.emacs.d ] && mv ~/.emacs.d ~/.emacs.default
git clone https://github.com/plexus/chemacs2.git ~/.emacs.d
(
("default" . ((user-emacs-directory . "~/.emacs.default")
(server-name . "default-server")))
("gccemacs" . ((user-emacs-directory . "~/.gccemacs.d")
(server-name . "gccemacs-server")))
)
mkdir -p ~/.gccemacs.d
cp ~/.emacs.default/init.el ~/.gccemacs.d/init.el
(setq comp-deferred-compilation t)
(if (and (fboundp 'native-comp-available-p)
(native-comp-available-p))
(message "Native compilation is available")
(message "Native complation is *not* available"))
(if (functionp 'json-serialize)
(message "Native JSON is available")
(message "Native JSON is *not* available"))
(use-package doom-themes
:straight '(doom-themes :build (:not native-compile))
:init
(load-theme 'doom-nord t)
)
emacs --with-profile=default
emacs --with-profile=default --daemon
emacsclient -c -s /run/user/1000/emacs/default-server
~/opt/emacs-native/bin/emacs --with-profile=gccemacs
~/opt/emacs-native/bin/emacs --with-profile=gccemacs --daemon
~/opt/emacs-native/bin/emacsclient -c -s /run/user/1000/emacs/gccemacs-server