分享一下MacOS下编译Emacs 28 native-comp分支

看到了 native-comp branch option · Issue #187 · d12frosted/homebrew-emacs-plus · GitHub

不过目前好像还编译不过,而且 @AndreaCorallo 不用 Mac,他也没法提供直接的帮助。如果 Nix 搞定,所有平台的编译都不成问题了。

也是。有必要让作者看看这个帖子,哈哈哈 :joy: :joy: :joy:

guix 也可以,和nix有类似的包管理机制

1 个赞

看了一下,guix 是基于的 nix 的,但是语法更对 Emacs 用户的胃口。

gcc通过brew edit gcc 编译成功了

编译emacs的时候卡在了这步,有遇到过的吗, 怎么解决

more info see INSTALL.REPO when compile error
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C lib all
make[3]: Nothing to be done for `all'.
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C lib-src all
make[3]: Nothing to be done for `all'.
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C src VCSWITNESS='$(srcdir)/../.git/logs/HEAD' all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C ../admin/charsets all
make[4]: Nothing to be done for `all'.
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C ../admin/unidata charscript.el
make[4]: Nothing to be done for `charscript.el'.
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C ../lisp autoloads EMACS="../src/bootstrap-emacs"
  ELC      international/titdic-cnv.elc
/bin/sh: line 1: 19409 Bus error: 10           EMACSLOADPATH= '../src/bootstrap-emacs' -batch --no-site-file --no-site-lisp --eval '(setq load-prefer-newer t)' -f batch-byte-compile international/titdic-cnv.el
make[4]: *** [international/titdic-cnv.elc] Error 138
make[3]: *** [../lisp/loaddefs.el] Error 2
make[2]: *** [src] Error 2
script aborted, because of errors

这也有个比较详细的 macOS 下编译的帖子:

company的后端应该是有company-keywords把?

我遇到了差不多的问题, 你解决了吗

编译emacs的时候报错如下:

    Dumping under the name bootstrap-emacs.pdmp
    dumping fingerprint: 4692c305281b0001e75e3f18eb7d4a4adc2c3dc2a8a9178c147310e0d5103377
    Dump complete
    Byte counts: header=96 hot=13741848 discardable=122496 cold=9502408
    Reloc counts: hot=959245 discardable=6049
    /Applications/Xcode.app/Contents/Developer/usr/bin/make -C ../lisp compile-first EMACS="../src/bootstrap-emacs"
      ELC      emacs-lisp/macroexp.elc
      ELC      emacs-lisp/cconv.elc
      ELC      emacs-lisp/byte-opt.elc
      ELC      emacs-lisp/bytecomp.elc
    /bin/sh: line 1: 13633 Bus error: 10           EMACSLOADPATH= '../src/bootstrap-emacs' -batch --no-site-file --no-site-lisp --eval '(setq load-prefer-newer t)' -f batch-byte-compile emacs-lisp/bytecomp.el
    make[3]: *** [emacs-lisp/bytecomp.elc] Error 138
    make[3]: *** Waiting for unfinished jobs....
    /bin/sh: line 1: 13632 Bus error: 10           EMACSLOADPATH= '../src/bootstrap-emacs' -batch --no-site-file --no-site-lisp --eval '(setq load-prefer-newer t)' -f batch-byte-compile emacs-lisp/byte-opt.el
    make[3]: *** [emacs-lisp/byte-opt.elc] Error 138
    /bin/sh: line 1: 13631 Bus error: 10           EMACSLOADPATH= '../src/bootstrap-emacs' -batch --no-site-file --no-site-lisp --eval '(setq load-prefer-newer t)' -f batch-byte-compile emacs-lisp/cconv.el
    make[3]: *** [emacs-lisp/cconv.elc] Error 138
    /bin/sh: line 1: 13630 Bus error: 10           EMACSLOADPATH= '../src/bootstrap-emacs' -batch --no-site-file --no-site-lisp --eval '(setq load-prefer-newer t)' -f batch-byte-compile emacs-lisp/macroexp.el
    make[3]: *** [emacs-lisp/macroexp.elc] Error 138
    make[2]: *** [bootstrap-emacs.pdmp] Error 2
    make[1]: *** [src] Error 2
    make: *** [default] Error 2

编译用的脚本:

    export CC="clang"

    export CFLAGS="${CFLAGS}-I/usr/local/Cellar/gcc/9.2.0_3/include"

    export CPPFLAGS="${CFLAGS}"

    export LDFLAGS="${LDFLAGS}-L/usr/local/Cellar/gcc/9.2.0_3/lib"

    export LIBXML2_CFLAGS=`xml2-config --cflags`

    export LIBXML2_LIBS=`xml2-config --libs`

    ./autogen.sh

    ./configure \
      --prefix="${HOME}"/gccemacs \
      --with-nativecomp 

    make -j4

这是什么问题?

LDFLAGS 改成 /usr/local/Cellar/gcc/9.2.0_3/lib/gcc/9 试试?

谢谢你的回复, 我刚试了, 没有用. 我觉得和gcc已经无关了, 这应该是emacs本身的源码的问题;

请问一下, 你用的emacs feature/native-comp 的commit id是多少

