Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use cargo +TOOLCHAIN shortcut and move --cfg bevy_lint logic #264

Merged
merged 2 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions bevy_lint/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,18 @@ fn main() -> anyhow::Result<ExitCode> {
// Find the path to `bevy_lint_driver`.
let driver_path = driver_path()?;

// Run `cargo check`.
let status = Command::new("cargo")
// Assuming that Rustup is installed, we can specify which toolchain to use with this.
.arg(format!("+{RUST_TOOLCHAIN_CHANNEL}"))
// Run `rustup run nightly-YYYY-MM-DD cargo check`.
let status = Command::new("rustup")
.arg("run")
.arg(RUST_TOOLCHAIN_CHANNEL)
.arg("cargo")
.arg("check")
// Forward all arguments to `cargo check` except for the first, which is the path to the
// current executable.
.args(std::env::args().skip(1))
// This instructs `rustc` to call `bevy_lint_driver` instead of its default routine.
// This lets us register custom lints.
.env("RUSTC_WORKSPACE_WRAPPER", driver_path)
// Pass `--cfg bevy_lint` so that programs can conditionally configure lints. If
// `RUSTFLAGS` is already set, we append `--cfg bevy_lint` to the end.
.env(
"RUSTFLAGS",
env::var("RUSTFLAGS").map_or_else(
|_| "--cfg bevy_lint".to_string(),
|mut flags| {
flags.push_str(" --cfg bevy_lint");
flags
},
),
)
.status()
.context("Failed to spawn `cargo check`.")?;

Expand Down
3 changes: 3 additions & 0 deletions bevy_lint/src/callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ impl Callbacks for BevyLintCallback {
fn config(&mut self, config: &mut Config) {
crate::config::load_config(config);

// Add `--cfg bevy_lint` so programs can conditionally configure lints.
config.crate_cfg.push("bevy_lint".to_string());

// We're overwriting `register_lints`, but we don't want to completely delete the original
// function. Instead, we save it so we can call it ourselves inside its replacement.
let previous = config.register_lints.take();
Expand Down