Mac OS X 上に rustfmt を install しようとした際にコンパイルエラーが発生する問題の回避法

要約

Mac OS X にて,homebrew を使って rust をインストールしていると,cargo install rustfmt を実行した際に失敗する. これは,homebrew 経由でインストールした rust コンパイラが,予期せぬ LC_ID_DYLIB の値を渡されるために発生する. この問題の回避方法は,homebrew 経由でインストールした rust を一旦アンインストールし,rustup 経由で rust をインストールした上で,cargo install rustfmtを実行し直すことである(2017/6/4現在).

経緯

rustfmt があることを知って,早速インストールしようとしたら失敗した.

$ rust install rustfmt
...(中略)...
   Compiling env_logger v0.4.3
error: proc-macro derive panicked
   --> /Users/ozawa/.cargo/registry/src/github.com-1ecc6299db9ec823/rustfmt-0.8.4/src/config.rs:213:18
    |
213 |         #[derive(Deserialize, Clone)]
    |                  ^^^^^^^^^^^
...
329 | create_config! {
    | - in this macro invocation
    |
    = help: message: proc_macro::__internal::with_parse_sess() called before set_parse_sess()!

error: failed to compile `rustfmt v0.8.4`, intermediate artifacts can be found at `/var/folders/59/5_yyjdc92zzfjsvrhz46x2mc0000gn/T/cargo-install.EsADzsGoPlu6`

コンパイルエラーの内容で検索をしたところ以下の github issue を発見. github.com

github.com

上記コメントを見て,rustup 経由で rust の再インストールを行うことで,正常に動作させることができた:

$ cargo install rustfmt
...(中略)...
   Compiling env_logger v0.4.3
    Finished release [optimized] target(s) in 269.78 secs
  Installing /Users/ozawa/.cargo/bin/cargo-fmt
  Installing /Users/ozawa/.cargo/bin/rustfmt