bazelbuild / bazelbuild/rules_rust

Support for overridable "--cap-lint" and other similar flags in toolchain

Open
#3,810 2 comments 0 reactions 1 assignee Claimed by @scentini View on GitHub
core needs-design
Dominant language
Starlark
Stars
843
Forks
651
Avg merge
2d 18h
Merged PRs (30d)
15

Description

### Problem Description

We are looking for a way to enforce a default rustc policy (specifically `--cap-lints=deny`) at the toolchain level, while retaining the ability to relax this constraint on specific targets (e.g. `--cap-lints=allow`).

### Current Limitation

Currently, rules_rust simply accumulates flags from the toolchain and the target. This works for flags where the last instance overrides previous ones (e.g., `-C opt-level`), but it fails for rustc flags that behave intersectionally.

Specifically, rustc's `--cap-lints` uses the "most restrictive" logic. If the toolchain passes deny and the target passes allow, rustc adheres to deny. Because there is no way to prevent the toolchain from emitting its default flags, we are unable to relax the lint cap on a per-target basis.

### Proposed Solution / Question

Does rules_rust have plans to support a feature configuration system similar to rules_cc?

In rules_cc, we could define mutually exclusive features (e.g., `cap_lints_deny` vs `cap_lints_allow`) where enabling one on a target disables the default. Without this, or a specific "default_rustc_flags" attribute that can be explicitly overridden/cleared by targets, we are forced to use wrapper macros for all targets to manage these defaults.

We would love to see a mechanism to define "weak" defaults in the toolchain that target-level flags can supersede.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.