Building Emacs native-comp with Docker

2 minute read Published: 2021-04-29

Emacs has recently merged into the master branch a long-awaited feature: native compiling of Lisp modules using libgccjit (just-in-time compilation with GCC).

I was curious to try it without waiting the official Emacs 28.x branch release so I copied a Docker file "template" found at this link and adapted to my needs.

Changes I applied to that template:

Here is my Dockerfile, copy this file next to your emacs sources (which you will get by cloning their repository).

The steps to build the package from scratch:

$ git clone --depth=1 https://git.savannah.gnu.org/git/emacs.git
$ ls
emacs Dockerfile.emacs-native-comp
$ cd emacs
$ docker build -t debian:emacs-builder -f ../Dockerfile.emacs-native-comp .
$ container_id=$( docker run -d  --name kill-me-when-finished debian:emacs-builder )
$ docker cp $container_id:/src/emacs-nc_0.1-1_amd64.deb .
$ docker rm kill-me-when-finished

I am not interested in versioning this package (I'll delete it anyway after the official releases) so in the Dockerfile I've simply set --pkgversion="0.1".

You'll now have a emacs-nc_0.1-1_amd64.deb in the emacs directory. Be mindful that Emacs with JIT has quite a few dependencies. After you're done building you also might want to remove the Docker image (~2.6gb).

Happy hacking!