Skip to content

Commit 05e62f9

Browse files
Add no_std support to wgpu-types (#6892)
* Initial Commit * Remove now-redundant `format` import * Update CHANGELOG.md * Appropriately feature-gate `texture_format_serialize` test * Remove `alloc` feature Also fixed some documentation links and a Wasm `std` import * Revert change to `Serialize` for `TextureFormat` * Combine use statements * Switch from `PathBuf` to `String` * Consider environmental flags as unset on `no_std` * Fix missing `format!` * Add new CI tasks for `no_std` testing * Comment out known failing CI matrix option * Update all usage of `Dx12Compiler::DynamicDxc` * Added comments to CI * Update .github/workflows/ci.yml * Update .github/workflows/ci.yml * Update .github/workflows/ci.yml * CI Touchups --------- Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
1 parent 4efc992 commit 05e62f9

File tree

17 files changed

+148
-74
lines changed

17 files changed

+148
-74
lines changed

.github/workflows/ci.yml

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,66 +91,93 @@ jobs:
9191
- name: Windows x86_64
9292
os: windows-2022
9393
target: x86_64-pc-windows-msvc
94+
tier: 1
9495
kind: native
9596

9697
# Windows
9798
- name: Windows aarch64
9899
os: windows-2022
99100
target: aarch64-pc-windows-msvc
101+
tier: 2
100102
kind: native
101103

102104
# MacOS
103105
- name: MacOS x86_64
104106
os: macos-14
105107
target: x86_64-apple-darwin
108+
tier: 1
106109
kind: native
107110

108111
- name: MacOS aarch64
109112
os: macos-14
110113
target: aarch64-apple-darwin
114+
tier: 1
111115
kind: native
112116

113117
# IOS
114118
- name: IOS aarch64
115119
os: macos-14
116120
target: aarch64-apple-ios
121+
tier: 2
117122
kind: native
118123

119124
# VisionOS
120125
- name: VisionOS aarch64
121126
os: macos-14
122127
target: aarch64-apple-visionos
123128
kind: wgpu-only
124-
toolchain: nightly
129+
tier: 3
125130
extra-flags: -Zbuild-std
126131

127132
# Linux
128133
- name: Linux x86_64
129134
os: ubuntu-22.04
130135
target: x86_64-unknown-linux-gnu
136+
tier: 1
131137
kind: native
132138

133139
- name: Linux aarch64
134140
os: ubuntu-22.04
135141
target: aarch64-unknown-linux-gnu
142+
tier: 1
136143
kind: native
137144

138145
# Android
139146
- name: Android aarch64
140147
os: ubuntu-22.04
141148
target: aarch64-linux-android
149+
tier: 2
142150
kind: native
143151

144152
# WebGPU/WebGL
145153
- name: WebAssembly
146154
os: ubuntu-22.04
147155
target: wasm32-unknown-unknown
156+
tier: 2
148157
kind: web
149158

150159
- name: Emscripten
151160
os: ubuntu-22.04
152161
target: wasm32-unknown-emscripten
162+
tier: 2
153163
kind: wgpu-only
164+
165+
# TODO: Uncomment once web-sys updates past 0.3.76
166+
# See https://github.com/rustwasm/wasm-bindgen/pull/4378 for details
167+
# - name: WebAssembly Core 1.0
168+
# os: ubuntu-22.04
169+
# target: wasm32v1-none
170+
# tier: 2
171+
# kind: no_std
172+
173+
# Bare-metal x86-64
174+
# TODO: Remove once web-sys updates past 0.3.76
175+
# Included while wasm32v1-none is failing to ensure `no_std` does not regress
176+
- name: no_std x86_64
177+
os: ubuntu-22.04
178+
target: x86_64-unknown-none
179+
tier: 2
180+
kind: no_std
154181

155182
name: Clippy ${{ matrix.name }}
156183
runs-on: ${{ matrix.os }}
@@ -159,8 +186,8 @@ jobs:
159186
- name: checkout repo
160187
uses: actions/checkout@v4
161188

162-
- name: Install Toolchain (Repo MSRV)
163-
if: matrix.toolchain != 'nightly'
189+
- name: Install Toolchain (Repo MSRV - Tier 1 or 2)
190+
if: matrix.tier == 1 || matrix.tier == 2
164191
run: |
165192
rustup toolchain install ${{ env.REPO_MSRV }} --no-self-update --profile=minimal --component clippy
166193
rustup target add ${{ matrix.target }} --toolchain ${{ env.REPO_MSRV }}
@@ -178,8 +205,8 @@ jobs:
178205
#
179206
# RUSTC_BOOTSTRAP=1 is how the rust project builds itself when bootstrapping the compiler, so while not "stable"
180207
# it has been around for many years and don't anticipate it going away any time soon.
181-
- name: Install Toolchain (Repo MSRV - Pseudo Nightly)
182-
if: matrix.toolchain == 'nightly'
208+
- name: Install Toolchain (Repo MSRV - Tier 3)
209+
if: matrix.tier == 3
183210
run: |
184211
rustup toolchain install ${{ env.REPO_MSRV }} --no-self-update --profile=minimal --component clippy,rust-src
185212
echo "RUSTC_BOOTSTRAP=1" >> "$GITHUB_ENV"
@@ -246,6 +273,19 @@ jobs:
246273
# Check with all features.
247274
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu-hal --all-features
248275
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu --all-features
276+
277+
# Building for no_std platforms where every feature is enabled except "std".
278+
- name: check no_std
279+
if: matrix.kind == 'no_std'
280+
shell: bash
281+
run: |
282+
set -e
283+
284+
# check with no features
285+
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu-types --no-default-features
286+
287+
# Check with all features except "std".
288+
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu-types --no-default-features --features strict_asserts,fragile-send-sync-non-atomic-wasm,serde,counters
249289
250290
# Building for native platforms with standard tests.
251291
- name: check native

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ By @wumpf in [#6849](https://github.com/gfx-rs/wgpu/pull/6849).
164164
- `DeviceType` and `AdapterInfo` now impl `Hash` by @cwfitzgerald in [#6868](https://github.com/gfx-rs/wgpu/pull/6868)
165165
- Add build support for Apple Vision Pro. By @guusw in [#6611](https://github.com/gfx-rs/wgpu/pull/6611).
166166
- Add `wgsl_language_features` for obtaining available WGSL language feature by @sagudev in [#6814](https://github.com/gfx-rs/wgpu/pull/6814)
167+
- Add `no_std` support to `wgpu-types`. By @bushrat011899 in [#6892](https://github.com/gfx-rs/wgpu/pull/6892).
167168

168169
##### Vulkan
169170

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ ron = "0.8"
127127
# rustc-hash 2.0 is a completely different hasher with different performance characteristics
128128
serde_json = "1.0.134"
129129
rustc-hash = "1"
130-
serde = "1"
130+
serde = { version = "1", default-features = false }
131131
smallvec = "1"
132132
static_assertions = "1.1.0"
133133
strum = { version = "0.26.0", features = ["derive"] }
@@ -173,11 +173,11 @@ windows = { version = "0.58", default-features = false }
173173
# wasm32 dependencies
174174
console_error_panic_hook = "0.1.7"
175175
console_log = "1"
176-
js-sys = "0.3.70"
176+
js-sys = { version = "0.3.70", default-features = false }
177177
wasm-bindgen = "0.2.97"
178178
wasm-bindgen-futures = "0.4.45"
179179
wasm-bindgen-test = "0.3"
180-
web-sys = "0.3.74"
180+
web-sys = { version = "0.3.74", default-features = false }
181181
web-time = "0.2.4"
182182

183183
# deno dependencies

lock-analyzer/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ anyhow.workspace = true
1616

1717
[dependencies.serde]
1818
workspace = true
19-
features = ["serde_derive"]
19+
features = ["default", "serde_derive"]

naga/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ log = "0.4"
7878
strum.workspace = true
7979
spirv = { version = "0.3", optional = true }
8080
thiserror.workspace = true
81-
serde = { version = "1.0.217", features = ["derive"], optional = true }
81+
serde = { version = "1.0.217", features = [
82+
"default",
83+
"derive",
84+
], optional = true }
8285
# Hold on updating to 0.7 until https://github.com/petgraph/petgraph/pull/714 is on crates.io
8386
petgraph = { version = "0.6", optional = true }
8487
pp-rs = { version = "0.2.1", optional = true }
@@ -101,5 +104,5 @@ hlsl-snapshots = { path = "./hlsl-snapshots" }
101104
# incompatible with our tests because we do a syntactic diff and not a semantic one.
102105
ron = "0.8.0"
103106
rspirv = { version = "0.11", git = "https://github.com/gfx-rs/rspirv", rev = "b969f175d5663258b4891e44b76c1544da9661ab" }
104-
serde = { workspace = true, features = ["derive"] }
107+
serde = { workspace = true, features = ["default", "derive"] }
105108
spirv = { version = "0.3", features = ["deserialize"] }

wgpu-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ profiling = { workspace = true, default-features = false }
127127
raw-window-handle = { workspace = true, optional = true }
128128
ron = { workspace = true, optional = true }
129129
rustc-hash.workspace = true
130-
serde = { workspace = true, features = ["derive"], optional = true }
130+
serde = { workspace = true, features = ["default", "derive"], optional = true }
131131
smallvec.workspace = true
132132
thiserror.workspace = true
133133

wgpu-hal/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,13 @@ core-graphics-types.workspace = true
188188
[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies]
189189
wasm-bindgen.workspace = true
190190
web-sys = { workspace = true, features = [
191+
"default",
191192
"Window",
192193
"HtmlCanvasElement",
193194
"WebGl2RenderingContext",
194195
"OffscreenCanvas",
195196
] }
196-
js-sys.workspace = true
197+
js-sys = { workspace = true, features = ["default"] }
197198

198199
[target.'cfg(unix)'.dependencies]
199200
libc.workspace = true

wgpu-hal/examples/ray-traced-triangle/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ impl<A: hal::Api> Example<A> {
240240
name: "example",
241241
flags: wgt::InstanceFlags::default(),
242242
dx12_shader_compiler: wgt::Dx12Compiler::DynamicDxc {
243-
dxc_path: std::path::PathBuf::from("dxcompiler.dll"),
244-
dxil_path: std::path::PathBuf::from("dxil.dll"),
243+
dxc_path: "dxcompiler.dll".to_string(),
244+
dxil_path: "dxil.dll".to_string(),
245245
},
246246
gles_minor_version: wgt::Gles3MinorVersion::default(),
247247
};

wgpu-hal/src/dx12/instance.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,13 @@ impl crate::Instance for super::Instance {
7272
dxil_path,
7373
dxc_path,
7474
} => {
75-
let container =
76-
super::shader_compilation::get_dynamic_dxc_container(dxc_path, dxil_path)
77-
.map_err(|e| {
78-
crate::InstanceError::with_source(
79-
String::from("Failed to load dynamic DXC"),
80-
e,
81-
)
82-
})?;
75+
let container = super::shader_compilation::get_dynamic_dxc_container(
76+
dxc_path.into(),
77+
dxil_path.into(),
78+
)
79+
.map_err(|e| {
80+
crate::InstanceError::with_source(String::from("Failed to load dynamic DXC"), e)
81+
})?;
8382

8483
Some(Arc::new(container))
8584
}

wgpu-info/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ anyhow.workspace = true
1414
bitflags.workspace = true
1515
env_logger.workspace = true
1616
pico-args.workspace = true
17-
serde.workspace = true
17+
serde = { workspace = true, features = ["default"] }
1818
serde_json.workspace = true
1919
wgpu = { workspace = true, features = ["serde", "dx12", "metal", "static-dxc"] }

0 commit comments

Comments
 (0)