How to native-compile custom code during 'doom sync'?

What happened?

I have bit of custom elisp code (few hundred lines) that gets loaded from config.el with (load "~/path/my.el"). I have noticed these functions are never natively compiled. Some of them are bit long running, and will be helped by native-comp.

What did you expect to happen?

Doom/Emacs should automatically natively compile these custom functions either ahead of time or JIT as stock emacs.

Steps to reproduce

  1. Define long running functions in separate file
  2. (load " ~/path/file.el")
  3. doom sync
  4. Run custom function
  5. C-h o custom-function RET

System information

Loading data dump...

Maybe not exactly what you’re looking for, but you could put the code you want to have native-compiled into a repository and reference it locally in packages.el. Then you can include it like so:

(package! my-elisp :recipe
  (:local-repo "~/my-elisp"))

While this builds doom config, as soon as Emacs launches it complains about missing function definition from my file that are called in rest of the config. So while doom sync says the package is built, it isn’t actually loaded when Emacs starts.

You’ll need to actually write the repository as if it was a package, which means you’ll need to add a provide statement at the end of the file in question, and then require it in your configuration:

(defun my-elisp-foo ()
  (message "hi"))

(provide 'my-elisp)


(require 'my-elisp)