Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added section on cranelift codegen #801

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions content/learn/book/getting-started/setup/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ Bevy can be built just fine using default configuration on stable Rust. However

For more information, see [The rustup book: Overrides](https://rust-lang.github.io/rustup/overrides.html#the-toolchain-file).

* **Cranelift Codegen**: This uses a new nightly-only codegen that can be 300% faster than LLVM! However it only currently works on Linux and is generally still immature.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

30% is a more realistic average.

It works fine on Windows now and x86_64 macOS (arm64 macOS has some ABI issues)

Copy link
Member

@janhohenheim janhohenheim Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could not get Bevy compiling on (intel) macOS with cranelift enabled. Specifically objc2 failed to build.
Windows works, but the installation process is a bit whackier and it may not play nice with sccache.
After my little investigation, it seems like the only platform where everything runs smoothly out of the box is still Linux.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! I'll post one tomorrow :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: there you go rust-lang/rustc_codegen_cranelift#1504
Let me know in that issue if there's anything I can try out to help debug it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

[Cranelift codegen setup](https://bjorn3.github.io/2023/10/31/progress-report-oct-2023.html).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe link to the setup section of the readme instead? Unlike this page it will be kept up to date if the setup changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it is possible to compile all dependencies with the LLVM backend and optimizations, but the main game crate with Cranelift to get much better runtime performance.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bjorn3 I've tried that before and ran into issues where I would get random segfaults.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were some abi incompatibilities in the past, but most should be fixed now.


* **Generic Sharing**: Allows crates to share monomorphized generic code instead of duplicating it. In some cases this allows us to "precompile" generic code so it doesn't affect iterative compiles. This is only available on nightly Rust.

To enable fast compiles, install the nightly rust compiler and LLD. Then copy the contents of [this file](https://github.com/bevyengine/bevy/blob/main/.cargo/config_fast_builds) to `YOUR_WORKSPACE/.cargo/config.toml`. For the project in this guide, that would be `my_bevy_game/.cargo/config.toml`.
Expand Down