🪤

tectonicクレートを使う時に引っかかったこと

に公開

Rustでtectonicを使おうとしたら,依存関係と環境変数の問題でずっとstuckしたので,次使う時に忘れないようメモをしておきます.

環境

  • MacBook Air (2020) / macOS Tahoe 26.0
  • rustc 1.89.0
  • cargo 1.89.0
  • tectonic 0.15.0
  • Homebrew 4.6.11

問題

以下のドキュメントに沿って依存関係をHomebrewで導入したが,コンパイル時にharfbuzzicu4cを見つけられず,コンパイルエラーになる

(中略)
The system library `icu-uc` required by crate `tectonic_bridge_icu` was not found.
  The file `icu-uc.pc` needs to be installed and the PKG_CONFIG_PATH environment variable must contain its parent directory.
  The PKG_CONFIG_PATH environment variable is not set.

  HINT: if you have installed the library, try setting PKG_CONFIG_PATH to the directory containing `icu-uc.pc`.
(中略)
  cargo:warning=layout/tectonic_xetex_layout.h:42:10: fatal error: 'harfbuzz/hb.h' file not found
  cargo:warning=   42 | #include <harfbuzz/hb.h>
  cargo:warning=      |          ^~~~~~~~~~~~~~~
  cargo:warning=1 error generated.

  --- stderr

https://tectonic-typesetting.github.io/book/latest/howto/build-tectonic/

解決

icu4cに関して,Homebrewでインストールしたライブラリは,デフォルトパスにはないため,Homebrewを使わず導入するか,環境変数でCFLAGSCXXFLAGSをそれぞれ指定しなければならないようです.
harfbuzzも同様の理由で,場所を別途環境変数で指定する必要があります.

CFLAGS="-I/opt/homebrew/opt/harfbuzz/include -I/opt/homebrew/opt/icu4c/include"
CXXFLAGS="-I/opt/homebrew/opt/harfbuzz/include -I/opt/homebrew/opt/icu4c/include -std=c++17"
PKG_CONFIG_PATH="/opt/homebrew/opt/harfbuzz/lib/pkgconfig:/opt/homebrew/opt/icu4c/lib/pkgconfig"

追加情報

tectonicを使う時,Cargo.tomlfeatures = "geturl-curl"を指定すると,コンパイル時に必要なパッケージ,フォントをWebから自動でダウンロードしてくれるようです.

まとめ

初投稿なのと,Rustはそこまで詳しくはないため,間違いや改善点などがあればコメントしていただけると幸いです.

参考資料・公式ドキュメント

https://tectonic-typesetting.github.io/book/latest/howto/build-tectonic/
https://crates.io/crates/tectonic/0.15.0https://crates.io/crates/tectonic/0.15.0
https://docs.rs/tectonic/0.15.0/tectonic/
https://www.reddit.com/r/rust/comments/1gffqo3/new_in_rust_i_facing_some_issue_while_setup/?tl=ja
https://github.com/tectonic-typesetting/tectonic/issues/1178

Discussion