reddit / emacs

Emacs 28 with nativecomp on macOS with MacPorts and NOT Homebrew?

ragnese · 2022-04-12 20:17
Hi All, I apologize for the possibly annoying question, but I'm struggling to get Emacs 28's nativecomp to work. There are plenty of guides/posts online about installing libgccjit with Homebrew to get it to work. But, I've been using MacPorts for a long time and really don't have any desire to use both MacPorts and Homebrew. When I install any of the usual suspect Emacs packages in MacPorts (emacs-app, emacs-mac-app, etc), I get the same issue when Emacs starts up: it floods the \*Warnings\* buffer with stuff like: > Warning (comp): collect2: error: ld returned 1 exit status Disable showing Disable logging > Warning (comp): libgccjit.so: error: error invoking gcc driver Disable showing Disable logging > Warning (comp): /Applications/MacPorts/Emacs.app/Contents/Resources/lisp/outline.el.gz: Error: Internal native compiler error failed to compile Disable showing Disable logging Now, this is totally normal when GCC and/or libgccjit are not present, and a web search of these errors will find several forums posts and bug reports, etc. The Homebrew crowd just installs some specific GCC package and all is well for them. I pretty quickly realized that macOS's clang is aliased (or soft-linked, or something- I didn't investigate) to `gcc`. So, I suspected that I needed to install the real GCC from MacPorts. Since my $PATH has my ports directory prepended, running `gcc` from a shell does in fact call the correct, true, GCC. However, I suspect that Emacs still doesn't see the correct GCC when it starts up. If you're familiar with macOS and Emacs, you might know what I'm talking about when I say that I do use the `exec-path-from-shell` Emacs package, but I assume that it does its thing too late in the start-up process to help me. Does anyone know a straight-forward way to either change the GCC path(s) for Emacs early enough to matter, or just some other way to get nativecomp working with only using stuff from MacPorts? Thanks!
crawsphi · 2022-04-12 20:38
This should work. I have 28 installed via the 'emacs-mac-app' Port on two machines and using native comp successfully. You can see that the Port specifies gcc11 as one of its dependencies: https://ports.macports.org/port/emacs-mac-app/details/ so it should be Doing The Right Thing. I'd suggest the normal routine for a misbehaving computer: clear and reset. Try uninstalling 'emacs-mac-app', including dependencies, and making sure that your ports tree is current (`port selfupdate`).
ragnese · 2022-04-12 20:44
Hm. Well, it's very good to know that it works for you- that at least means it's an issue with my setup and not the port(s) being broken. I definitely have uninstalled and reinstalled multiple of the emacs ports. But I guess doing it again won't hurt! :P Do you have Xcode installed and all of its toolchain stuff?
crawsphi · 2022-04-12 20:48
> Do you have Xcode installed and all of its toolchain stuff? I do, yes. Very strange. :/
oldjawbone · 2022-04-12 21:40
I came across the suggestion somewhere to add something like the following to early-init.el (with appropriate paths): `(setenv "LIBRARY_PATH" "/usr/local/opt/gcc/lib/gcc/11:/usr/local/opt/libgccjit/lib/gcc/11:/usr/local/opt/gcc/lib/gcc/11/gcc/x86_64-apple-darwin21/11")` Really can't say if this is a good idea or not, but it sorted out the issue for me.
ragnese · 2022-04-12 22:01
Thanks for the tip! I wasn't sure if early-init would be early enough to do stuff like this. Here's the paths that worked with my current situation of installing the `emacs-app` port from MacPorts: (setenv "LIBRARY_PATH" "/opt/local/lib/gcc11:/opt/local/lib/libgcc:/opt/local/lib/gcc11/gcc/x86_64-apple-darwin21/11.2.0") I do hate having hacky stuff like this hanging out in my config because I'm **positive** this will cause issues some day when something is updated. :( But, it did work, and my Emacs is fast as snot now, so thank you!
crawsphi · 2022-04-13 04:20
This is interesting. I have the `exec-path-from-shell` package as part of my startup. I wonder if that's why I had no problem. The package doesn't set `LIBRARY_PATH`, but maybe `PATH` and `exec-path` are sufficient.
amake · 2022-04-13 09:41
I am the maintainer of the emacs-mac-app{,-devel} port and a contributor to emacs{,-app}{,-devel}. All of these ports work correctly “out of the box” on my machine, but you are not the only person to report this problem. I would try to fix it, but I can’t reproduce it.
ragnese · 2022-04-13 12:02
I appreciate your work! I wish I had any guess as to what's causing the issue, but honestly, I try to keep my work machines as vanilla as possible. So my MacPorts installation is not customized in anyway, I just do whatever Xcode tells me to do as far as installing the extra command line utils, etc. The only "system-wide" customization I do is that I use the MacPorts bash and bash-completions as my default shell... I even try to keep my Emacs config fairly minimal. All of my customizations/configurations are just installing packages and adding keybindings. I hardly mess with anything "low level" in Emacs. Is there a particular tracker issue that you're keeping open for this that I can follow? Or, if you ever want to test something or ask me for details of my setup, feel free to ping me.
ragnese · 2022-04-13 12:11
I use that package as well, so it's not that. :/
wargxs · 2022-04-13 21:48
Have you tried with https://github.com/purcell/exec-path-from-shell ? Edit: sorry you are already using it ..
gepardcv · 2022-04-14 00:01
Do you know of any incompatibilities between the latest emacs-mac code and older macOS and Xcode versions? I’m still on 10.14. When I build from source, none of the Mac-specific code seems to be there (terminal only), and the Emacs.app bundle only contains the Emacs.sh script, nothing else. I’m following the same procedures that built 26 and 27 Mac apps just fine.
amake · 2022-04-14 00:42
So this solved your problem? What was the value of `LIBRARY_PATH` before making this change? I apparently don't have a value for this set at all, so I should probably try to figure out what the effective default is.
amake · 2022-04-14 00:43
The original post says he or she does use exec-path-from-shell.
amake · 2022-04-14 00:46
It looks like this ticket has the same error messages: https://trac.macports.org/ticket/64976 But there are multiple tickets related to nativecomp: https://trac.macports.org/query?0_port=emacs&0_port_mode=%7E&0_status=%21closed&col=id&col=summary&col=port&col=status&col=owner&col=type&col=priority&col=time&col=changetime It sounds like my setup is basically the same as yours (no major system-wide customization; vanilla Emacs; Xcode installed; exec-path-from-shell) so I am at a loss as to why things aren't working. If setting `LIBRARY_PATH` fixed it for you though then that's a very good place to start investigating.
amake · 2022-04-14 00:47
emacs-mac 9.0 dropped support for OS X 10.9 and earlier, but 10.14 should be fine. What are your config flags?
amake · 2022-04-14 01:09
I didn't realize this until now, but this issue is documented in PROBLEMS: https://github.com/emacs-mirror/emacs/blob/575c3beb4c001687ce7a4581de005a16d6f2e081/etc/PROBLEMS#L2881-L2898 > ** Native Compilation on macOS > > Native complitation requires the libgccjit library to be installed and > its path available to Emacs. Errors such as: > > libgccjit.so: error: error invoking gcc driver > Error: Internal native compiler error failed to compile > > indicate Emacs can't find the library in running time. One can set > the "LIBRARY_PATH" environment variable in the early initialization > file; for example: > > (setenv "LIBRARY_PATH" > (string-join > '("/usr/local/opt/gcc/lib/gcc/11" > "/usr/local/opt/libgccjit/lib/gcc/11" > "/usr/local/opt/gcc/lib/gcc/11/gcc/x86_64-apple-darwin20/11.2.0") ":")) But I don't understand why some people installing from MacPorts have a problem with this and some don't.
gepardcv · 2022-04-14 05:36
Most recent attempt (cribbed from https://github.com/macports/macports-ports/blob/master/aqua/emacs-mac-app/Portfile): ./configure --disable-silent-rules \ --with-mac \ --enable-mac-app="${PWD}/mac-build" \ --prefix="${PWD}/mac-build" \ --enable-mac-self-contained \ --without-dbus \ --without-gconf \ --without-libotf \ --without-m17n-flt \ --without-harfbuzz \ --without-imagemagick \ --without-rsvg \ --without-xaw3d \ --with-libgmp \ --with-gnutls \ --with-xml2 \ --with-json \ --with-lcms2 \ --with-modules
wargxs · 2022-04-14 07:24
Ups!
amake · 2022-04-14 10:53
Last time I cleaned up the port I had a hell of a time getting the paths working right. My guess is: - The value of `--enable-mac-app` needs to be inside the repository tree, and may not like being even in a subdirectory. Try setting it to just `$PWD` and ensure you invoke from the repository root. - Get rid of `--prefix`. MacPorts sets it to the MacPorts prefix (`/opt/local` by default). Setting it to be inside the source tree causes problems in my experience.
ragnese · 2022-04-14 11:43
It did solve my problem, yes. And, like you, it was unset for me before adding that setenv call. I also wonder how the default behavior works when it's unset. I know that macOS links /usr/gcc to clang. Maybe it also does something that affects the effective LIBRARY_PATH? I wonder if using gcc-select from MacPorts to manually select the MacPorts gcc as the active one would make it so that I didn't have to set the LIBRARY_Path... I'll have to play around with it more when I have a bit of time.
gepardcv · 2022-04-14 15:13
Thanks! Setting `--enable-mac-app` to `$PWD` didn't make a difference: $ exa --tree Emacs.app Emacs.app └── Contents ├── MacOS │ └── Emacs.sh ├── PkgInfo └── Resources ├── document.icns └── Emacs.icns Maybe I'm using incorrect `make` targets? I run `make && make install`. That definitely used to work with 26 and 27.
gepardcv · 2022-04-14 20:45
It looks like my environment isn’t picking up Apple framework headers like Carbon.h. I should be able to figure it out. Thanks for your help. Looking more closely at the configure script flags gave me the clue I needed.
paretoOptimalDev · 2022-04-14 21:09
Wild guess... they use the exec-path-from-shell library and it does some equivalent of this?