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

Updated 'Enable Fast Compiles' section #137

Closed
wants to merge 30 commits into from
Closed
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
56f519a
Add user-facing explanation to CONTRIBUTING.md
alice-i-cecile May 24, 2021
fd6e055
Revised guidance on state of docs
alice-i-cecile May 24, 2021
6efe94b
Removed old book content
alice-i-cecile May 24, 2021
acbbd61
Fixed redirect
alice-i-cecile May 24, 2021
7abb5e1
Cleaned up heading levels
alice-i-cecile May 24, 2021
ce9866f
Stubs for Welcome chapter
alice-i-cecile May 24, 2021
d6057fa
Stubs for ECS chapter
alice-i-cecile May 24, 2021
7a12cd0
Misc cleanup
alice-i-cecile May 24, 2021
09245a7
Stubs for Game Logic chapter
alice-i-cecile May 24, 2021
38981b9
Stubs for Graphics chapter
alice-i-cecile May 25, 2021
ef6756e
Stubs for Assets chapter
alice-i-cecile May 25, 2021
34c4ad0
Stubs for Input chapter
alice-i-cecile May 25, 2021
a20ec71
Stubs for Audio chapter
alice-i-cecile May 25, 2021
b903100
Stubs for UI chapter
alice-i-cecile May 25, 2021
f110421
Stubs for Development Practices chapter
alice-i-cecile May 25, 2021
8caef4b
Stubs for Performance Optimizations chapter
alice-i-cecile May 25, 2021
6ffb8d0
Added note on query.get
alice-i-cecile May 25, 2021
8a42bcb
More content for Bevy community page
alice-i-cecile May 25, 2021
6468ac7
Stub for Platforms chapter
alice-i-cecile May 25, 2021
a25891e
Added old troubleshooting section to Getting Started
alice-i-cecile May 25, 2021
dcf361e
Grabbed setup instructions from book
alice-i-cecile May 25, 2021
b443089
Port and refresh of Next Steps chapter
alice-i-cecile May 25, 2021
35690c4
Added note on system chaining for error handling
alice-i-cecile May 25, 2021
1f31009
Fix typo
alice-i-cecile May 29, 2021
0a58839
Improved fast compiles section
lukors May 29, 2021
252325d
Book structure (#154)
alice-i-cecile Jun 2, 2021
ff22c12
Merge branch 'new-book' into patch-1
lukors Jun 3, 2021
c34029a
Merge remote-tracking branch 'upstream/new-book' into patch-1
lukors Sep 7, 2021
46aad34
Fixed typo: "mmand" to "command"
lukors Oct 13, 2021
3634c72
Clarified use of `+nightly`
lukors Oct 13, 2021
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
85 changes: 44 additions & 41 deletions content/learn/book/development-practices/fast-compiles/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,47 @@ page_template = "book-section.html"

TODO: explain why you might want faster compiles

* **Enable Bevy's Dynamic Linking Feature**: This is the most impactful compilation time decrease! If `bevy` is a dependency you can compile the binary with the "dynamic" feature flag (enables dynamic linking):

```sh
cargo run --features bevy/dynamic
```

If you don't want to add the `--features bevy/dynamic` to each run, this flag can permanently be set via `Cargo.toml`:

```toml
[dependencies]
bevy = { version = "0.5.0", features = ["dynamic"] }
```

NOTE: Remember to revert this before releasing your game! Otherwise you will need to include `libbevy_dylib` alongside your game if you want it to run. If you remove the "dynamic" feature, your game executable can run standalone.

* **LLD linker**: The Rust compiler spends a lot of time in the "link" step. LLD is _much faster_ at linking than the default Rust linker. To install LLD, find your OS below and run the given command:
* **Ubuntu**: `sudo apt-get install lld`
* **Arch**: `sudo pacman -S lld`
* **Windows**: Ensure you have the latest [cargo-binutils](https://github.com/rust-embedded/cargo-binutils)

```sh
cargo install -f cargo-binutils
rustup component add llvm-tools-preview
```

* **MacOS**: Modern LLD does not yet support MacOS, but we can use zld instead: `brew install michaeleisel/zld/zld`
* **Nightly Rust Compiler**: This gives access to the latest performance improvements and "unstable" optimizations

```sh
# Install the nightly toolchain
rustup toolchain install nightly
# Configure your current project to use nightly (run this command within the project)
rustup override set nightly
# OR configure cargo to use nightly for all projects -- switch back with `rustup default stable`
rustup default nightly
```

* You can use `cargo +nightly ...` if you don't want to change the default to nightly.
* **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 [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`.
* **Bevy's Dynamic Linking Feature**: This is the most impactful iterative compilation time decrease! It requires no special setup except on Windows, where you also have to follow the three numbered steps below for it to work. If `bevy` is a dependency you can compile the binary with the `dynamic` feature flag (enables dynamic linking):

```sh
cargo run --features bevy/dynamic
```

If you don't want to add the `--features bevy/dynamic` to each run, this flag can permanently be set via `Cargo.toml`:

```toml
[dependencies]
bevy = { version = "0.5.0", features = ["dynamic"] }
```

NOTE: Remember to revert this before releasing your game! Otherwise you will need to include `libbevy_dylib` alongside your game if you want it to run. If you remove the `dynamic` feature, your game executable can run standalone.

For the fastest iterative compile times, we recommend the following configuration as well. You need to follow all three steps for any effect:

1. **LLD linker**: The Rust compiler spends a lot of time in the "link" step. LLD is _much faster_ at linking than the default Rust linker. To install LLD, find your OS below and run the given command:
* **Ubuntu**: `sudo apt-get install lld clang`
* **Arch**: `sudo pacman -S lld`
* **Windows**: Ensure you have the latest [cargo-binutils](https://github.com/rust-embedded/cargo-binutils)

```sh
cargo install -f cargo-binutils
rustup component add llvm-tools-preview
```

* **MacOS**: Modern LLD does not yet support MacOS, but we can use zld instead: `brew install michaeleisel/zld/zld`
2. **Nightly Rust Compiler**: This gives access to the latest performance improvements and "unstable" optimizations

```sh
# Install the nightly toolchain
rustup toolchain install nightly
# EITHER configure your current project to use nightly (run this command within the project)
rustup override set nightly
# OR configure cargo to use nightly for all projects -- switch back with `rustup default stable`
rustup default nightly
```

You can use `cargo +nightly ...` if you don't want to change the default to nightly, but just want to use it once for the current command.

3. **Configure cargo**: With the linker installed and nightly rust activated, all we need to do now is put them to proper use. Copy [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`.

Beyond enabling the LLD linker, this configuration file also activates **Generic Sharing** (unless you use Windows), which 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.