12
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Rust のコンパイルを爆速にしよう (nightly で LLD か zld を使ってリンクする)

Last updated at Posted at 2020-12-19

まとめ

  1. Linker を替える と良いようです (『Enable Fast Compiles (Optional) 』) 。 5 倍ほど速くコンパイルできるようになりました。
  2. 依存クレートが遅くなる場合は、 opt-level を設定します。 imageなどで顕著でした。
  3. さらに sccache も導入します。複数のプロジェクトでクレートのキャッシュを共有できます。

Linker を変える

Bevy - Setup からのコピペです。

2020/12/19 にコピペしたのですが、古くなっていたらごめんなさい。

LLD or zld のインストール

# ubuntu
sudo apt-get install lld
# arch
sudo pacman -S lld

# macOS
brew install michaeleisel/zld/zld
# windows
cargo install -f cargo-binutils
rustup component add llvm-tools-preview

nightly rust の有効化

rustup toolchain install nightly

# use nightly rust for this project
# rustup override set nightly
# or everywhere
rustup default nightly

.cargo/config.toml の作成

プロジェクト毎に config.toml を設定する場合:

cd your/project/root

mkdir .cargo
curl 'https://raw.githubusercontent.com/bevyengine/bevy/master/.cargo/config_fast_builds' > .cargo/config.toml

グローバルな Cargo.toml を作る場合:

mkdir ~/.cargo
curl 'https://raw.githubusercontent.com/bevyengine/bevy/master/.cargo/config_fast_builds' > ~/.cargo/config.toml

.cargo/Cargo.toml への修正

『image クレートによる画像のロードが極端に遅くなった』

.cargo/config.toml から最適化レベルを設定できます。やり過ぎな気もしますが、たとえば opt-level = 3 にするには:

[profile.dev.package."image"]
opt-level = 3

# [profile.dev.package."*"]
# opt-level = 3

最適化レベルを上げ過ぎると、初回のコンパイルは遅くなります。

sccache

sccache も導入します。複数のプロジェクトでクレートのキャッシュを共有できます。

参考: コンパイルキャッシュでRustのビルド時間を短縮しよう

12
3
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
12
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?