0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Bevyセットアップ(Hello WorldのコンパイルまでBevyはまだ使わない)

Posted at

実施した作業

Hello WorldのコンパイルまでBevyはまだ使わない

参考URL

プロジェクト作成とBevyの追加

プロジェクトを作る

cargo new bevy_project1
cd bevy_project1

BevyのDependencyを追加する

cargo add bevy

コンパイルオプションの調整

デバッグビルドの最適化オプションを推奨設定に合わせる

Gargo.toml
# Enable a small amount of optimization in the dev profile.
[profile.dev]
opt-level = 1

# Enable a large amount of optimization in the dev profile for dependencies.
[profile.dev.package."*"]
opt-level = 3

この状態からのHello Worldのコンパイル時間は約30分
コンパイル後のファイル・フォルダサイズは以下の通り

  • 実行ファイル(bevy_project1.exe): 134KB
  • プロジェクトフォルダ: 4.41GB
実行ファイル

image.png

プロジェクトフォルダ

image.png

Hello, Worldの文字列を変えて再コンパイルにかかる時間は2秒程度

【参考】リリース用の設定など

wasmに最適化するためのコンパイルオプション

wasm-opt -Os --output output.wasm input.wasm

リリースビルド用のCargo.toml設定

Cargo.toml
Cargo.toml
# Enable more optimization in the release profile at the cost of compile time.
[profile.release]
# Compile the entire crate as one unit.
# Slows compile times, marginal improvements.
codegen-units = 1
# Do a second optimization pass over the entire program, including dependencies.
# Slows compile times, marginal improvements.
lto = "thin"

# Optimize for size in the wasm-release profile to reduce load times and bandwidth usage on web.
[profile.wasm-release]
# Default to release profile values.
inherits = "release"
# Optimize with size in mind (also try "z", sometimes it is better).
# Slightly slows compile times, great improvements to file size and runtime performance.
opt-level = "s"
# Strip all debugging information from the binary to slightly reduce file size.
strip = "debuginfo"

繰り返しコンパイル時間を短縮するための設定についてのメモ

ダイナミックリンク

実行時に次のオプション(ダイナミックリンク)を入れると早くなるらしい
cargo run --features bevy/dynamic_linking

次のコマンドを実行しておくと自動的にオプションを付けてくれるようになる
cargo add bevy -F dynamic_linking

ゲーム公開時にはダイナミックリンクのオプションを外すことをお勧めされている

Shipping your game with dynamic linking enabled is not recommended because it requires you to include libbevy_dylib alongside your game, it prevents certain optimizations, and can increase the size of your game. If you remove the dynamic_linking feature, your game executable can run standalone.

  • リンカをLLDに変える
  • Nightly Rust Compiler
  • Cranelift
  • Generic Sharing
  • Improve Runtime Performance (Optional)
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?