Skip to content

Conversation

Kobzol
Copy link
Member

@Kobzol Kobzol commented Sep 15, 2025

This extends the build performance guide in the Cargo book with the parallel frontend. This is the first mechanism we have in the guide that is not configured via profiles (unless we want to advertise setting rustflags through profiles?), but rather through RUSTFLAGS. Which means that we have to explain how to do that.

I proposed using footnotes for this, so that we can reuse them also for other thing (such as explaining how to change a profile). An alternative would be to have a short paragraph at the beginning of the configuration subsection where we explain all the possible ways of configuring things, and then we refer to them.

This is a follow up to #15924

r? @epage

@rustbot rustbot added A-documenting-cargo-itself Area: Cargo's documentation S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 15, 2025
Comment on lines 76 to 78
```console
$ RUSTFLAGS="-Zthreads=8" cargo build
```
Copy link
Contributor

Choose a reason for hiding this comment

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

Should our default recommendation be the CLI or build.rustflags? I lean towards the latter:

  • The docs call out the other mechanisms
  • Starts the user off with a more permanent place to put this so they don't have to remember on every invocation

Copy link
Contributor

Choose a reason for hiding this comment

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

Granted, this means we need to update the config section to be more nuanced since this wouldn't be set in Cargo.toml

Copy link
Contributor

Choose a reason for hiding this comment

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

build.rustflags was added in addition to the command line. Do we need both?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that we should show both, as using RUSTLAGS is useful for one-off tests. Not sure if we need to repeat both ways to configure rustflags for all workarounds that use it though. Once/if we have a second mechanism that uses RUSTFLAGS, I'd perhaps move this to the beginning of the section and then just refer to it.

Copy link
Contributor

Choose a reason for hiding this comment

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

If our goal is "show how to speed your build", having our recommendation be something that is not required on every command seems better to me. If we link out to the docs, it will list out how else it can be set (maybe we could even call out that there are other ways). Not a fan of the redundancy though.

Copy link
Member Author

Choose a reason for hiding this comment

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

I figured that for manually benchmarking which one is faster (e.g. using back-to-back CLI invocations or e.g. hyperfine), setting it through the environment variable is easier. For long term usage the config is ofc better.

Also regarding the config, there are trade-offs between setting build.rustflags and target.rustflags 😆 Stuff is complicated.

Copy link
Contributor

Choose a reason for hiding this comment

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

Framing this as "what steps you need to benchmark" vs "what steps to apply to get the benefit" are very different. If we were going for the former, the debug info section should instead use the environment variable for it.

As for which *.rustflags, this is platform agnostic so it seems like that would be build.rustflags.

Copy link
Member Author

Choose a reason for hiding this comment

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

Which rustflags flag is important regarding their priority, and whether they are used for build scripts, but for the parallel frontend that probably won't matter, so let's keep it simple and use build.rustflags, yeah.


Trade-offs:
- ✅ Faster build times
-**Requires using nightly Rust and an unstable Cargo feature**
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have this link out to the documentation for the unstable feature? imo it would be good to help people track the progress. I went with the docs to add an extra step in the hope that it reduces "whats the status?" posts.

I was wondering about this for our other one but that seemed to have fallen through the cracks

Copy link
Member Author

Choose a reason for hiding this comment

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

Will add a link to the parallel frontend issue. There is no tracking issue for Cranelift, I think, but we can link to rust-lang/rust#77933.

Copy link
Member Author

Choose a reason for hiding this comment

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

I linked to the unstable Cargo -Zcodegen-backend feature in Cargo reference in the book.

Recommendation: Add `-Zthreads=n` to the `RUSTFLAGS` environment variable[^rustflags], for example:

```console
$ RUSTFLAGS="-Zthreads=8" cargo build
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we somewhere mention the way to make nightly your default?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, that seems a bit orthogonal to this document, and more related to rustup. We also don't describe how to actually install nightly (nor should we). The example should use +nightly though, that's a good point.

@Kobzol
Copy link
Member Author

Kobzol commented Sep 19, 2025

I think it now looks as you wanted it to, but happy to make further edits :)

@epage
Copy link
Contributor

epage commented Sep 19, 2025

Since we're looking at a couple more changes, mind cleaning up the commits while you are at it? For me, having them go back and forth in different directions makes it harder to review

@Kobzol Kobzol force-pushed the build-performance-parallel-frontend branch from 6f1c8df to a887a25 Compare September 19, 2025 18:09
@Kobzol
Copy link
Member Author

Kobzol commented Sep 19, 2025

Ok, done.

@epage epage enabled auto-merge September 19, 2025 18:13
@epage epage added this pull request to the merge queue Sep 19, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Sep 19, 2025
@ehuss ehuss added this pull request to the merge queue Sep 19, 2025
Merged via the queue into rust-lang:master with commit 5818dcd Sep 19, 2025
25 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 19, 2025
@Kobzol Kobzol deleted the build-performance-parallel-frontend branch September 20, 2025 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-documenting-cargo-itself Area: Cargo's documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants