Fix initialize_adapter_from_env under no_std.

Without this change, `desired_adapter_name` is an undeclared variable.
This commit is contained in:
Kevin Reid 2025-07-10 10:06:36 -07:00 committed by Connor Fitzgerald
parent c0a8ba69b0
commit b83c9cfd57

View File

@ -5,20 +5,23 @@ use crate::Backends;
/// Initialize the adapter obeying the `WGPU_ADAPTER_NAME` environment variable. /// Initialize the adapter obeying the `WGPU_ADAPTER_NAME` environment variable.
#[cfg(wgpu_core)] #[cfg(wgpu_core)]
#[cfg_attr(not(std), expect(unused_variables, unreachable_code))]
pub fn initialize_adapter_from_env( pub fn initialize_adapter_from_env(
instance: &Instance, instance: &Instance,
compatible_surface: Option<&Surface<'_>>, compatible_surface: Option<&Surface<'_>>,
) -> Result<Adapter, wgt::RequestAdapterError> { ) -> Result<Adapter, wgt::RequestAdapterError> {
cfg_if::cfg_if! { let desired_adapter_name: alloc::string::String = {
if #[cfg(std)] { cfg_if::cfg_if! {
let desired_adapter_name = std::env::var("WGPU_ADAPTER_NAME") if #[cfg(std)] {
.as_deref() std::env::var("WGPU_ADAPTER_NAME")
.map(str::to_lowercase) .as_deref()
.map_err(|_| wgt::RequestAdapterError::EnvNotSet)?; .map(str::to_lowercase)
} else { .map_err(|_| wgt::RequestAdapterError::EnvNotSet)?
return Err(wgt::RequestAdapterError::EnvNotSet); } else {
return Err(wgt::RequestAdapterError::EnvNotSet)
}
} }
} };
let adapters = instance.enumerate_adapters(crate::Backends::all()); let adapters = instance.enumerate_adapters(crate::Backends::all());