diff --git a/bevy_lint/src/bin/main.rs b/bevy_lint/src/bin/main.rs index 7eca2df..6858eb6 100644 --- a/bevy_lint/src/bin/main.rs +++ b/bevy_lint/src/bin/main.rs @@ -21,10 +21,11 @@ fn main() -> anyhow::Result { // 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. @@ -32,18 +33,6 @@ fn main() -> anyhow::Result { // 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`.")?; diff --git a/bevy_lint/src/callback.rs b/bevy_lint/src/callback.rs index e1d80e7..ab87dc1 100644 --- a/bevy_lint/src/callback.rs +++ b/bevy_lint/src/callback.rs @@ -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();