From fcbd467b085446e37eef8bc32280b58dc4d59c10 Mon Sep 17 00:00:00 2001 From: Jan Hohenheim Date: Thu, 4 Jul 2024 16:04:52 +0200 Subject: [PATCH 1/8] Add section for cranelift --- .../quick-start/getting-started/setup.md | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/content/learn/quick-start/getting-started/setup.md b/content/learn/quick-start/getting-started/setup.md index a21b56a2a1..d10232a7d9 100644 --- a/content/learn/quick-start/getting-started/setup.md +++ b/content/learn/quick-start/getting-started/setup.md @@ -246,6 +246,32 @@ channel = "nightly" For more information, see [The rustup book: Overrides](https://rust-lang.github.io/rustup/overrides.html#the-toolchain-file). +#### Cranelift + +This uses a new nightly-only codegen that is about 30% faster at compiling than LLM. + +To install cranelift on Linux or macOS, run the following. +``` +rustup component add rustc-codegen-cranelift-preview --toolchain nightly +``` + +To activate it for your project, add the following to your `.config/cargo.toml`. +```toml +[unstable] +codegen-backend = true + +[profile.dev] +codegen-backend = "cranelift" +``` + +See the [cranelift setup guide](https://github.com/rust-lang/rustc_codegen_cranelift?tab=readme-ov-file#download-using-rustup) for +details on other ways in which cranelift can be enabled. The installation process for Windows is a bit more involved. Consult the linked documentation for help. +Note that cranelift [currently does not build Bevy on macOS](https://github.com/rust-lang/rustc_codegen_cranelift/issues/1504). + + +While cranelift is very fast to compile, the generated binaries are not optimized for speed. Additionally, it is generally still immature, so you may run into issues with it. +When shipping your game, you should compile all dependencies with LLVM. + #### Generic Sharing Allows crates to share monomorphized generic code instead of duplicating it. From c00b0ac48fc18311c2fc4b30c1a5c68183300d78 Mon Sep 17 00:00:00 2001 From: Jan Hohenheim Date: Thu, 4 Jul 2024 16:44:13 +0200 Subject: [PATCH 2/8] Compile only top-level crate with cranelift Co-authored-by: BD103 <59022059+BD103@users.noreply.github.com> --- content/learn/quick-start/getting-started/setup.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/content/learn/quick-start/getting-started/setup.md b/content/learn/quick-start/getting-started/setup.md index d10232a7d9..28adbc3c92 100644 --- a/content/learn/quick-start/getting-started/setup.md +++ b/content/learn/quick-start/getting-started/setup.md @@ -260,11 +260,12 @@ To activate it for your project, add the following to your `.config/cargo.toml`. [unstable] codegen-backend = true -[profile.dev] +# Replace `my_program` with the name of your binary. +[profile.dev.package.my_program] codegen-backend = "cranelift" ``` -See the [cranelift setup guide](https://github.com/rust-lang/rustc_codegen_cranelift?tab=readme-ov-file#download-using-rustup) for +This enables faster compiles for your binary, but builds Bevy and other dependencies with the more-optimized LLVM backend. See the [cranelift setup guide](https://github.com/rust-lang/rustc_codegen_cranelift?tab=readme-ov-file#download-using-rustup) for details on other ways in which cranelift can be enabled. The installation process for Windows is a bit more involved. Consult the linked documentation for help. Note that cranelift [currently does not build Bevy on macOS](https://github.com/rust-lang/rustc_codegen_cranelift/issues/1504). From 5cd435cbacf425816af19cf3ffce63f1fd50d762 Mon Sep 17 00:00:00 2001 From: Jan Hohenheim Date: Thu, 4 Jul 2024 16:44:48 +0200 Subject: [PATCH 3/8] Change advice on shipping. --- content/learn/quick-start/getting-started/setup.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/learn/quick-start/getting-started/setup.md b/content/learn/quick-start/getting-started/setup.md index 28adbc3c92..8351950482 100644 --- a/content/learn/quick-start/getting-started/setup.md +++ b/content/learn/quick-start/getting-started/setup.md @@ -271,7 +271,7 @@ Note that cranelift [currently does not build Bevy on macOS](https://github.com/ While cranelift is very fast to compile, the generated binaries are not optimized for speed. Additionally, it is generally still immature, so you may run into issues with it. -When shipping your game, you should compile all dependencies with LLVM. +When shipping your game, you should still compile it with LLVM. #### Generic Sharing From ecf73d10d6a34e52d79619f58a2cc8af27508260 Mon Sep 17 00:00:00 2001 From: Jan Hohenheim Date: Thu, 4 Jul 2024 16:59:58 +0200 Subject: [PATCH 4/8] Make link more clear Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com> --- content/learn/quick-start/getting-started/setup.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/learn/quick-start/getting-started/setup.md b/content/learn/quick-start/getting-started/setup.md index 8351950482..9044ffb358 100644 --- a/content/learn/quick-start/getting-started/setup.md +++ b/content/learn/quick-start/getting-started/setup.md @@ -265,7 +265,7 @@ codegen-backend = true codegen-backend = "cranelift" ``` -This enables faster compiles for your binary, but builds Bevy and other dependencies with the more-optimized LLVM backend. See the [cranelift setup guide](https://github.com/rust-lang/rustc_codegen_cranelift?tab=readme-ov-file#download-using-rustup) for +This enables faster compiles for your binary, but builds Bevy and other dependencies with the more-optimized LLVM backend. See the [cranelift setup guide](https://github.com/rust-lang/rustc_codegen_cranelift#download-using-rustup) for details on other ways in which cranelift can be enabled. The installation process for Windows is a bit more involved. Consult the linked documentation for help. Note that cranelift [currently does not build Bevy on macOS](https://github.com/rust-lang/rustc_codegen_cranelift/issues/1504). From 5f9b4e6c7e3bec8fa631ad71a71abb14a94adbe2 Mon Sep 17 00:00:00 2001 From: Jan Hohenheim Date: Thu, 4 Jul 2024 17:00:53 +0200 Subject: [PATCH 5/8] Remove need for user to specify crate name --- content/learn/quick-start/getting-started/setup.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/content/learn/quick-start/getting-started/setup.md b/content/learn/quick-start/getting-started/setup.md index 9044ffb358..d876197b9a 100644 --- a/content/learn/quick-start/getting-started/setup.md +++ b/content/learn/quick-start/getting-started/setup.md @@ -260,9 +260,11 @@ To activate it for your project, add the following to your `.config/cargo.toml`. [unstable] codegen-backend = true -# Replace `my_program` with the name of your binary. -[profile.dev.package.my_program] +[profile.dev] codegen-backend = "cranelift" + +[profile.dev.package."*"] +codegen-backend = "llvm" ``` This enables faster compiles for your binary, but builds Bevy and other dependencies with the more-optimized LLVM backend. See the [cranelift setup guide](https://github.com/rust-lang/rustc_codegen_cranelift#download-using-rustup) for From bef3c031dc1fd67ad72154502e8a7a3d3c19f45a Mon Sep 17 00:00:00 2001 From: Jan Hohenheim Date: Thu, 4 Jul 2024 17:02:01 +0200 Subject: [PATCH 6/8] Remove note about macOS --- content/learn/quick-start/getting-started/setup.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/content/learn/quick-start/getting-started/setup.md b/content/learn/quick-start/getting-started/setup.md index d876197b9a..f7b822b9ec 100644 --- a/content/learn/quick-start/getting-started/setup.md +++ b/content/learn/quick-start/getting-started/setup.md @@ -269,8 +269,6 @@ codegen-backend = "llvm" This enables faster compiles for your binary, but builds Bevy and other dependencies with the more-optimized LLVM backend. See the [cranelift setup guide](https://github.com/rust-lang/rustc_codegen_cranelift#download-using-rustup) for details on other ways in which cranelift can be enabled. The installation process for Windows is a bit more involved. Consult the linked documentation for help. -Note that cranelift [currently does not build Bevy on macOS](https://github.com/rust-lang/rustc_codegen_cranelift/issues/1504). - While cranelift is very fast to compile, the generated binaries are not optimized for speed. Additionally, it is generally still immature, so you may run into issues with it. When shipping your game, you should still compile it with LLVM. From aca277a113994d7137df750475eee1d983059383 Mon Sep 17 00:00:00 2001 From: Jan Hohenheim Date: Thu, 4 Jul 2024 17:23:30 +0200 Subject: [PATCH 7/8] Add disclaimer for Wasm --- content/learn/quick-start/getting-started/setup.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/content/learn/quick-start/getting-started/setup.md b/content/learn/quick-start/getting-started/setup.md index f7b822b9ec..76d02ce637 100644 --- a/content/learn/quick-start/getting-started/setup.md +++ b/content/learn/quick-start/getting-started/setup.md @@ -270,7 +270,9 @@ codegen-backend = "llvm" This enables faster compiles for your binary, but builds Bevy and other dependencies with the more-optimized LLVM backend. See the [cranelift setup guide](https://github.com/rust-lang/rustc_codegen_cranelift#download-using-rustup) for details on other ways in which cranelift can be enabled. The installation process for Windows is a bit more involved. Consult the linked documentation for help. -While cranelift is very fast to compile, the generated binaries are not optimized for speed. Additionally, it is generally still immature, so you may run into issues with it. +While cranelift is very fast to compile, the generated binaries are not optimized for speed. Additionally, it is generally still immature, so you may run into issues with it. +Notably, Wasm builds do not work yet. + When shipping your game, you should still compile it with LLVM. #### Generic Sharing From dcbc3c12ad512840d457e489dea1a1b3c4b1c910 Mon Sep 17 00:00:00 2001 From: Jan Hohenheim Date: Sun, 7 Jul 2024 20:03:21 +0200 Subject: [PATCH 8/8] Recommend cranelift only for Linux --- content/learn/quick-start/getting-started/setup.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/content/learn/quick-start/getting-started/setup.md b/content/learn/quick-start/getting-started/setup.md index cfe71a36ba..176fb25dd3 100644 --- a/content/learn/quick-start/getting-started/setup.md +++ b/content/learn/quick-start/getting-started/setup.md @@ -249,8 +249,9 @@ For more information, see [The rustup book: Overrides](https://rust-lang.github. #### Cranelift This uses a new nightly-only codegen that is about 30% faster at compiling than LLM. +It currently works best on Linux. -To install cranelift on Linux or macOS, run the following. +To install cranelift, run the following. ``` rustup component add rustc-codegen-cranelift-preview --toolchain nightly ``` @@ -269,6 +270,7 @@ codegen-backend = "llvm" This enables faster compiles for your binary, but builds Bevy and other dependencies with the more-optimized LLVM backend. See the [cranelift setup guide](https://github.com/rust-lang/rustc_codegen_cranelift#download-using-rustup) for details on other ways in which cranelift can be enabled. The installation process for Windows is a bit more involved. Consult the linked documentation for help. +MacOS builds can currently crash on Bevy applications, so you should still wait a bit before using cranelift on that system. While cranelift is very fast to compile, the generated binaries are not optimized for speed. Additionally, it is generally still immature, so you may run into issues with it. Notably, Wasm builds do not work yet.