support overriding a crate's opt level per compilation mode
Maintainers usually reply within 3 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 74/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- rust
- Domain
- build-system
Research direction
Start in rust.bzl to trace the rust_* rule attributes, then follow construct_arguments where the toolchain opt level is substituted. Add the compilation-mode-keyed opt_level behavior described in the issue and verify that listed crates override the mode's level while unlisted modes and crates retain current behavior.
Written by the indexing model from the issue text.
Description
Cargo's canonical fast-dev-build recipe optimizes chosen packages while the rest of the workspace keeps opt-level 0 ([profile.dev.package."<name>"] opt-level = 1). rules_rust has no equivalent: rust_toolchain.opt_level applies to every crate in a compilation mode, and the only per-crate escape hatch is raw -C flags in rustc_flags, which bypasses the compilation-mode model — one rustc_flags value applies in every mode, so a fastbuild override leaks into -c opt builds too.
Proposal: an opt_level attr on the rust_* rules, keyed by compilation mode, substituting the toolchain's opt level for that crate:
rust_library(
name = "hot_crate",
...
opt_level = {"fastbuild": "1"},
)
Modes not listed, and crates without the attr, behave exactly as today.
Data point from our monorepo: a profile of a CPU-bound e2e suite put ~55% of CPU self-time in a handful of rarely-edited foundation crates; pinning those to opt-level 1 under fastbuild cut the heaviest test from 158s to ~85s while leaving every other crate's compile time untouched. We carry this as a ~25-line patch (attr in rust.bzl, one substitution in construct_arguments) and can send a PR if the shape is acceptable.
- Dominant language
- Starlark
- Stars
- 857
- Forks
- 701
- Avg merge
- 4d 7h
- Merged PRs (30d)
- 46
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from bazelbuild/rules_rust
-
`rust_test(crate = ...)` does not stage the crate's transitive dynamic libraries into runfilesPossibly taken @Wito-1 claimed this 65 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
bazelbuild/rules_rust#4309 ·
Maintainers usually reply within 3 days
-
Windows (no-symlink path): drain_runfiles_dir_windows deletes retained runfiles — inverted filename_suffixes_to_retain conditionPossibly taken @Mattbusel claimed this 17 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
bazelbuild/rules_rust#4266 ·
Maintainers usually reply within 3 days
-
rust.toolchain(strip_level = ...) is silently ignoredPossibly taken @Mattbusel claimed this 17 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
bazelbuild/rules_rust#4223 ·
Maintainers usually reply within 3 days
-
Difficulty 1/5 1-3 hours Newbie friendliness 90/100
bazelbuild/rules_rust#4152 · 1 reaction ·
Maintainers usually reply within 3 days
-
awaiting-response
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
bazelbuild/rules_rust#3599 · 1 comment ·
Maintainers usually reply within 3 days
All issues in bazelbuild/rules_rust
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
bazelbuild/apple_support#707 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
out-of-date
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
CachyOS/CachyOS-PKGBUILDS#2232 ·
Maintainers usually reply within 1 day
-
blast/large refactor risk/low spend-dem
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
chriskelly/MusicWall#87 · 2 comments ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
neilotoole/sq#1503 ·
Maintainers usually reply within 1 day