From dcb272489e6bf300555fbd33e86a6b50c7549298 Mon Sep 17 00:00:00 2001 From: BD103 <59022059+BD103@users.noreply.github.com> Date: Sat, 8 Feb 2025 11:20:30 -0500 Subject: [PATCH 1/2] feat: call driver with `rustup run TOOLCHAIN` instead of `cargo +TOOLCHAIN` Some users don't have Rustup's proxy `cargo` on their path, so we cannot depend on `cargo +TOOLCHAIN` always working. Since we do require `rustup`, though, the explicit form should work more often. --- bevy_lint/src/bin/main.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bevy_lint/src/bin/main.rs b/bevy_lint/src/bin/main.rs index 7eca2df..af4cec6 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. From 36467d93f8eb07a7bc1059a7687bd5ccb0c43f88 Mon Sep 17 00:00:00 2001 From: BD103 <59022059+BD103@users.noreply.github.com> Date: Sat, 8 Feb 2025 18:31:32 -0500 Subject: [PATCH 2/2] refactor: move `--cfg bevy_lint` logic to driver Now if someone calls the driver directly, the `cfg` will still be applied. --- bevy_lint/src/bin/main.rs | 12 ------------ bevy_lint/src/callback.rs | 3 +++ 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/bevy_lint/src/bin/main.rs b/bevy_lint/src/bin/main.rs index af4cec6..6858eb6 100644 --- a/bevy_lint/src/bin/main.rs +++ b/bevy_lint/src/bin/main.rs @@ -33,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();