有两种方式来在 macOS 编译 Emacs:
- d12frosted/homebrew-emacs-plus - Homebrew formula,适合日常使用
- jimeh/build-emacs-for-macos - 从源码构建,更灵活
IGC (Incremental Garbage Collector) 是 Emacs 的增量垃圾回收器,基于 Ravenbrook MPS 实现。相比传统的 stop-the-world GC,IGC 可以显著减少垃圾回收时的停顿时间,提升编辑器响应性。
目前 IGC 处于实验阶段,在 feature/igc3 分支开发。
构建环境:
| 项目 | 版本 |
|---|---|
| macOS | 15.7.3 (Build 24G419) |
| Xcode | 26.3 (Build 17C529) |
| Ruby | 3.3.4 (arm64-darwin23) |
| Go | 1.26.1 darwin/arm64 |
| build-emacs-for-macos | 支持 --igc 选项 |
构建命令:
# 克隆仓库
git clone https://github.com/jimeh/build-emacs-for-macos.git
cd build-emacs-for-macos
# 构建 IGC 分支(需要先安装依赖)
./build-emacs-for-macos --igc feature/igc3快速方案 :如果遇到上述 macOS API 可用性问题,可以直接使用已修复的分支:
git clone https://github.com/nailuoGG/build-emacs-for-macos.git
cd build-emacs-for-macos
git checkout feat/add-igc-support
./build-emacs-for-macos --igc feature/igc3遇到的坑:
configure 选项名称 :Emacs 使用
--with-mps而非--with-igc=,可通过检查 =configure.ac确认。macOS API 可用性 :在 macOS 15 上构建时遇到
Abort trap: 6错误。原因是posix_spawn_file_actions_addchdir函数仅在 macOS 26+ 可用,但编译时只有警告没有错误。
解决方案是创建 patch 文件 =fix_build.patch=:
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -1368,9 +1368,15 @@
/* Haiku appears to have linkable posix_spawn_file_actions_chdir,
but it always fails. So use the _np function instead. */
-#if defined HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR && !defined HAIKU
- error = posix_spawn_file_actions_addchdir (actions, cwd);
-#else
- error = posix_spawn_file_actions_addchdir_np (actions, cwd);
-#endif
+#if defined HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR && !defined HAIKU && defined(__APPLE__)
+ if (__builtin_available(macOS 26.0, *))
+ error = posix_spawn_file_actions_addchdir (actions, cwd);
+ else
+ error = posix_spawn_file_actions_addchdir_np (actions, cwd);
+#elif defined HAVE_POSIX_SPAWN_FILE_ACTIONS_ADDCHDIR && !defined HAIKU
+ error = posix_spawn_file_actions_addchdir (actions, cwd);
+#else
+ error = posix_spawn_file_actions_addchdir_np (actions, cwd);
+#endif
if (error != 0)
goto out;
然后使用 --patch 选项应用:
./build-emacs-for-macos --igc --patch=fix_build.patch feature/igc3- 缺少依赖 :打包阶段可能提示找不到 =libexpat.1.dylib=,需要安装:
brew install expat验证构建结果:
grep "incremental GC" builds/Emacs.*/configure_output.txt预期输出:
Does Emacs use incremental GC with MPS? yes经验总结:
- 添加新功能前,先检查目标项目的
configure.ac文件确认选项名称 - 不要只看编译成功,要检查 configure 输出确认功能已启用
Abort trap: 6通常是动态链接问题的标志,即使编译通过也可能运行时失败