summaryrefslogtreecommitdiff
path: root/guix/build
diff options
context:
space:
mode:
authorMaxim Cournoyer <maxim.cournoyer@gmail.com>2022-09-15 11:29:02 -0400
committerMaxim Cournoyer <maxim.cournoyer@gmail.com>2022-09-15 11:43:21 -0400
commit4920f6e634eeecb37b501bdc024dfe0aab849ed0 (patch)
treec7dd5859715071cb602133b67449a29488027f70 /guix/build
parent513091dbd2eeba138b558f5f9bb1ee6e68eee01d (diff)
parent3d297a0017210f1dd135592efb10846840a8af88 (diff)
Merge branch 'staging' into core-updates
Conflicts resolved in: gnu/local.mk gnu/packages/cmake.scm gnu/packages/glib.scm gnu/packages/gnome.scm gnu/packages/gtk.scm gnu/packages/sdl.scm pango-next, vala-next and librsvg-bootstrap were removed in the process.
Diffstat (limited to 'guix/build')
-rw-r--r--guix/build/emacs-build-system.scm20
-rw-r--r--guix/build/emacs-utils.scm39
2 files changed, 57 insertions, 2 deletions
diff --git a/guix/build/emacs-build-system.scm b/guix/build/emacs-build-system.scm
index 6a6918bfdd..3808b60445 100644
--- a/guix/build/emacs-build-system.scm
+++ b/guix/build/emacs-build-system.scm
@@ -108,13 +108,29 @@ environment variable\n" source-directory))
(format #t "expanded load paths for ~{~a~^, ~}\n"
(map basename diff))))))
+(define* (add-install-to-native-load-path #:key outputs #:allow-other-keys)
+ "Append the native-site-lisp of OUTPUT to EMACSNATIVELOADPATH."
+ (let ((native-load-path (or (false-if-exception
+ (string-split (getenv "EMACSNATIVELOADPATH") #\:))
+ '()))
+ (install-directory (string-append (assoc-ref outputs "out")
+ "/lib/emacs/native-site-lisp")))
+ (setenv "EMACSNATIVELOADPATH"
+ ;; Emacs pushes these directories in reverse order, so the
+ ;; last one will be the first.
+ (string-join `(,@native-load-path ,install-directory)
+ ":"))))
+
(define* (build #:key outputs inputs #:allow-other-keys)
"Compile .el files."
+ ;; Ensure that already compiled files in the working directory don't shadow
+ ;; the build. Might happen, because check runs first.
+ (for-each delete-file (find-files "." "\\.el[cn]$"))
(let* ((emacs (search-input-file inputs "/bin/emacs"))
(out (assoc-ref outputs "out")))
(setenv "SHELL" "sh")
(parameterize ((%emacs emacs))
- (emacs-byte-compile-directory (elpa-directory out)))))
+ (emacs-compile-directory (elpa-directory out)))))
(define* (patch-el-files #:key outputs #:allow-other-keys)
"Substitute the absolute \"/bin/\" directory with the right location in the
@@ -343,6 +359,8 @@ for libraries following the ELPA convention."
(modify-phases gnu:%standard-phases
(replace 'unpack unpack)
(add-after 'unpack 'expand-load-path expand-load-path)
+ (add-after 'expand-load-path 'add-install-to-native-load-path
+ add-install-to-native-load-path)
(delete 'bootstrap)
(delete 'configure)
(delete 'build)
diff --git a/guix/build/emacs-utils.scm b/guix/build/emacs-utils.scm
index 8ee547f2b3..b2280ae70c 100644
--- a/guix/build/emacs-utils.scm
+++ b/guix/build/emacs-utils.scm
@@ -38,6 +38,7 @@
emacs-generate-autoloads
emacs-byte-compile-directory
+ emacs-compile-directory
emacs-header-parse
as-display
@@ -105,7 +106,14 @@ true, evaluate using dynamic scoping."
(let* ((file (string-append directory "/" name "-autoloads.el"))
(expr `(let ((backup-inhibited t)
(generated-autoload-file ,file))
- (update-directory-autoloads ,directory))))
+ (cond
+ ((require 'loaddefs-gen nil t)
+ ;; Emacs >= 29
+ (loaddefs-generate ,directory ,file))
+ ((fboundp 'make-directory-autoloads)
+ ;; Emacs 28
+ (make-directory-autoloads ,directory ,file))
+ (t (update-directory-autoloads ,directory))))))
(emacs-batch-eval expr #:dynamic? #t)))
(define* (emacs-byte-compile-directory dir)
@@ -115,6 +123,35 @@ true, evaluate using dynamic scoping."
(byte-recompile-directory (file-name-as-directory ,dir) 0 1))))
(emacs-batch-eval expr)))
+(define* (emacs-compile-directory dir)
+ "Compile all files in DIR to native code.
+
+If native code is not supported, compile to bytecode instead."
+ (emacs-batch-eval
+ `(let ((byte-compile-debug t) ; for proper exit status
+ (byte+native-compile (native-comp-available-p))
+ (files (directory-files-recursively ,dir "\\.el$")))
+ (mapc
+ (lambda (file)
+ (let (byte-to-native-output-file
+ ;; First entry is the eln-cache of the homeless shelter,
+ ;; second entry is the install directory.
+ (eln-dir (and (native-comp-available-p)
+ (cadr native-comp-eln-load-path))))
+ (if byte+native-compile
+ (native-compile file
+ (comp-el-to-eln-filename file eln-dir))
+ (byte-compile-file file))
+ ;; Sadly, we can't use pcase because quasiquote works different in
+ ;; Emacs. See `batch-byte+native-compile' in comp.el for the
+ ;; actual shape of byte-to-native-output-file.
+ (unless (null byte-to-native-output-file)
+ (rename-file (car byte-to-native-output-file)
+ (cdr byte-to-native-output-file)
+ t))))
+ files))
+ #:dynamic? #t))
+
(define (emacs-header-parse section file)
"Parse the header SECTION in FILE and return it as a string."
(emacs-batch-script