Gentoo overlay for adding AOT native compilation support for emacs packages to portage.
Add this overlay to the systems repos and add eln
to load-suffixes
in your emacs early-init.el
.
(add-to-list 'load-suffixes ".eln")
To prevent emacs from JIT compiling packages set native-comp-jit-compilation
to nil
.
(setq native-comp-jit-compilation nil)
Todo: Make packages add themselves to the JIT compilation deny list, which allows using portage AOT compilation and JIT compilation at the same time.
Enable the native-compilation
USE flag to enable native compilation on packages that inherit from elisp-common.eclass
or elisp.eclass
.
Add gentoo.git
as a remote, then compare or checkout ebuilds from gentoo’s master
branch.
The elisp eclasses have been modified to compile and install binaries when the native-compilation
USE flag is enabled.
elisp-compile
simply invokes the native compilation alternative to batch-compile
, batch-native-compile
.
The variable native-compile-target-directory
is set to default-directory
which causes emacs to output compiled binaries in the current working directory. This is how batch-compile
works by default.
When provided, elisp-install will install binaries along with source and bytecode files.
Each package is installed into it’s own subdirectory inside of ${NATIVELISP}
(technically a subdirectory of a version and ABI derived subdirectory in ${NATIVELISP}
The packages sitefile is used to configure emacs to use the binaries. This is done by appending the path to the binaries to load-path
and adding eln
to load-suffixes
.
The sitefile also contains a condition that checks if the currently running emacs instance is the same version and has the same ABI as the one that was used to build and install the binaries for this package. This is done using the value of comp-native-version-dir
in emacs. Users can have this value interpolated into the sitefile using the @COMP_NATIVE_VERSION_DIR@
token.
;; use elisp binaries if possible
;;
;; @NATIVELISP@ expands to the path containing the packages
;; binaries.
(when (and (ignore-errors (native-comp-available-p))
(string= comp-native-version-dir "@COMP_NATIVE_VERSION_DIR@"))
(add-to-list 'load-path "@NATIVELISP@"))
A few very small patches have been applied to comp.el
to make batch-native-compile
function more package manager friendly.
Before patching, batch-native-compile
would not respect native-compile-target-directory
, and only gave an option of using the last value of native-comp-eln-load-path
which is intended to be used for binaries for packages built into emacs.
Also before patching, batch-native-compile
would mangle filenames. The name mangling algorithm uses hashes of the source files absolute filename and it’s contents. Package managers such as portage typically compile files in a temporary directory and then move them into the root filesystem when installing, which breaks the name managling algorithm.
These patches can be found in ${elisp-native-comp}/app-editors/emacs/files
.