LoginSignup
1
0

native compile 対応の Emacs を Mac へ install する

Last updated at Posted at 2024-05-06

目的

native compile とは

  • elisp を gcc を用いてコンパイルし, 最適化したバイナリを生成する
  • このバイナリを用いると2.5 ~ 5倍ほど高速になる
  • native compile を使用するには,
    • Emacs ビルド時に libgccjit などと共に build する必要がある
    • また, gcc ginutils などが install されている必要がある

環境

  • m1 及び intel mac

how to install

dependencies

brew install gcc glib libgccjit gnutls jansson librsvg tree-sitter

// 環境が汚れていたので不要なものもあるかもしれない

install

brew tap d12frosted/emacs-plus
brew install emacs-plus \
    --with-ctags \
    --with-native-comp \
    --with-poll \
    --with-imagemagick

// option は末尾の参考サイトからお好みで
// --with-debug は指定すると重くなる.

copy app to Application dir

cp -r /usr/local/opt/emacs-plus\@29/Emacs.app /Applications/

// 環境によって install 先が異なる可能性があるため場所を確認されたし

native compile の確認と実行

emacs 起動

Application dir から通常の app と同様に起動

native compile が有効か確認

lisp-interaction-mode にて以下を実行.
NATIVE_COMP が含まれていれば有効.

(describe-variable 'system-configuration-features)
#("system-configuration-features is a variable defined in ‘C source code’.

Its value is
\"ACL GIF GLIB GMP GNUTLS IMAGEMAGICK JPEG JSON LCMS2 LIBXML2 MODULES NATIVE_COMP NOTIFY KQUEUE NS PDUMPER PNG RSVG SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER WEBP XIM ZLIB\"

native compile for elpa packages

通常は必要な package が読み込まれた際に, 非同期で compile される模様.
意図的に一括で compile する場合は以下.
directory 指定で dir再帰でまとめて compile される

(native-compile-async "~/.emacs.d/elpa/" t t)

// spec によってはだいぶ時間を要する
// 通常は, cpu の半数を使用し並列処理する模様

compile 後

以下 dir などに eln file として保存される

~/.emacs.d/eln-cache/[each version dir]

補足

eln と elc は不可分な様子.

native-compile関数により単一の関数やマクロ、あるいはLispコードのファイル全体をネイティブコンパイルできます。ファイルをネイティブコンパイルすると、それに対応するバイトコードの.elcファイルと、ネイティブコードの.elnファイルの両方が生成されます。

参考サイト

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0