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.
#[cfg(wgpu_core)]
#[cfg_attr(not(std), expect(unused_variables, unreachable_code))]
pub fn initialize_adapter_from_env(
instance: &Instance,
compatible_surface: Option<&Surface<'_>>,
) -> Result<Adapter, wgt::RequestAdapterError> {
cfg_if::cfg_if! {
if #[cfg(std)] {
let desired_adapter_name = std::env::var("WGPU_ADAPTER_NAME")
.as_deref()
.map(str::to_lowercase)
.map_err(|_| wgt::RequestAdapterError::EnvNotSet)?;
} else {
return Err(wgt::RequestAdapterError::EnvNotSet);
let desired_adapter_name: alloc::string::String = {
cfg_if::cfg_if! {
if #[cfg(std)] {
std::env::var("WGPU_ADAPTER_NAME")
.as_deref()
.map(str::to_lowercase)
.map_err(|_| wgt::RequestAdapterError::EnvNotSet)?
} else {
return Err(wgt::RequestAdapterError::EnvNotSet)
}
}
}
};
let adapters = instance.enumerate_adapters(crate::Backends::all());