Add per-target clippy_config attribute to Rust rules#4007
Open
zertosh wants to merge 1 commit intobazelbuild:mainfrom
Open
Add per-target clippy_config attribute to Rust rules#4007zertosh wants to merge 1 commit intobazelbuild:mainfrom
zertosh wants to merge 1 commit intobazelbuild:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
rules_rustexposes the clippy configuration file only via the global@rules_rust//rust/settings:clippy.tomlbuild setting. There is no wayto attach a different
clippy.tomlto a specific target.In a large workspace, a root
clippy.tomlis often supplemented byper-subtree configs that scope
disallowed-methods,disallowed-types,and similar config-only lints to specific subsystems. Under Cargo,
clippy-driverwalks parent directories fromCARGO_MANIFEST_DIRandfinds the nearest config. Under Bazel only the global file applies, so
those subtree-specific lints never fire.
Solution
Add a
clippy_configattribute to the common Rust rule attributes(
rust_library,rust_binary,rust_test,rust_shared_library,rust_static_library,rust_proc_macro). When set,rust_clippy_aspectpoints
CLIPPY_CONF_DIRat this file's directory instead of the globalbuild setting. The existing basename validation and input registration
in
rust_clippy_actionare reused unchanged.An alternative was to extend
rust_lint_configwith aclippy_tomlattribute populating
LintsInfo.clippy_lint_files. That keeps theconfig on the existing
lint_configattribute, butCLIPPY_CONF_DIRaccepts a single directory so the aspect would still pick exactly one
file, and the indirection makes BUILD files less obvious than
clippy_config = ":clippy.toml"on the target.Testing
//test/unit/clippyassertCLIPPY_CONF_DIRresolves to the global default when
clippy_configis unset, to theper-target directory when set, that a
rust_test(crate = ...)doesnot inherit the setting from the crate under test, and that it honors
its own
clippy_config.//test/clippy:clippy_failure_testercovers a per-target sourceconfig, a per-target generated config, and precedence of
clippy_configover the global label flag.This also fixes the
BAD_CLIPPY_TOMLlabel inclippy_failure_tester.sh, which previously made the existing assertionpass on a package-resolution error rather than the intended lint
failure.