Commit bcc8cd3
committed
Chatted about this previously in
[Slack](https://bazelbuild.slack.com/archives/CSV56UT0F/p1718030356910019).
The goal with this PR is to make it easier to define and share lint
configurations for your build.
The PR adds two new rules, `rust_lint_group` and `cargo_lints`. It also
adds a "lints" attr to `rust_library` and `rust_binary` rules that
expects a new `LintsInfo` provider.
* `rust_lint_group` allows you to define Rust, Clippy, and Rustdoc lints
in a `BUILD` file.
* `cargo_lints` automatically generates a set of lints by reading a
crate's `Cargo.toml`, and optionally the workspace's Cargo.toml for
workspace inheritance.
Then the rustc, clippy, and rustdoc actions are all updated to check for
the `LintsInfo` provider and appends the correct arguments so the lints
take effect.
Honestly this is my first large change to a set of Bazel rules, so I
definitely could have done something wrong here!
The change is split into two commits, the first introduces
`rust_lint_group` which IMO is relatively straight forward. Some
attributes are defined on a rule which are then formatted into command
line flags and passed around with a provider.
The second commit adds `cargo_lints` and is much larger, a few things
worth considering:
* I was back and forth a bit on using a `repository_rule` or a regular
`rule`. While the `repository_rule` maps well to a Cargo Workspace and
you'd only need to define it once, not everyone uses workspaces and so I
figured a regular `rule` was more general.
* Parsing a `Cargo.toml` is done via a new Rust binary called
`cargo_toml_info`. I tried to keep the external dependencies on this
binary to a minimum, it only has one at the moment which is
[`cargo_toml`](https://docs.rs/cargo_toml/latest/cargo_toml/) and I
based this change largely off of
bazelbuild#2772. I tried to make the
tool general though so other Cargo metadata rules could use it in the
future.
There aren't any! I wasn't sure where the best place to start was, any
guidance here is appreciated!
1 parent ffdf608 commit bcc8cd3
File tree
53 files changed
+3374
-25
lines changed- .bazelci
- cargo
- private
- cargo_toml_info
- 3rdparty
- crates
- docs/src
- examples
- bazel_env/rust/hello_world
- src
- cargo_lints
- src
- rust
- private
- test/unit/lint_flags
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
53 files changed
+3374
-25
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
28 | 43 | | |
29 | 44 | | |
30 | 45 | | |
| |||
297 | 312 | | |
298 | 313 | | |
299 | 314 | | |
300 | | - | |
301 | | - | |
| 315 | + | |
| 316 | + | |
302 | 317 | | |
303 | 318 | | |
304 | 319 | | |
305 | 320 | | |
306 | 321 | | |
307 | | - | |
| 322 | + | |
308 | 323 | | |
309 | | - | |
| 324 | + | |
310 | 325 | | |
311 | 326 | | |
312 | 327 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
161 | 167 | | |
162 | 168 | | |
163 | 169 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
48 | 52 | | |
49 | 53 | | |
50 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
16 | 20 | | |
17 | 21 | | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
21 | 25 | | |
| 26 | + | |
| 27 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 38 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
0 commit comments