Skip to content

Commit dd32435

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 fb3abfc commit dd32435

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Bottom level categories:
4242

4343
### Bug Fixes
4444

45+
- Fixed build error inside `wgpu::util::initialize_adapter_from_env` when `std` feature is not enabled. By @kpreid in [#7918](https://github.com/gfx-rs/wgpu/pull/7918).
4546
- Fixed build error occurring when the `profiling` dependency is configured to have profiling active. By @kpreid in [#7916](https://github.com/gfx-rs/wgpu/pull/7916).
4647

4748
## v26.0.0 (2025-07-09)

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)