从【求助】emacs 29 with native-comp 无法 dump继续讨论:
只在 macOS 用 GitHub - jimeh/emacs-builds: Self-contained Emacs.app builds for macOS, with native-compilation support. 试验过,Windows 或 Linux 请自行调整
用的 dump 脚本
.../Emacs --dump $EMDUMPDIR/Emacs.pdmp.bak -q --batch --load dump.el
dump.el
;; -*- lexical-binding: t; -*-
(setq native-comp-jit-compilation nil)
(package-initialize)
(load (concat user-emacs-directory "pkgs"))
(dolist (package '(mwim unfill ctrlf yasnippet orderless
which-key bind-key))
(require package))
(let (loaded-config-files)
(mapcar (lambda (pair)
(if (and (string-prefix-p (expand-file-name user-emacs-directory)
(car pair))
(not (string-suffix-p "-autoloads.el"
(car pair))))
(push (file-name-base (car pair)) loaded-config-files)))
load-history)
(dolist (file loaded-config-files)
(let* ((default-directory
(concat "~/.emacs.d/eln-cache/" comp-native-version-dir))
(filename (car (file-expand-wildcards (concat file "-*") t))))
(if filename
(copy-file filename
(concat "/Applications/Emacs.app/Contents/Frameworks/native-lisp/"
comp-native-version-dir "/")
t)
(warn "%s not exists!" file)))))
(defconst dumped-load-path load-path)
(defconst dumped-eln-path native-comp-eln-load-path)
(garbage-collect)
(dump-emacs-portable "~/.emacs.d/Emacs.pdmp")
init.el
(defvar dumped-load-path)
(if (not (boundp 'dumped-load-path))
(load (concat user-emacs-directory "pkgs"))
(setq load-path dumped-load-path
native-comp-jit-compilation t
native-comp-eln-load-path dumped-eln-path)
(global-font-lock-mode t)
(transient-mark-mode t)
(set-face-foreground 'homoglyph "#686868"))
几个细节,dump 时已经加载的 eln 必须要从 ~/.emacs.d/eln-cache 复制到 "/Applications/Emacs.app/Contents/Frameworks/native-lisp/" 不然 dump 后启动时提示找不到这些 eln
native-comp-eln-load-path 也不能在 dump 脚本里改,不然启动时会直接 segfault
dump 的脚本里也不能调用 native comp,不然会产生无法 dump 的内存内容,使 dump 失败
手动调用 native-compile 生成的 eln 是 package.-xxxxxx-xxxxx.eln 而不是 package-xxxxxx-xxxxx.eln,要注意。我还没有想好怎么设计自动重新编译的方法,现在是起一个 dump 前的 Emacs 等它自动触发编译