daviderestivo / homebrew-emacs-head

GNU Emacs formula for the Homebrew package manager
GNU General Public License v3.0
297 stars 29 forks source link

Native comp on Emacs 29 does not seem to work #129

Closed jmckitrick closed 2 years ago

jmckitrick commented 2 years ago

I realize this could be user error, but in the interest of helping other users, I'd like to figure out what is going wrong, and contribute to improvements in the formula or the docs.

I build this formula once a week, and decided to try native comp for the first time. Everything seems fine until it loads, then the frame fills with error messages from libgccjit failures. I have a feeling it's a missing dependency, but I thought I got everything that was required. I'd like to figure out what I missed, and help document the issue for anyone else trying the same feature. I have gcc and libgccjit installed, so....

Here are the first few error messages:

Warning (initialization): An error occurred while loading ‘/Users/jmckitrick/.emacs.d/init.el’:

Native compiler error: (lambda (arg1 &optional) (let ((f #'yes-or-no-p)) (funcall f arg1))), Compiling /Users/jmckitrick/.emacs.d/eln-cache/28.0.60-3d05cc13/subr--trampoline-7965732d6f722d6e6f2d70_yes_or_no_p_0.eln...
ld: library not found for -lgcc_ext.10.5
libgccjit.so: error: error invoking gcc driver
Debugger entered--Lisp error: (native-ice "failed to compile" "/Users/jmckitrick/.emacs.d/eln-cache/28.0.60-3d05c..." "error invoking gcc driver")
  comp--compile-ctxt-to-file("/Users/jmckitrick/.emacs.d/eln-cache/28.0.60-3d05c...")
  comp-compile-ctxt-to-file("/Users/jmckitrick/.emacs.d/eln-cache/28.0.60-3d05c...")
  comp-final1()
  load-with-code-conversion("/private/var/folders/27/xs02f08d325_q2vh49wks48r00..." "/private/var/folders/27/xs02f08d325_q2vh49wks48r00..." nil t)
  command-line-1(("-l" "/var/folders/27/xs02f08d325_q2vh49wks48r0000gn/T/e..."))
  command-line()
  normal-top-level()

Warning (comp): libgccjit.so: error: error invoking gcc driver Disable showing Disable logging
Warning (comp): /usr/local/Cellar/emacs-head@28/28.0.50_1/share/emacs/28.0.60/lisp/url/url-vars.el.gz: Error: Internal native compiler error failed to compile Disable showing Disable logging
Warning (comp): libgccjit.so: error: error invoking gcc driver Disable showing Disable logging
Warning (comp): /usr/local/Cellar/emacs-head@28/28.0.50_1/share/emacs/28.0.60/lisp/password-cache.el.gz: Error: Internal native compiler error failed to compile Disable showing Disable logging
daviderestivo commented 2 years ago

Try to uninstall emacs-head@28 and libgccjit and install emacs-head@29 and libgccjit once again.

jmckitrick commented 2 years ago

Same exact result. The build succeeds, but starting emacs produces the same error messages.

daviderestivo commented 2 years ago

Just to be sure, have you tried to:

$ brew uninstall gcc libgccjit
$ brew install gcc libgccjit

?

jmckitrick commented 2 years ago

Yep, I just tried the whole process again, with the same result. Very frustrating.

Could it be a classpath or lib path issue?

On Sun, Oct 17, 2021 at 3:48 AM Davide Restivo @.***> wrote:

Just to be sure, have you tried to:

$ brew uninstall gcc libgccjit $ brew install gcc libgccjit

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/daviderestivo/homebrew-emacs-head/issues/129#issuecomment-945067187, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAD6PKKMOSPOUHIYBNB2D6LUHJ5VPANCNFSM5GCIXDFQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

daviderestivo commented 2 years ago

Do you have something in early-init.el? or did you set LIBRARY_PATH manually? Can you give me the output of env from a shell?

jmckitrick commented 2 years ago

No, nothing special. Emacs can find ripgrep, java, clojure, scala, etc.

On Sun, Oct 17, 2021 at 10:28 AM Davide Restivo @.***> wrote:

Do you have something in early-init.el? or did you set LIBRARY_PATH manually?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/daviderestivo/homebrew-emacs-head/issues/129#issuecomment-945135090, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAD6PKJQCJAMKA4A6KT4PVLUHLMPLANCNFSM5GCIXDFQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

daviderestivo commented 2 years ago

No, nothing special. Emacs can find ripgrep, java, clojure, scala, etc.

Please share there output of env and the content of early-init.el :)

jmckitrick commented 2 years ago
Screen Shot 2021-10-17 at 2 49 37 PM

Nothing in early-init.el

jmckitrick commented 2 years ago

Also, exec-path:

exec-path is a variable defined in ‘C source code’.

Its value is ("/usr/bin" "/bin" "/usr/sbin" "/sbin" "/usr/local/Cellar/emacs-head@29/29.0.50_1/libexec/emacs/29.0.50/x86_64-apple-darwin20.6.0")

jmckitrick commented 2 years ago

I think I found a solution. I'll post details when I'm sure....

jmckitrick commented 2 years ago

It turns out there are instructions in a troubleshooting README in emacs source for adding an early-init.el with correct library paths for macos. That seemed to do the trick.

Final question: will native comp work with the M1 chip?

daviderestivo commented 2 years ago

It turns out there are instructions in a troubleshooting README in emacs source for adding an early-init.el with correct library paths for macos. That seemed to do the trick.

Could you please share a bit more details?

Final question: will native comp work with the M1 chip?

As far as I know yes but I didn't test myself.

jmckitrick commented 2 years ago

https://github.com/emacs-mirror/emacs/blob/f56408a6f0152cd46d1ea8a0985fbfeeb839ea06/etc/PROBLEMS#L2772

jmckitrick commented 2 years ago

I followed these directions and it almost worked. One caveat: I needed this line as well

(eval-when-compile (require 'subr-x))

There might be a better way, but at least it's working now.

jmckitrick commented 2 years ago

Now I'm trying on M1, and even though the entire project builds and runs as normal (regular emacs head) trying to add native compilation fails early in the process. I have a feeling this is a simple config issue, but I'm not sure how to tackle it for arm64.

Screen Shot 2021-10-26 at 8 15 14 PM
jmckitrick commented 2 years ago

I thought maybe it was a 'no correct' setting in my zsh config, but even when I removed that, I got the error.

daviderestivo commented 2 years ago

I thought maybe it was a 'no correct' setting in my zsh config, but even when I removed that, I got the error.

I think the problem is that the compiler is not found. Do you have the "Command Line Tools" installed under /Library/Developer/CommandLineTools/?

jmckitrick commented 2 years ago

I thought you might be right, but I checked, and the folder is there with all the tools.

I've also asked on the emacs help forum.

On Wed, Oct 27, 2021 at 4:43 AM Davide Restivo @.***> wrote:

I thought maybe it was a 'no correct' setting in my zsh config, but even when I removed that, I got the error.

I think the problem is that the compiler is not found. Do you have the "Command Line Tools" installed under /Library/Developer/CommandLineTools/?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/daviderestivo/homebrew-emacs-head/issues/129#issuecomment-952680555, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAD6PKLWH36WMDUPDN3EGT3UI7CU7ANCNFSM5GCIXDFQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

jmckitrick commented 2 years ago

A user suggested I manually set CFLAGS or remove -march=native.

I've worked with Linux projects and autoconf a bit in the distant past, but I have not worked with brew formulae. How might I do this?

jmckitrick commented 2 years ago

Problem solved! I needed to run brew edit and remove the line with -march=native and everything worked fine after that.

daviderestivo commented 2 years ago

Fixed in https://github.com/daviderestivo/homebrew-emacs-head/pull/139. Please lemme know if it works for you.