Subject: bug#44676: [PATCH] Support native compilation of packages on install

From: Stefan Kangas <[email-masked]>
Date: Sun, 15 Nov 2020 18:38:20 -0800

Severity: wishlist

Please find attach a patch to add support to package.el for native
compilation of packages on installation.

I've done some minimal testing and it seems to do the job.

(This is intended for the native-comp branch.)
From 9a0da21a6989b20f593ec2b27a48eb4ef90561b7 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <[email-masked]>
Date: Mon, 16 Nov 2020 03:28:39 +0100
Subject: [PATCH] Support native compilation of packages on install

* lisp/emacs-lisp/package.el (package-unpack)
(package--native-compile): Native compile packages on install, if the
feature is available.
---
 lisp/emacs-lisp/package.el | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index a381ca01f3..54b42db181 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -968,6 +968,7 @@ package-unpack
         ;; E.g. for multi-package installs, we should first install all packages
         ;; and then compile them.
         (package--compile new-desc)
+        (package--native-compile new-desc)
         ;; After compilation, load again any files loaded by
         ;; `activate-1', so that we use the byte-compiled definitions.
         (package--load-files-for-activation new-desc :reload)))
@@ -1052,6 +1053,12 @@ package--compile
         (load-path load-path))
     (byte-recompile-directory (package-desc-dir pkg-desc) 0 t)))
 
+(defun package--native-compile (pkg-desc)
+  (when (and (featurep 'nativecomp)
+             (native-comp-available-p))
+    (let ((warning-minimum-level :error))
+      (native-compile-async (package-desc-dir pkg-desc) t 'late))))
+
 ;;;; Inferring package from current buffer
 (defun package-read-from-string (str)
   "Read a Lisp expression from STR.
-- 
2.29.2