Skip to content

Commit

Permalink
Improve the Cranelift section.
Browse files Browse the repository at this point in the history
  • Loading branch information
nnethercote committed Feb 4, 2024
1 parent a2b9141 commit 22815b8
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions src/build-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ Alternative linkers can be dramatically faster, without any downsides.
### Experimental Parallel Front-end

If you use nightly Rust, you can enable the experimental [parallel front-end].
It may reduce compile times at the cost of higher compile-time memory usage. It
won't affect the quality of the generated code.

[parallel front-end]: https://blog.rust-lang.org/2023/11/09/parallel-rustc.html

Expand All @@ -337,7 +339,7 @@ You can do that by adding `-Zthreads=N` to RUSTFLAGS, for example:
RUSTFLAGS="-Zthreads=8" cargo build --release
```

Alternatively, to request these instructions from a [`config.toml`] file (for
Alternatively, to enable the parallel front-end from a [`config.toml`] file (for
one or more projects), add these lines:
```toml
[build]
Expand All @@ -353,20 +355,38 @@ up to 50%. But the effects vary widely and depend on the characteristics of the
code and its build configuration, and for some programs there is no compile
time improvement.

### Codegen backend
You can use a different codegen backend to reduce compile times. Currently,
the Cranelift codegen backend is available in the nightly chanel for Linux x64 and 64-bit ARM targets.
### Cranelift Codegen Back-end

If you use nightly Rust on x86-64/Linux or ARM/Linux, you can enable the
Cranelift codegen back-end. It may reduce compile times at the cost of lower
quality generated code, and therefore is recommended for dev builds rather than
release builds.

You can install it with this `rustup` command:
First, install the back-end with this `rustup` command:
```bash
$ rustup component add rustc-codegen-cranelift-preview --toolchain nightly
rustup component add rustc-codegen-cranelift-preview --toolchain nightly
```

To select Cranelift from the command line, use the
`-Zcodegen-backend=cranelift` flag. For example:
```
RUSTFLAGS="-Zcodegen-backend=cranelift" cargo +nightly build
```

And then use it with one of the following commands:
- `RUSTFLAGS="-Zcodegen-backend=cranelift" cargo +nightly build`
- `CARGO_PROFILE_DEV_CODEGEN_BACKEND=cranelift cargo +nightly build -Zcodegen-backend`
Alternatively, to specify Cranelift from a [`config.toml`] file (for one or
more projects), add these lines:
```toml
[unstable]
codegen-backend = true

[profile.dev]
codegen-backend = "cranelift"
```
[`config.toml`]: https://doc.rust-lang.org/cargo/reference/config.html

For more information, see the [Cranelift documentation].

You can find more information about this codegen backend [here](https://github.com/rust-lang/rustc_codegen_cranelift).
[Cranelift documentation]: https://github.com/rust-lang/rustc_codegen_cranelift

## Custom profiles

Expand Down

0 comments on commit 22815b8

Please sign in to comment.