d12frosted / homebrew-emacs-plus

Emacs Plus formulae for the Homebrew package manager
MIT License
2.36k stars 182 forks source link

native-comp branch option #187

Closed seagle0128 closed 3 years ago

seagle0128 commented 4 years ago

The native compiling is a amazing feature to improve the Emacs performance. I'd like get an option to build this branch. Thanks!

https://github.com/emacs-mirror/emacs/tree/feature/native-comp

d12frosted commented 3 years ago

Didn't work for me 😿 While I am sorry that you you spent time on this patch, I am happy that you did it :)

Let me know if emacs-plus works for you.

ghost commented 3 years ago

@d12frosted, setting LIBRARY_PATH worked for me but with one slight modification:

(setenv "LIBRARY_PATH" "/usr/local/opt/gcc/lib/gcc/10:/usr/local/opt/libgccjit/lib/gcc/10:/usr/local/opt/gcc/lib/gcc/10/gcc/x86_64-apple-darwin20/10.2.0")

Notice the darwin20. I'm running Big Sur (darwin20).

$ ls /usr/local/opt/gcc/lib/gcc/10/gcc/x86_64-apple-darwin20/10.2.0/

~Unfortunately, something else broke with my emacs setup that I'm now trying to figure out but afaict the native branch worked and the async compilation was going through and doing its thing and I no longer saw the "error invoking gcc driver".~

EDIT: fixed my other issues and am successfully compiling my packages to native (reading through Async-native-compile-log)

EDIT 2: I removed the (setenv ...) from my init.el and re-installed gcc and libgccjit like others suggested and still have a working build :)

$ brew reinstall gcc libgccjit --force --build-from-source

EDIT 3: see this comment below, --force --build-from-source and not necessary

d12frosted commented 3 years ago

Alright... seems like I had to reinstall gcc and now it works! 🎉 @rgrmrts

DaniruKun commented 3 years ago

Same, I had to manually force reinstall with brew install gcc --build-from-source --force, but now Doom Emacs doesn't work, but at least Emacs itself compiles and launches!

jimeh commented 3 years ago

@d12frosted no worries about the patch, was only a few minutes, the timing was just funny :)... And yeah for me locally on Catalina the formula is working fine with native compiling out of the box without any environment setup, both from terminal and launching Emacs.app via Finder.

daviderestivo commented 3 years ago

@d12frosted that's a shame, and I just finished the absolute path hacky patch 4 seconds before I got a notification about your comment... lol

@jimeh Thanks for the patch. I will include it as well on emacs-head :)

jimeh commented 3 years ago

@daviderestivo Oh, cool :)... I'm not quite happy with its hacky-ness, so I'll try and ping you if I come up with something better, or if it needs any tweaks as I recently had to do.

daviderestivo commented 3 years ago

@daviderestivo Oh, cool :)... I'm not quite happy with its hacky-ness, so I'll try and ping you if I come up with something better, or if it needs any tweaks as I recently had to do.

Thanks a lot ... and thanks as well for the nice work you have done on build-emacs-for-macos. I took a lot of inspiration from it 👍

ghost commented 3 years ago

Just FYI, if gcc doesn't work for you, simply brew reinstall gcc libgccjit will do. There is no need to build from source.

d12frosted commented 3 years ago

Indeed, reinstalling gcc worked fine for me. Realised that thanks to @rgrmrts and his Notice the darwin20 part 😸

Alright, now I can say this at last. THANK YOU all who made it possible 😸 💯 🎉 This was quite a ride! Now let's the most fun part begin - fixing compilation of own init.el 😸 Share your tips here.

d12frosted commented 3 years ago

BTW, while I was reinstalling the whole thing, I wanted to do some writing and realised that I don't have Emacs - it's installing! It's always a bummer when Emacs is no available. Like, why the hell does this computer even exist if there is no Emacs???

jimeh commented 3 years ago

@d12frosted haha... that's part of the reason I try to use self-contained Emacs.app bundles myself. Though the flip-side of that is, when I'm trying to track down a bug with native-comp, I've at times had like 5-6 separate Emacs.app bundles floating around and I can hardly keep track of which is which... lol

razzmatazz commented 3 years ago

I have tried to fix homebrew-core's libgccjit formula issues a bit and drop dependency on gcc:

Apparently current libgccjit does not bundle are the required bin and lib files. Also this PR should unlock arm64 builds for libgccjit too.

razzmatazz commented 3 years ago

I have tried to fix homebrew-core's libgccjit formula issues a bit and drop dependency on gcc:

