Use target family insted of target arch (#2975)

* Replace cfg target_arch wasm32 with target_family wasm

* Fix warnings in test builds from previous pr
This commit is contained in:
Timon
2025-08-03 10:28:53 +00:00
committed by GitHub
parent 1e3c3da3fe
commit 67123f55dc
18 changed files with 106 additions and 96 deletions
@@ -1,35 +1,35 @@
use dyn_any::StaticType;
use graphene_application_io::{ApplicationError, ApplicationIo, ResourceFuture, SurfaceHandle, SurfaceId};
#[cfg(target_arch = "wasm32")]
#[cfg(target_family = "wasm")]
use js_sys::{Object, Reflect};
use std::collections::HashMap;
use std::hash::Hash;
use std::sync::Arc;
#[cfg(target_arch = "wasm32")]
#[cfg(target_family = "wasm")]
use std::sync::atomic::AtomicU64;
use std::sync::atomic::Ordering;
#[cfg(feature = "tokio")]
use tokio::io::AsyncReadExt;
#[cfg(target_arch = "wasm32")]
#[cfg(target_family = "wasm")]
use wasm_bindgen::JsCast;
#[cfg(target_arch = "wasm32")]
#[cfg(target_family = "wasm")]
use wasm_bindgen::JsValue;
#[cfg(target_arch = "wasm32")]
#[cfg(target_family = "wasm")]
use web_sys::HtmlCanvasElement;
#[cfg(target_arch = "wasm32")]
#[cfg(target_family = "wasm")]
use web_sys::window;
#[cfg(feature = "wgpu")]
use wgpu_executor::WgpuExecutor;
#[derive(Debug)]
struct WindowWrapper {
#[cfg(target_arch = "wasm32")]
#[cfg(target_family = "wasm")]
window: SurfaceHandle<HtmlCanvasElement>,
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_family = "wasm"))]
window: SurfaceHandle<Arc<winit::window::Window>>,
}
#[cfg(target_arch = "wasm32")]
#[cfg(target_family = "wasm")]
impl Drop for WindowWrapper {
fn drop(&mut self) {
let window = window().expect("should have a window in this context");
@@ -52,14 +52,14 @@ impl Drop for WindowWrapper {
}
}
#[cfg(target_arch = "wasm32")]
#[cfg(target_family = "wasm")]
unsafe impl Sync for WindowWrapper {}
#[cfg(target_arch = "wasm32")]
#[cfg(target_family = "wasm")]
unsafe impl Send for WindowWrapper {}
#[derive(Debug, Default)]
pub struct WasmApplicationIo {
#[cfg(target_arch = "wasm32")]
#[cfg(target_family = "wasm")]
ids: AtomicU64,
#[cfg(feature = "wgpu")]
pub(crate) gpu_executor: Option<WgpuExecutor>,
@@ -79,7 +79,7 @@ pub fn wgpu_available() -> Option<bool> {
impl WasmApplicationIo {
pub async fn new() -> Self {
#[cfg(all(feature = "wgpu", target_arch = "wasm32"))]
#[cfg(all(feature = "wgpu", target_family = "wasm"))]
let executor = if let Some(gpu) = web_sys::window().map(|w| w.navigator().gpu()) {
let request_adapter = || {
let request_adapter = js_sys::Reflect::get(&gpu, &wasm_bindgen::JsValue::from_str("requestAdapter")).ok()?;
@@ -95,7 +95,7 @@ impl WasmApplicationIo {
None
};
#[cfg(all(feature = "wgpu", not(target_arch = "wasm32")))]
#[cfg(all(feature = "wgpu", not(target_family = "wasm")))]
let executor = WgpuExecutor::new().await;
#[cfg(not(feature = "wgpu"))]
@@ -105,7 +105,7 @@ impl WasmApplicationIo {
WGPU_AVAILABLE.store(wgpu_available as i8, Ordering::SeqCst);
let mut io = Self {
#[cfg(target_arch = "wasm32")]
#[cfg(target_family = "wasm")]
ids: AtomicU64::new(0),
#[cfg(feature = "wgpu")]
gpu_executor: executor,
@@ -130,7 +130,7 @@ impl WasmApplicationIo {
WGPU_AVAILABLE.store(wgpu_available as i8, Ordering::SeqCst);
let mut io = Self {
#[cfg(target_arch = "wasm32")]
#[cfg(target_family = "wasm")]
ids: AtomicU64::new(0),
#[cfg(feature = "wgpu")]
gpu_executor: executor,
@@ -142,7 +142,7 @@ impl WasmApplicationIo {
io
}
#[cfg(all(not(target_arch = "wasm32"), feature = "wgpu"))]
#[cfg(all(not(target_family = "wasm"), feature = "wgpu"))]
pub fn new_with_context(context: wgpu_executor::Context) -> Self {
#[cfg(feature = "wgpu")]
let executor = WgpuExecutor::with_context(context);
@@ -184,16 +184,16 @@ impl<'a> From<&'a WasmApplicationIo> for &'a WgpuExecutor {
pub type WasmEditorApi = graphene_application_io::EditorApi<WasmApplicationIo>;
impl ApplicationIo for WasmApplicationIo {
#[cfg(target_arch = "wasm32")]
#[cfg(target_family = "wasm")]
type Surface = HtmlCanvasElement;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_family = "wasm"))]
type Surface = Arc<winit::window::Window>;
#[cfg(feature = "wgpu")]
type Executor = WgpuExecutor;
#[cfg(not(feature = "wgpu"))]
type Executor = ();
#[cfg(target_arch = "wasm32")]
#[cfg(target_family = "wasm")]
fn create_window(&self) -> SurfaceHandle<Self::Surface> {
let wrapper = || {
let document = window().expect("should have a window in this context").document().expect("window should have a document");
@@ -228,7 +228,7 @@ impl ApplicationIo for WasmApplicationIo {
wrapper().expect("should be able to set canvas in global scope")
}
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_family = "wasm"))]
fn create_window(&self) -> SurfaceHandle<Self::Surface> {
todo!("winit api changed, calling create_window on EventLoop is deprecated");
@@ -256,7 +256,7 @@ impl ApplicationIo for WasmApplicationIo {
// }
}
#[cfg(target_arch = "wasm32")]
#[cfg(target_family = "wasm")]
fn destroy_window(&self, surface_id: SurfaceId) {
let window = window().expect("should have a window in this context");
let window = Object::from(window);
@@ -277,7 +277,7 @@ impl ApplicationIo for WasmApplicationIo {
wrapper().expect("should be able to set canvas in global scope")
}
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_family = "wasm"))]
fn destroy_window(&self, _surface_id: SurfaceId) {}
#[cfg(feature = "wgpu")]
@@ -346,9 +346,9 @@ impl graphene_application_io::GetEditorPreferences for EditorPreferences {
impl Default for EditorPreferences {
fn default() -> Self {
Self {
#[cfg(target_arch = "wasm32")]
#[cfg(target_family = "wasm")]
use_vello: false,
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(target_family = "wasm"))]
use_vello: true,
}
}