commit ab8fed0a96a55107895e6105e7b0e4b6735156d7 (HEAD -> feature/native-comp, origin/feature/native-comp)

Author: Andrea Corallo [email protected] Date: Thu Mar 12 22:36:39 2020 +0000

* Do not produce .eln files when a byte compilation error happen

Have the byte compiler signal an error when compilation fails to stop
native compilation too.

目前还在尝试中 ,主要是编译太慢, 还没看出成果, 从现有的输出来看 似乎有 Segmentation fault,但是还没有结束 处于Waiting for unfinished jobs… 中 ,对make 不熟, 不知道这算不算异常 正在等待

javat-wy.el" java-tags.wy
  INFO     Scraping files for cal-loaddefs.el...
  INFO     Scraping files for mh-loaddefs.el...
Loading macroexp.elc...
Fatal error 11: Segmentation fault
Loading macroexp.elc...
Fatal error 11: Segmentation fault
  INFO     Scraping files for tramp-loaddefs.el...
Loading macroexp.elc...
car-safe:0:0: error: wrong-type-argument: (stringp car-safe)
make[6]: *** [net/tramp-loaddefs.el] Error 255
make[6]: *** Waiting for unfinished jobs....
[ ! -f "../../lisp/cedet/semantic/wisent/js-wy.el" ] || chmod +w "../../lisp/cedet/semantic/wisent/js-wy.el"
EMACSLOADPATH= "../../src/bootstrap-emacs" -batch --no-site-file --no-site-lisp -l semantic/wisent/grammar -f wisent-batch-make-parser -o "../../lisp/cedet/semantic/wisent/js-wy.el" js.wy
[ ! -f "../../lisp/cedet/semantic/wisent/python-wy.el" ] || chmod +w "../../lisp/cedet/semantic/wisent/python-wy.el"
EMACSLOADPATH= "../../src/bootstrap-emacs" -batch --no-site-file --no-site-lisp -l semantic/wisent/grammar -f wisent-batch-make-parser -o "../../lisp/cedet/semantic/wisent/python-wy.el" python.wy
[ ! -f "../../lisp/cedet/srecode/srt-wy.el" ] || chmod +w "../../lisp/cedet/srecode/srt-wy.el"
EMACSLOADPATH= "../../src/bootstrap-emacs" -batch --no-site-file --no-site-lisp -l semantic/wisent/grammar -f wisent-batch-make-parser -o "../../lisp/cedet/srecode/srt-wy.el" srecode-template.wy

这是我用的编译脚本。

另外也分享下 brew 编译gcc9.3 的脚本与补丁

https://github.com/jixiuf/vmacs/blob/master/bin/build-gcc.sh#L1

https://github.com/jixiuf/vmacs/blob/master/bin/gcc9.3.patch#L1

后端都是默认的,没改动过

咨询一个问题,你编译成功的native-comp 版本 只是终端下的吗? 图形界面下能用吗。

我的编译脚本和你的基本没差别, 我现在用的emacs commit id是 “16ec5f5f2ffd9e114262b0a3a717b772ee0350ae”, 我直接用feature/native-comp 就会出现segmentation fault. 但是我用 16ec5f5f2ffd9e114262b0a3a717b772ee0350ae 这个源码编译出来的emacs打开之后没有 native-comp-async这个函数, 而且也没有生成eln文件, 虽然编译没报错, 但还是感觉没成功

图形界面也可以用

你们是Mojave还是Catalina,可能Catalina下很多软件会出问题,我是Mojave

@CapsuleEXY 在我这里,使用脚本编译在 ELC+ELN 时会出现Segmentation fault. 但用 ./configure --with-nativecom LDFLAGS=... && make -j4 编译就很顺利。

我是mojave.

我如果用CC="clang"编译, 就会出现这种error:

In file included from regex.c:70:
./regex_internal.h:178:9: error: unknown type name '__re_size_t'
typedef __re_size_t re_hashval_t

        ^
./regex_internal.h:399:3: error: unknown type name 'RE_TRANSLATE_TYPE'
  RE_TRANSLATE_TYPE trans;
  ^
./regex_internal.h:684:3: error: unknown type name 'reg_syntax_t'
  reg_syntax_t syntax;
  ^
In file included from regex.c:72:
./regex_internal.c:22:6: error: unknown type name 'RE_TRANSLATE_TYPE'
                                        RE_TRANSLATE_TYPE trans, bool icase,
                                        ^
./regex_internal.c:31:8: error: unknown type name 'reg_errcode_t'
static reg_errcode_t re_string_realloc_buffers (re_string_t *pstr,
       ^
./regex_internal.c:47:8: error: unknown type name 'reg_errcode_t'
static reg_errcode_t
       ^
./regex_internal.c:48:1: error: expected identifier or '('
__attribute_warn_unused_result__

fatal error: too many errors emitted, stopping now [-ferror-limit=]
190 warnings and 20 errors generated.
make[2]: *** [regex.o] Error 1
make[1]: *** [lib] Error 2
make: *** [bootstrap] Error 2

如果用CC=”gcc“编译, 就会出现: missing “gdk/gdkx.h” . 这应该可以解决, 但我还是倾向于用clang编译, gcc编译只能 --without-ns

你clang编译没有出问题吗? 另外请问一下emacs的源码你用的commit id