* [Homebrew/homebrew-core#67706](https://github.com/Homebrew/homebrew-core/pull/67706)

* [Homebrew/homebrew-core@c8c9cc7](https://github.com/Homebrew/homebrew-core/commit/c8c9cc7e59562cca268a27368c8b9e182379df1b)

Apparently current libgccjit does not bundle are the required bin and lib files. Also this PR should unlock arm64 builds for libgccjit too.

But now I think of it, maybe the design of libgccjit Formula was to require both gcc and libgccjit installed in particular order and have libgccjit overlay binaries on top of what gcc installs.. So I might be fixing the wrong thing.

seanfarley commented 3 years ago

I have tried to fix homebrew-core's libgccjit formula issues a bit and drop dependency on gcc:

* [Homebrew/homebrew-core#67706](https://github.com/Homebrew/homebrew-core/pull/67706)

* [Homebrew/homebrew-core@c8c9cc7](https://github.com/Homebrew/homebrew-core/commit/c8c9cc7e59562cca268a27368c8b9e182379df1b)

Apparently current libgccjit does not bundle are the required bin and lib files. Also this PR should unlock arm64 builds for libgccjit too.

But now I think of it, maybe the design of libgccjit Formula was to require both gcc and libgccjit installed in particular order and have libgccjit overlay binaries on top of what gcc installs.. So I might be fixing the wrong thing.

No, the order doesn't matter at all. Also, you said in the PR:

I have also added caveats, as LIBRARY_PATH needs to be set on runtime for libgccjit to work.

Please, please, please, let's stop suggestioning that we need to set LIBRARY_PATH. First, try recompiling gcc and libgccjit from source (without setting any environment variables) and test that. Setting that environment is an anti-pattern on MacOS. As I've mentioned before, I suspect it's a cross-compiling error on Homebrew's part since the bottle isn't actually working but compiling from source does work, so that implies gcc is working correctly.

d12frosted commented 3 years ago

I agree with @seanfarley that there is no need to set LIBRARY_PATH. I tried installing gcc from bottle and libgccjit from sources and there is no need to modify anything anymore. No more missing dlibs! It just works 😸

The only thing that I encounter on a fresh install is some funky error related to seq library. The workaround is to start emacs with -Q option and wait for sometime until everything is compiled and then I can start Emacs normally. Also, in order to help myself bootstraping things, I've implemented this little function that I run in batch mode.

important note please read ALL the code before copying it and trying to launch it. It is unlikely that it will work unless you are using d12frosted/environment repo.

;; stored in $XDG_CONFIG_HOME/emacs/lisp/+native-comp.el
(defun +native-compile (dir)
  "Natively compile files in DIR."
  (add-hook 'comp-async-cu-done-hook
            (lambda (f)
              (message "done compiling %s" f)))
  (native-compile-async dir t)
  (while comp-files-queue
    (message "compiling %s files..." (length comp-files-queue))
    (sleep-for 2)))
# compile all built-in el files AOT - this is optional
cellar=$(brew --cellar emacs-plus@28)
version=$(brew info --json=v1 emacs-plus@28 | jq -r '.[0].installed[0].version')
built_in="${cellar}/${version}/share/emacs/${version}/lisp/"
emacs --batch \
  --load "$XDG_CONFIG_HOME/emacs/lisp/+native-comp.el" \
  --eval "(+native-compile \"$built_in\")"

# now I am installing all packages using straight.el - you can actually skip that
emacs --batch --load "$XDG_CONFIG_HOME/emacs/init.el" --eval '(+package-install)'

# now compile all my el files
emacs --batch \
  --load "$XDG_CONFIG_HOME/emacs/lisp/+native-comp.el" \
  --eval "(+native-compile \"$XDG_CONFIG_HOME/emacs/\")"
jimeh commented 3 years ago

@d12frosted just in case you didn't know, you can achieve full AOT of all built-in lisp files at build time by passing NATIVE_FULL_AOT=1 to make.

d12frosted commented 3 years ago

Oh cool. Didn't know. Thanks for the hint @jimeh

daviderestivo commented 3 years ago

I agree with @seanfarley that there is no need to set LIBRARY_PATH. I tried installing gcc from bottle and libgccjit from sources and there is no need to modify anything anymore. No more missing dlibs! It just works 😸

@d12frosted: Does this mean that this patch from @jimeh is not anymore required?

daviderestivo commented 3 years ago

Oh cool. Didn't know. Thanks for the hint @jimeh

@d12frosted: look at my formula ... I have included the full AoT option as well :)

d12frosted commented 3 years ago

@daviderestivo yep, that patch is actually not needed.

Oh cool, I will take a look.

daviderestivo commented 3 years ago

@daviderestivo yep, that patch is actually not needed.

Oh cool, I will take a look.

Then I'm gonna remove it.

d12frosted commented 3 years ago

Fixed CI (lol I just needed to remove unnecessary brew update). And mentioned this feature in README. :tada: