mirror of
https://github.com/jimeh/build-emacs-for-macos.git
synced 2026-02-19 09:36:42 +00:00
The old patch would dynamically glob within Emacs.app/Contents/MacOS/lib/gcc using the full absolute path to Emacs.app. If there are obsure characters like "[]" and others in the absolute path, it can cause glob search within the native-compile-setup-environment-variables function to fail, in turn preventing native-comp from working. The fix is to hard-code the relative paths from Emacs' invocation-directory (**/Emacs.app/Contents/MacOS) into the environment setup function itself, making it very simple and effectively just joining a few strings and setting an environment variable. It did require a little bit of cleanup and better organization of the GCC/libgccjit releated code in the build script, creating a new GccInfo class which is the central place for determining various paths and information about GCC and libgccjit which the build will be using.
58 lines
2.3 KiB
Plaintext
58 lines
2.3 KiB
Plaintext
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
|
|
index 4036080976..2ff8dbd74c 100644
|
|
--- a/lisp/emacs-lisp/comp.el
|
|
+++ b/lisp/emacs-lisp/comp.el
|
|
@@ -4079,6 +4079,52 @@ of (commands) to run simultaneously."
|
|
(let ((load (not (not load))))
|
|
(native--compile-async paths recursively load selector)))
|
|
|
|
+;;;###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"))
|
|
+ (devtools-dir
|
|
+ "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib")
|
|
+ (gcc-dir (expand-file-name
|
|
+ "<%= relative_lib_dir %>"
|
|
+ invocation-directory))
|
|
+ (darwin-dir (expand-file-name
|
|
+ "<%= relative_darwin_lib_dir %>"
|
|
+ invocation-directory))
|
|
+ (lib-paths (list)))
|
|
+
|
|
+ (if library-path-env
|
|
+ (push library-path-env lib-paths))
|
|
+ (if (file-directory-p devtools-dir)
|
|
+ (push devtools-dir lib-paths))
|
|
+ (push darwin-dir lib-paths)
|
|
+ (push gcc-dir lib-paths)
|
|
+
|
|
+ (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 'comp--native-compile
|
|
+ 'native-compile-setup-environment-variables)
|
|
+ (advice-remove 'native-compile-async
|
|
+ '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 'comp--native-compile :before
|
|
+ 'native-compile-setup-environment-variables)
|
|
+(advice-add 'native-compile-async :before
|
|
+ 'native-compile-setup-environment-variables)
|
|
+(advice-add 'native--compile-async :before
|
|
+ 'native-compile-setup-environment-variables)
|
|
+
|
|
(provide 'comp)
|
|
|
|
;;; comp.el ends here
|