Skip to content

Commit b0f1fa6

Browse files
cwfitzgeraldguusw
andauthored
Add VisionOS Support (gfx-rs#6888)
* Add visionos support * Use `target_vendor = "apple"` * Fixes * Build VisionOS * Gah * Bleh * Typos --------- Co-authored-by: Guus Waals <[email protected]>
1 parent 1aabf22 commit b0f1fa6

File tree

20 files changed

+78
-46
lines changed

20 files changed

+78
-46
lines changed

.github/workflows/ci.yml

+50-20
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ env:
3434
# We sometimes need nightly to use special things in CI.
3535
#
3636
# In order to prevent CI regressions, we pin the nightly version.
37-
NIGHTLY_VERSION: "nightly-2024-10-10"
37+
NIGHTLY_VERSION: "nightly-2024-10-17"
3838
# This is the MSRV used by `wgpu` itself and all surrounding infrastructure.
3939
REPO_MSRV: "1.83"
4040
# This is the MSRV used by the `wgpu-core`, `wgpu-hal`, and `wgpu-types` crates,
@@ -111,6 +111,14 @@ jobs:
111111
target: aarch64-apple-ios
112112
kind: native
113113

114+
# VisionOS
115+
- name: VisionOS aarch64
116+
os: macos-14
117+
target: aarch64-apple-visionos
118+
kind: wgpu-only
119+
toolchain: nightly
120+
extra-flags: -Zbuild-std
121+
114122
# Linux
115123
- name: Linux x86_64
116124
os: ubuntu-22.04
@@ -137,7 +145,7 @@ jobs:
137145
- name: Emscripten
138146
os: ubuntu-22.04
139147
target: wasm32-unknown-emscripten
140-
kind: em
148+
kind: wgpu-only
141149

142150
name: Clippy ${{ matrix.name }}
143151
runs-on: ${{ matrix.os }}
@@ -146,12 +154,31 @@ jobs:
146154
- name: checkout repo
147155
uses: actions/checkout@v4
148156

149-
- name: Install Repo MSRV toolchain
157+
- name: Install Toolchain (Repo MSRV)
158+
if: matrix.toolchain != 'nightly'
150159
run: |
151-
rustup toolchain install ${{ env.REPO_MSRV }} --no-self-update --profile=minimal --component clippy --target ${{ matrix.target }}
160+
rustup toolchain install ${{ env.REPO_MSRV }} --no-self-update --profile=minimal --component clippy
161+
rustup target add ${{ matrix.target }} --toolchain ${{ env.REPO_MSRV }}
152162
rustup override set ${{ env.REPO_MSRV }}
153163
cargo -V
154164
165+
# In order to build on platforms that require a nightly toolchain, we install stable as expected,
166+
# add the rust-src component, then tell stable to consider itself nightly by setting RUSTC_BOOTSTRAP=1.
167+
#
168+
# This is not formally "correct" thing to do, but it saves significant maintainer burden. If we were to
169+
# use a proper nightly toolchain we would have to manually find a date that works. Even with a date that is
170+
# carefully coordinated with the version of stable we are using, there are often mismatches of clippy lints
171+
# between nightly and stable. This is a real mess. By using RUSTC_BOOTSTRAP=1, we get access to all the nice
172+
# nightly features without needing to go through the hassle of maintaining a nightly toolchain.
173+
#
174+
# RUSTC_BOOTSTRAP=1 is how the rust project builds itself when bootstrapping the compiler, so while not "stable"
175+
# it has been around for many years and don't anticipate it going away any time soon.
176+
- name: Install Toolchain (Repo MSRV - Pseudo Nightly)
177+
if: matrix.toolchain == 'nightly'
178+
run: |
179+
rustup toolchain install ${{ env.REPO_MSRV }} --no-self-update --profile=minimal --component clippy,rust-src
180+
echo "RUSTC_BOOTSTRAP=1" >> "$GITHUB_ENV"
181+
155182
- name: disable debug
156183
shell: bash
157184
run: |
@@ -183,50 +210,53 @@ jobs:
183210
# the android sdk doesn't use the conventional name for ar, so explicitly set it.
184211
echo "AR_aarch64_linux_android=llvm-ar" >> "$GITHUB_ENV"
185212
213+
# Building for wasm32 requires a series of specific tests for the WebGPU backend.
186214
- name: check web
187215
if: matrix.kind == 'web'
188216
shell: bash
189217
run: |
190218
set -e
191219
192220
# build for WebGPU
193-
cargo clippy --target ${{ matrix.target }} --tests --features glsl,spirv,fragile-send-sync-non-atomic-wasm
194-
cargo clippy --target ${{ matrix.target }} --tests --features glsl,spirv
195-
cargo doc --target ${{ matrix.target }} --no-deps --features glsl,spirv
221+
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} --tests --features glsl,spirv,fragile-send-sync-non-atomic-wasm
222+
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} --tests --features glsl,spirv
223+
cargo doc --target ${{ matrix.target }} ${{ matrix.extra-flags }} --no-deps --features glsl,spirv
196224
197225
# all features
198-
cargo clippy --target ${{ matrix.target }} --tests --all-features
199-
cargo doc --target ${{ matrix.target }} --no-deps --all-features
226+
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} --tests --all-features
227+
cargo doc --target ${{ matrix.target }} ${{ matrix.extra-flags }} --no-deps --all-features
200228
201-
- name: check em
202-
if: matrix.kind == 'em'
229+
# Building for platforms where the tests do not compile.
230+
- name: check wgpu only
231+
if: matrix.kind == 'wgpu-only'
203232
shell: bash
204233
run: |
205234
set -e
206235
207-
# build for Emscripten
208-
cargo clippy --target ${{ matrix.target }} -p wgpu -p wgpu-hal --no-default-features
236+
# check with no features
237+
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu -p wgpu-hal --no-default-features
209238
210239
# Don't check samples since we use winit in our samples which has dropped support for Emscripten.
211240
212-
# all features
213-
cargo clippy --target ${{ matrix.target }} -p wgpu-hal --all-features
214-
cargo clippy --target ${{ matrix.target }} -p wgpu --all-features
241+
# Check with all features.
242+
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu-hal --all-features
243+
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} -p wgpu --all-features
215244
245+
# Building for native platforms with standard tests.
216246
- name: check native
217247
if: matrix.kind == 'native'
218248
shell: bash
219249
run: |
220250
set -e
221251
222252
# check with no features
223-
cargo clippy --target ${{ matrix.target }} --no-default-features
253+
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} --no-default-features
224254
225255
# Check with all features.
226-
cargo clippy --target ${{ matrix.target }} --tests --benches --all-features
256+
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} --tests --benches --all-features
227257
228258
# build docs
229-
cargo doc --target ${{ matrix.target }} --all-features --no-deps
259+
cargo doc --target ${{ matrix.target }} ${{ matrix.extra-flags }} --all-features --no-deps
230260
231261
- name: check private item docs
232262
if: matrix.kind == 'native'
@@ -235,7 +265,7 @@ jobs:
235265
set -e
236266
237267
# wgpu_core package
238-
cargo doc --target ${{ matrix.target }} \
268+
cargo doc --target ${{ matrix.target }} ${{ matrix.extra-flags }} \
239269
--package wgpu-core \
240270
--package wgpu-hal \
241271
--package naga \

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ By @wumpf in [#6849](https://github.com/gfx-rs/wgpu/pull/6849).
162162
- Move raytracing alignments into HAL instead of in core. By @Vecvec in [#6563](https://github.com/gfx-rs/wgpu/pull/6563).
163163
- Allow for statically linking DXC rather than including separate `.dll` files. By @DouglasDwyer in [#6574](https://github.com/gfx-rs/wgpu/pull/6574).
164164
- `DeviceType` and `AdapterInfo` now impl `Hash` by @cwfitzgerald in [#6868](https://github.com/gfx-rs/wgpu/pull/6868)
165+
- Add build support for Apple Vision Pro. By @guusw in [#6611](https://github.com/gfx-rs/wgpu/pull/6611).
165166
- Add `wgsl_language_features` for obtaining available WGSL language feature by @sagudev in [#6814](https://github.com/gfx-rs/wgpu/pull/6814)
166167

167168
##### Vulkan
@@ -171,6 +172,7 @@ By @wumpf in [#6849](https://github.com/gfx-rs/wgpu/pull/6849).
171172
##### Metal
172173

173174
- Allow using some 32-bit floating-point atomic operations (load, store, add, sub, exchange) in shaders. It requires Metal 3.0+ with Apple 7, 8, 9 or Mac 2. By @AsherJingkongChen in [#6234](https://github.com/gfx-rs/wgpu/pull/6234).
175+
- Add build support for Apple Vision Pro. By @guusw in [#6611](https://github.com/gfx-rs/wgpu/pull/6611).
174176

175177
#### Changes
176178

deno_webgpu/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ features = [
3636
]
3737

3838
# We want the wgpu-core Metal backend on macOS and iOS.
39-
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies.wgpu-core]
39+
[target.'cfg(target_vendor = "apple")'.dependencies.wgpu-core]
4040
workspace = true
4141
features = ["metal"]
4242

naga/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ fn main() {
33
dot_out: { feature = "dot-out" },
44
glsl_out: { feature = "glsl-out" },
55
hlsl_out: { any(feature = "hlsl-out", all(target_os = "windows", feature = "hlsl-out-if-target-windows")) },
6-
msl_out: { any(feature = "msl-out", all(any(target_os = "ios", target_os = "macos"), feature = "msl-out-if-target-apple")) },
6+
msl_out: { any(feature = "msl-out", all(target_vendor = "apple", feature = "msl-out-if-target-apple")) },
77
spv_out: { feature = "spv-out" },
88
wgsl_out: { feature = "wgsl-out" },
99
}

naga/fuzz/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ arbitrary = { version = "1.4.1", features = ["derive"] }
1515
# See https://github.com/rust-fuzz/libfuzzer/issues/126
1616
libfuzzer-sys = ">0.4.0,<=0.4.7"
1717

18-
[target.'cfg(not(any(target_arch = "wasm32", target_os = "ios")))'.dependencies.naga]
18+
[target.'cfg(not(any(target_arch = "wasm32", target_os = "ios", target_os = "visionos")))'.dependencies.naga]
1919
path = ".."
2020
version = "23.0.0"
2121
features = ["arbitrary", "spv-in", "wgsl-in", "glsl-in"]

naga/xtask/src/validate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ fn collect_validation_jobs(jobs: &mut Vec<Job>, cmd: ValidateSubcommand) -> anyh
150150
| ValidateSubcommand::Spirv
151151
| ValidateSubcommand::Glsl
152152
| ValidateSubcommand::Dot => true,
153-
ValidateSubcommand::Metal => cfg!(any(target_os = "macos", target_os = "ios")),
153+
ValidateSubcommand::Metal => cfg!(target_vendor = "apple"),
154154
// The FXC compiler is only available on Windows.
155155
//
156156
// The DXC compiler can be built and run on any platform,

wgpu-core/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn main() {
77
webgl: { all(target_arch = "wasm32", not(target_os = "emscripten"), gles) },
88
dx12: { all(target_os = "windows", feature = "dx12") },
99
gles: { all(feature = "gles") },
10-
metal: { all(any(target_os = "ios", target_os = "macos"), feature = "metal") },
10+
metal: { all(target_vendor = "apple", feature = "metal") },
1111
vulkan: { all(not(target_arch = "wasm32"), feature = "vulkan") }
1212
}
1313
}

wgpu-core/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#![cfg_attr(
1111
all(
1212
not(all(feature = "vulkan", not(target_arch = "wasm32"))),
13-
not(all(feature = "metal", any(target_os = "macos", target_os = "ios"))),
13+
not(all(feature = "metal", any(target_vendor = "apple"))),
1414
not(all(feature = "dx12", windows)),
1515
not(feature = "gles"),
1616
),

wgpu-hal/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ glutin_wgl_sys = { workspace = true, optional = true }
177177
[target.'cfg(all(windows, not(target_arch = "aarch64")))'.dependencies]
178178
mach-dxcompiler-rs = { workspace = true, optional = true }
179179

180-
[target.'cfg(any(target_os="macos", target_os="ios"))'.dependencies]
180+
[target.'cfg(target_vendor = "apple")'.dependencies]
181181
# backend: Metal
182182
block = { workspace = true, optional = true }
183183

@@ -221,7 +221,7 @@ env_logger.workspace = true
221221
glam.workspace = true # for ray-traced-triangle example
222222
winit.workspace = true # for "halmark" example
223223

224-
[target.'cfg(not(any(target_arch = "wasm32", target_os = "ios")))'.dev-dependencies]
224+
[target.'cfg(not(any(target_arch = "wasm32", target_os = "ios", target_os = "visionos")))'.dev-dependencies]
225225
glutin-winit = { workspace = true, features = [
226226
"egl",
227227
"wgl",

wgpu-hal/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn main() {
99
Emscripten: { all(target_os = "emscripten", gles) },
1010
dx12: { all(target_os = "windows", feature = "dx12") },
1111
gles: { all(feature = "gles") },
12-
metal: { all(any(target_os = "ios", target_os = "macos"), feature = "metal") },
12+
metal: { all(target_vendor = "apple", feature = "metal") },
1313
vulkan: { all(not(target_arch = "wasm32"), feature = "vulkan") },
1414
// ⚠️ Keep in sync with target.cfg() definition in Cargo.toml and cfg_alias in `wgpu` crate ⚠️
1515
static_dxc: { all(target_os = "windows", feature = "static-dxc", not(target_arch = "aarch64")) }

wgpu-hal/examples/halmark/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ impl<A: hal::Api> Example<A> {
797797

798798
cfg_if::cfg_if! {
799799
// Apple + Metal
800-
if #[cfg(all(any(target_os = "macos", target_os = "ios"), feature = "metal"))] {
800+
if #[cfg(all(target_vendor = "apple", feature = "metal"))] {
801801
type Api = hal::api::Metal;
802802
}
803803
// Wasm + Vulkan

wgpu-hal/examples/raw-gles.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
1111
extern crate wgpu_hal as hal;
1212

13-
#[cfg(not(any(target_arch = "wasm32", target_os = "ios")))]
13+
#[cfg(not(any(target_arch = "wasm32", target_os = "ios", target_os = "visionos")))]
1414
fn main() {
1515
use std::{ffi::CString, num::NonZeroU32};
1616

@@ -256,15 +256,17 @@ fn main() {
256256

257257
#[cfg(any(
258258
all(target_arch = "wasm32", not(target_os = "emscripten")),
259-
target_os = "ios"
259+
target_os = "ios",
260+
target_os = "visionos"
260261
))]
261262
fn main() {
262263
eprintln!("This example is not supported on Windows and non-emscripten wasm32")
263264
}
264265

265266
#[cfg(not(any(
266267
all(target_arch = "wasm32", not(target_os = "emscripten")),
267-
target_os = "ios"
268+
target_os = "ios",
269+
target_os = "visionos"
268270
)))]
269271
fn fill_screen(exposed: &hal::ExposedAdapter<hal::api::Gles>, width: u32, height: u32) {
270272
use hal::{Adapter as _, CommandEncoder as _, Device as _, Queue as _};

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ impl<A: hal::Api> Example<A> {
11071107

11081108
cfg_if::cfg_if! {
11091109
// Apple + Metal
1110-
if #[cfg(all(any(target_os = "macos", target_os = "ios"), feature = "metal"))] {
1110+
if #[cfg(all(target_vendor = "apple", feature = "metal"))] {
11111111
type Api = hal::api::Metal;
11121112
}
11131113
// Wasm + Vulkan

wgpu-hal/src/gles/egl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ impl crate::Instance for Instance {
785785
"libEGL.dll",
786786
)
787787
}
788-
} else if cfg!(any(target_os = "macos", target_os = "ios")) {
788+
} else if cfg!(target_vendor = "apple") {
789789
unsafe {
790790
khronos_egl::DynamicInstance::<khronos_egl::EGL1_4>::load_required_from_filename(
791791
"libEGL.dylib",

wgpu-hal/src/metal/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl crate::Instance for Instance {
121121
window_handle: raw_window_handle::RawWindowHandle,
122122
) -> Result<Surface, crate::InstanceError> {
123123
match window_handle {
124-
#[cfg(target_os = "ios")]
124+
#[cfg(any(target_os = "ios", target_os = "visionos"))]
125125
raw_window_handle::RawWindowHandle::UiKit(handle) => {
126126
Ok(unsafe { Surface::from_view(handle.ui_view.cast()) })
127127
}

wgpu-hal/src/vulkan/adapter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ impl PhysicalDeviceProperties {
10031003
}
10041004

10051005
// Require `VK_KHR_portability_subset` on macOS/iOS
1006-
#[cfg(any(target_os = "macos", target_os = "ios"))]
1006+
#[cfg(target_vendor = "apple")]
10071007
extensions.push(khr::portability_subset::NAME);
10081008

10091009
// Require `VK_EXT_texture_compression_astc_hdr` if the associated feature was requested

wgpu-hal/src/vulkan/instance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ impl crate::Instance for super::Instance {
881881
{
882882
self.create_surface_from_view(handle.ns_view)
883883
}
884-
#[cfg(all(target_os = "ios", feature = "metal"))]
884+
#[cfg(all(any(target_os = "ios", target_os = "visionos"), feature = "metal"))]
885885
(Rwh::UiKit(handle), _)
886886
if self.shared.extensions.contains(&ext::metal_surface::NAME) =>
887887
{

wgpu/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ features = ["indirect-validation"]
150150

151151
# Enable `wgc` by default on macOS and iOS to allow the `metal` crate feature to
152152
# enable the Metal backend while being no-op on other targets.
153-
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies.wgc]
153+
[target.'cfg(target_vendor = "apple")'.dependencies.wgc]
154154
workspace = true
155155

156156
# We want the wgpu-core Direct3D backend and OpenGL (via WGL) on Windows.
@@ -159,12 +159,12 @@ workspace = true
159159
features = ["gles"]
160160

161161
# We want the wgpu-core Vulkan backend on Unix (but not emscripten, macOS, iOS) and Windows.
162-
[target.'cfg(any(windows, all(unix, not(target_os = "emscripten"), not(target_os = "ios"), not(target_os = "macos"))))'.dependencies.wgc]
162+
[target.'cfg(any(windows, all(unix, not(target_os = "emscripten"), not(target_vendor = "apple"))))'.dependencies.wgc]
163163
workspace = true
164164
features = ["vulkan"]
165165

166166
# We want the wgpu-core GLES backend on Unix (but not macOS, iOS).
167-
[target.'cfg(all(unix, not(target_os = "ios"), not(target_os = "macos")))'.dependencies.wgc]
167+
[target.'cfg(all(unix, not(target_vendor = "apple")))'.dependencies.wgc]
168168
workspace = true
169169
features = ["gles"]
170170

@@ -175,7 +175,7 @@ workspace = true
175175
[target.'cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))'.dependencies]
176176
hal = { workspace = true }
177177

178-
[target.'cfg(all(not(target_arch = "wasm32"), unix, not(target_os = "ios"), not(target_os = "macos")))'.dependencies]
178+
[target.'cfg(all(not(target_arch = "wasm32"), unix, not(target_vendor = "apple")))'.dependencies]
179179
hal = { workspace = true, features = ["renderdoc"] }
180180

181181
[target.'cfg(windows)'.dependencies]

wgpu/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn main() {
1010
all(feature = "fragile-send-sync-non-atomic-wasm", not(target_feature = "atomics"))
1111
) },
1212
dx12: { all(target_os = "windows", feature = "dx12") },
13-
metal: { all(any(target_os = "ios", target_os = "macos"), feature = "metal") },
13+
metal: { all(target_vendor = "apple", feature = "metal") },
1414
// This alias is _only_ if _we_ need naga in the wrapper. wgpu-core provides
1515
// its own re-export of naga, which can be used in other situations
1616
naga: { any(feature = "naga-ir", feature = "spirv", feature = "glsl") },

wgpu/src/api/instance.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ impl Instance {
8282
}
8383

8484
// Vulkan on Mac/iOS is only available through vulkan-portability.
85-
if (cfg!(target_os = "ios") || cfg!(target_os = "macos"))
86-
&& cfg!(feature = "vulkan-portability")
87-
{
85+
if cfg!(target_vendor = "apple") && cfg!(feature = "vulkan-portability") {
8886
backends = backends.union(Backends::VULKAN);
8987
}
9088

0 commit comments

Comments
 (0)