Skip to content

Commit b83c9cf

Browse files
kpreidcwfitzgerald
authored andcommitted
Fix initialize_adapter_from_env under no_std.
Without this change, `desired_adapter_name` is an undeclared variable.
1 parent c0a8ba6 commit b83c9cf

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

wgpu/src/util/init.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,23 @@ use crate::Backends;
55

66
/// Initialize the adapter obeying the `WGPU_ADAPTER_NAME` environment variable.
77
#[cfg(wgpu_core)]
8+
#[cfg_attr(not(std), expect(unused_variables, unreachable_code))]
89
pub fn initialize_adapter_from_env(
910
instance: &Instance,
1011
compatible_surface: Option<&Surface<'_>>,
1112
) -> Result<Adapter, wgt::RequestAdapterError> {
12-
cfg_if::cfg_if! {
13-
if #[cfg(std)] {
14-
let desired_adapter_name = std::env::var("WGPU_ADAPTER_NAME")
15-
.as_deref()
16-
.map(str::to_lowercase)
17-
.map_err(|_| wgt::RequestAdapterError::EnvNotSet)?;
18-
} else {
19-
return Err(wgt::RequestAdapterError::EnvNotSet);
13+
let desired_adapter_name: alloc::string::String = {
14+
cfg_if::cfg_if! {
15+
if #[cfg(std)] {
16+
std::env::var("WGPU_ADAPTER_NAME")
17+
.as_deref()
18+
.map(str::to_lowercase)
19+
.map_err(|_| wgt::RequestAdapterError::EnvNotSet)?
20+
} else {
21+
return Err(wgt::RequestAdapterError::EnvNotSet)
22+
}
2023
}
21-
}
24+
};
2225

2326
let adapters = instance.enumerate_adapters(crate::Backends::all());
2427

0 commit comments

Comments
 (0)