mirror of
https://github.com/jimeh/build-emacs-for-macos.git
synced 2026-02-19 13:06:38 +00:00
The new libgccjit Homebrew formula negates the need to install a custom
patched gcc formula from source to get libgccjit.
As it's a separate formula, the file structure is a bit different
though, requiring some changes to the script. This means it is no longer
compatible libgccjit from the custom gcc formula. If you already have
the custom patched gcc formula installed, you can replace it with the
standard gcc formula by running:
brew reinstall gcc
In theory though, it should work even with the patched gcc formula, as
long as libgccjit is installed too. But it will probably produce a
Emacs.app that's around 35MB larger than it needs to, thanks to
duplicating the libgccjit.so.0.0.1 file within the final application.
BREAKING CHANGE: Standard Homewbrew `gcc` and `libgccjit` formula are now required for native-comp, instead of the custom patched gcc formula.
51 lines
2.2 KiB
Diff
51 lines
2.2 KiB
Diff
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
|
|
index 25e2de9..bcedd31 100644
|
|
--- a/lisp/emacs-lisp/comp.el
|
|
+++ b/lisp/emacs-lisp/comp.el
|
|
@@ -2801,6 +2801,45 @@ queued with LOAD %"
|
|
(comp-run-async-workers)
|
|
(message "Compilation started."))))
|
|
|
|
+;;;###autoload
|
|
+(defun native-compile-setup-environment-variables (&rest _args)
|
|
+ "Ensure LIBRARY_PATH is set correctly when libgccjit is bundled."
|
|
+ (when (and (eq system-type 'darwin)
|
|
+ (string-match-p "\.app\/Contents\/MacOS\/?$"
|
|
+ invocation-directory))
|
|
+ (let* ((library-path-env (getenv "LIBRARY_PATH"))
|
|
+ (gcc-base-dir (concat invocation-directory "lib/gcc"))
|
|
+ (gcc-version (car (seq-filter
|
|
+ (lambda (dir) (string-match-p "^[0-9]+$" dir))
|
|
+ (directory-files gcc-base-dir))))
|
|
+ (gcc-dir (concat gcc-base-dir "/" gcc-version))
|
|
+ (darwin-base-dir (car (file-expand-wildcards
|
|
+ (concat gcc-dir "/gcc/*apple-darwin*"))))
|
|
+ (darwin-version (car (seq-filter
|
|
+ (lambda (dir)
|
|
+ (string-match-p
|
|
+ "^[0-9]+\\(\.[0-9]+\\(\.[0-9]+\\)?\\)?$" dir))
|
|
+ (directory-files darwin-base-dir))))
|
|
+ (darwin-dir (concat darwin-base-dir "/" darwin-version))
|
|
+ (lib-paths (append
|
|
+ (list gcc-dir darwin-dir)
|
|
+ (if library-path-env (list library-path-env) (list)))))
|
|
+
|
|
+ (when (and gcc-dir darwin-dir)
|
|
+ (setenv "LIBRARY_PATH" (mapconcat 'identity lib-paths ":")))))
|
|
+
|
|
+ ;; Remove advice, as it only needs to run once.
|
|
+ (advice-remove 'native-compile
|
|
+ 'native-compile-setup-environment-variables)
|
|
+ (advice-remove 'native-compile-async
|
|
+ 'native-compile-setup-environment-variables))
|
|
+
|
|
+;; Ensure environment setup runs before any native compilation.
|
|
+(advice-add 'native-compile :before
|
|
+ 'native-compile-setup-environment-variables)
|
|
+(advice-add 'native-compile-async :before
|
|
+ 'native-compile-setup-environment-variables)
|
|
+
|
|
(provide 'comp)
|
|
|
|
;;; comp.el ends here
|