diff --git a/esp-hal/build.rs b/esp-hal/build.rs index 1c0cef638..c3e0d3b29 100644 --- a/esp-hal/build.rs +++ b/esp-hal/build.rs @@ -22,6 +22,11 @@ macro_rules! assert_unique_features { } fn main() -> Result<(), Box> { + // if using '"rust-analyzer.cargo.buildScripts.useRustcWrapper": true' we can detect this + let suppress_panics = std::env::var("RUSTC_WRAPPER") + .unwrap_or_default() + .contains("rust-analyzer"); + println!("cargo:rustc-check-cfg=cfg(is_debug_build)"); if let Ok(level) = std::env::var("OPT_LEVEL") && (level == "0" || level == "1") @@ -30,7 +35,7 @@ fn main() -> Result<(), Box> { } // If some library required unstable make sure unstable is actually enabled. - if cfg!(feature = "requires-unstable") && !cfg!(feature = "unstable") { + if !suppress_panics && cfg!(feature = "requires-unstable") && !cfg!(feature = "unstable") { panic!( "\n\nThe `unstable` feature is required by a dependent crate but is not enabled.\n\n" ); @@ -44,7 +49,7 @@ fn main() -> Result<(), Box> { // Ensure that exactly one chip has been specified: let chip = esp_metadata_generated::Chip::from_cargo_feature()?; - if chip.target() != std::env::var("TARGET").unwrap_or_default().as_str() { + if !suppress_panics && chip.target() != std::env::var("TARGET").unwrap_or_default().as_str() { panic!(" Seems you are building for an unsupported or wrong target (e.g. the host environment). Maybe you are missing the `target` in `.cargo/config.toml` or you have configs overriding it? diff --git a/esp-radio/build.rs b/esp-radio/build.rs index e6f752bec..4bb11c55a 100644 --- a/esp-radio/build.rs +++ b/esp-radio/build.rs @@ -21,6 +21,11 @@ macro_rules! assert_unique_features { } fn main() -> Result<(), Box> { + // if using '"rust-analyzer.cargo.buildScripts.useRustcWrapper": true' we can detect this + let suppress_panics = std::env::var("RUSTC_WRAPPER") + .unwrap_or_default() + .contains("rust-analyzer"); + // Load the configuration file for the configured device: let chip = Chip::from_cargo_feature()?; @@ -28,7 +33,7 @@ fn main() -> Result<(), Box> { chip.define_cfgs(); // If some library required unstable make sure unstable is actually enabled. - if cfg!(feature = "requires-unstable") && !cfg!(feature = "unstable") { + if !suppress_panics && cfg!(feature = "requires-unstable") && !cfg!(feature = "unstable") { panic!( "\n\nThe `unstable` feature is required by a dependent crate but is not enabled.\n\n" ); @@ -42,6 +47,7 @@ fn main() -> Result<(), Box> { || cfg!(feature = "smoltcp") || cfg!(feature = "sniffer")) && !cfg!(feature = "unstable") + && !suppress_panics { panic!( "\n\nThe `unstable` feature was not provided, but is required for the following features: `ble`, `coex`, `csi`, `esp-now`, `ieee802154`, `smoltcp`, `sniffer`.\n\n"