Skip to content

Commit 67123f5

Browse files
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
1 parent 1e3c3da commit 67123f5

File tree

18 files changed

+106
-96
lines changed

18 files changed

+106
-96
lines changed

editor/src/messages/frontend/frontend_message.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use graphene_std::raster::Image;
1313
use graphene_std::raster::color::Color;
1414
use graphene_std::text::{Font, TextAlign};
1515

16-
#[cfg(not(target_arch = "wasm32"))]
16+
#[cfg(not(target_family = "wasm"))]
1717
use crate::messages::portfolio::document::overlays::utility_types::OverlayContext;
1818

1919
#[impl_message(Message, Frontend)]
@@ -322,7 +322,7 @@ pub enum FrontendMessage {
322322
UpdateViewportHolePunch {
323323
active: bool,
324324
},
325-
#[cfg(not(target_arch = "wasm32"))]
325+
#[cfg(not(target_family = "wasm"))]
326326
RenderOverlays(
327327
#[serde(skip, default = "OverlayContext::default")]
328328
#[derivative(Debug = "ignore", PartialEq = "ignore")]

editor/src/messages/portfolio/document/node_graph/document_node_definitions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
591591
description: Cow::Borrowed("Creates a new canvas object."),
592592
properties: None,
593593
},
594-
#[cfg(all(feature = "gpu", target_arch = "wasm32"))]
594+
#[cfg(all(feature = "gpu", target_family = "wasm"))]
595595
DocumentNodeDefinition {
596596
identifier: "Rasterize",
597597
category: "Raster",

editor/src/messages/portfolio/document/overlays/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pub mod grid_overlays;
22
mod overlays_message;
33
mod overlays_message_handler;
44
pub mod utility_functions;
5-
#[cfg_attr(not(target_arch = "wasm32"), path = "utility_types_vello.rs")]
5+
#[cfg_attr(not(target_family = "wasm"), path = "utility_types_vello.rs")]
66
pub mod utility_types;
77

88
#[doc(inline)]

editor/src/messages/portfolio/document/overlays/overlays_message_handler.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,24 @@ pub struct OverlaysMessageContext<'a> {
1111
#[derive(Debug, Clone, Default, ExtractField)]
1212
pub struct OverlaysMessageHandler {
1313
pub overlay_providers: HashSet<OverlayProvider>,
14-
#[cfg(target_arch = "wasm32")]
14+
#[cfg(target_family = "wasm")]
1515
canvas: Option<web_sys::HtmlCanvasElement>,
16-
#[cfg(target_arch = "wasm32")]
16+
#[cfg(target_family = "wasm")]
1717
context: Option<web_sys::CanvasRenderingContext2d>,
1818
}
1919

2020
#[message_handler_data]
2121
impl MessageHandler<OverlaysMessage, OverlaysMessageContext<'_>> for OverlaysMessageHandler {
2222
fn process_message(&mut self, message: OverlaysMessage, responses: &mut VecDeque<Message>, context: OverlaysMessageContext) {
23-
let OverlaysMessageContext { visibility_settings, ipp, .. } = context;
24-
let device_pixel_ratio = context.device_pixel_ratio;
23+
let OverlaysMessageContext {
24+
visibility_settings,
25+
ipp,
26+
device_pixel_ratio,
27+
..
28+
} = context;
2529

2630
match message {
27-
#[cfg(target_arch = "wasm32")]
31+
#[cfg(target_family = "wasm")]
2832
OverlaysMessage::Draw => {
2933
use super::utility_functions::overlay_canvas_element;
3034
use super::utility_types::OverlayContext;
@@ -68,11 +72,10 @@ impl MessageHandler<OverlaysMessage, OverlaysMessageContext<'_>> for OverlaysMes
6872
}
6973
}
7074
}
71-
#[cfg(test)]
72-
OverlaysMessage::Draw => {}
73-
#[cfg(all(not(target_arch = "wasm32"), not(test)))]
75+
#[cfg(all(not(target_family = "wasm"), not(test)))]
7476
OverlaysMessage::Draw => {
7577
use super::utility_types::OverlayContext;
78+
7679
let size = ipp.viewport_bounds.size();
7780

7881
let overlay_context = OverlayContext::new(size, device_pixel_ratio, visibility_settings);
@@ -86,6 +89,13 @@ impl MessageHandler<OverlaysMessage, OverlaysMessageContext<'_>> for OverlaysMes
8689
}
8790
responses.add(FrontendMessage::RenderOverlays(overlay_context));
8891
}
92+
#[cfg(all(not(target_family = "wasm"), test))]
93+
OverlaysMessage::Draw => {
94+
// Removes unused warnings in test builds
95+
drop(responses);
96+
drop(context);
97+
drop(super::utility_types::OverlayContext::new(ipp.viewport_bounds.size(), device_pixel_ratio, visibility_settings));
98+
}
8999
OverlaysMessage::AddProvider(message) => {
90100
self.overlay_providers.insert(message);
91101
}

editor/src/messages/portfolio/document/utility_types/network_interface.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,13 +1424,13 @@ impl NodeNetworkInterface {
14241424
.any(|id| id == potentially_upstream_node)
14251425
}
14261426

1427-
#[cfg(not(target_arch = "wasm32"))]
1427+
#[cfg(not(target_family = "wasm"))]
14281428
fn text_width(&self, node_id: &NodeId, network_path: &[NodeId]) -> Option<f64> {
14291429
warn!("Failed to find width of {node_id:#?} in network_path {network_path:?} due to non-wasm arch");
14301430
Some(0.)
14311431
}
14321432

1433-
#[cfg(target_arch = "wasm32")]
1433+
#[cfg(target_family = "wasm")]
14341434
fn text_width(&self, node_id: &NodeId, network_path: &[NodeId]) -> Option<f64> {
14351435
let document = web_sys::window().unwrap().document().unwrap();
14361436
let div = match document.create_element("div") {

editor/src/messages/portfolio/portfolio_message_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageContext<'_>> for Portfolio
962962
responses.add(FrontendMessage::UpdateOpenDocumentsList { open_documents });
963963
}
964964
PortfolioMessage::UpdateVelloPreference => {
965-
let active = if cfg!(target_arch = "wasm32") { false } else { preferences.use_vello };
965+
let active = if cfg!(target_family = "wasm") { false } else { preferences.use_vello };
966966
responses.add(FrontendMessage::UpdateViewportHolePunch { active });
967967
responses.add(NodeGraphMessage::RunDocumentGraph);
968968
self.persistent_data.use_vello = preferences.use_vello;

editor/src/node_graph_executor/runtime.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ impl NodeRuntime {
134134
pub async fn run(&mut self) -> Option<ImageTexture> {
135135
if self.editor_api.application_io.is_none() {
136136
self.editor_api = WasmEditorApi {
137-
#[cfg(all(not(test), target_arch = "wasm32"))]
137+
#[cfg(all(not(test), target_family = "wasm"))]
138138
application_io: Some(WasmApplicationIo::new().await.into()),
139-
#[cfg(any(test, not(target_arch = "wasm32")))]
139+
#[cfg(any(test, not(target_family = "wasm")))]
140140
application_io: Some(WasmApplicationIo::new_offscreen().await.into()),
141141
font_cache: self.editor_api.font_cache.clone(),
142142
node_graph_message_sender: Box::new(self.sender.clone()),

libraries/dyn-any/src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -363,31 +363,31 @@ fn simple_downcast_panic() {
363363
assert_eq!(*downcast::<u32>(x).expect("attempted to perform invalid downcast"), 3_u32);
364364
}
365365

366-
#[cfg(not(target_arch = "wasm32"))]
366+
#[cfg(not(target_family = "wasm"))]
367367
pub trait WasmNotSend: Send {}
368-
#[cfg(target_arch = "wasm32")]
368+
#[cfg(target_family = "wasm")]
369369
pub trait WasmNotSend {}
370370

371-
#[cfg(not(target_arch = "wasm32"))]
371+
#[cfg(not(target_family = "wasm"))]
372372
impl<T: Send> WasmNotSend for T {}
373373

374-
#[cfg(target_arch = "wasm32")]
374+
#[cfg(target_family = "wasm")]
375375
impl<T> WasmNotSend for T {}
376376

377-
#[cfg(not(target_arch = "wasm32"))]
377+
#[cfg(not(target_family = "wasm"))]
378378
pub trait WasmNotSync: Sync {}
379-
#[cfg(target_arch = "wasm32")]
379+
#[cfg(target_family = "wasm")]
380380
pub trait WasmNotSync {}
381381

382-
#[cfg(not(target_arch = "wasm32"))]
382+
#[cfg(not(target_family = "wasm"))]
383383
impl<T: Sync> WasmNotSync for T {}
384384

385-
#[cfg(target_arch = "wasm32")]
385+
#[cfg(target_family = "wasm")]
386386
impl<T> WasmNotSync for T {}
387387

388-
#[cfg(not(target_arch = "wasm32"))]
388+
#[cfg(not(target_family = "wasm"))]
389389
#[cfg(feature = "alloc")]
390390
pub type DynFuture<'n, T> = Pin<Box<dyn core::future::Future<Output = T> + 'n + Send>>;
391-
#[cfg(target_arch = "wasm32")]
391+
#[cfg(target_family = "wasm")]
392392
#[cfg(feature = "alloc")]
393393
pub type DynFuture<'n, T> = Pin<Box<dyn core::future::Future<Output = T> + 'n>>;

node-graph/gapplication-io/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub trait Size {
4242
fn size(&self) -> UVec2;
4343
}
4444

45-
#[cfg(target_arch = "wasm32")]
45+
#[cfg(target_family = "wasm")]
4646
impl Size for web_sys::HtmlCanvasElement {
4747
fn size(&self) -> UVec2 {
4848
UVec2::new(self.width(), self.height())
@@ -115,9 +115,9 @@ pub struct SurfaceHandle<Surface> {
115115
pub surface: Surface,
116116
}
117117

118-
// #[cfg(target_arch = "wasm32")]
118+
// #[cfg(target_family = "wasm")]
119119
// unsafe impl<T: dyn_any::WasmNotSend> Send for SurfaceHandle<T> {}
120-
// #[cfg(target_arch = "wasm32")]
120+
// #[cfg(target_family = "wasm")]
121121
// unsafe impl<T: dyn_any::WasmNotSync> Sync for SurfaceHandle<T> {}
122122

123123
impl<S: Size> Size for SurfaceHandle<S> {
@@ -153,9 +153,9 @@ impl<'a, Surface> Drop for SurfaceHandle<'a, Surface> {
153153
}
154154
}*/
155155

156-
#[cfg(target_arch = "wasm32")]
156+
#[cfg(target_family = "wasm")]
157157
pub type ResourceFuture = Pin<Box<dyn Future<Output = Result<Arc<[u8]>, ApplicationError>>>>;
158-
#[cfg(not(target_arch = "wasm32"))]
158+
#[cfg(not(target_family = "wasm"))]
159159
pub type ResourceFuture = Pin<Box<dyn Future<Output = Result<Arc<[u8]>, ApplicationError>> + Send>>;
160160

161161
pub trait ApplicationIo {

node-graph/gcore/src/registry.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,20 @@ pub static NODE_REGISTRY: NodeRegistry = LazyLock::new(|| Mutex::new(HashMap::ne
5656

5757
pub static NODE_METADATA: LazyLock<Mutex<HashMap<ProtoNodeIdentifier, NodeMetadata>>> = LazyLock::new(|| Mutex::new(HashMap::new()));
5858

59-
#[cfg(not(target_arch = "wasm32"))]
59+
#[cfg(not(target_family = "wasm"))]
6060
pub type DynFuture<'n, T> = Pin<Box<dyn Future<Output = T> + 'n + Send>>;
61-
#[cfg(target_arch = "wasm32")]
61+
#[cfg(target_family = "wasm")]
6262
pub type DynFuture<'n, T> = Pin<Box<dyn std::future::Future<Output = T> + 'n>>;
6363
pub type LocalFuture<'n, T> = Pin<Box<dyn Future<Output = T> + 'n>>;
64-
#[cfg(not(target_arch = "wasm32"))]
64+
#[cfg(not(target_family = "wasm"))]
6565
pub type Any<'n> = Box<dyn DynAny<'n> + 'n + Send>;
66-
#[cfg(target_arch = "wasm32")]
66+
#[cfg(target_family = "wasm")]
6767
pub type Any<'n> = Box<dyn DynAny<'n> + 'n>;
6868
pub type FutureAny<'n> = DynFuture<'n, Any<'n>>;
6969
// TODO: is this safe? This is assumed to be send+sync.
70-
#[cfg(not(target_arch = "wasm32"))]
70+
#[cfg(not(target_family = "wasm"))]
7171
pub type TypeErasedNode<'n> = dyn for<'i> NodeIO<'i, Any<'i>, Output = FutureAny<'i>> + 'n + Send + Sync;
72-
#[cfg(target_arch = "wasm32")]
72+
#[cfg(target_family = "wasm")]
7373
pub type TypeErasedNode<'n> = dyn for<'i> NodeIO<'i, Any<'i>, Output = FutureAny<'i>> + 'n;
7474
pub type TypeErasedPinnedRef<'n> = Pin<&'n TypeErasedNode<'n>>;
7575
pub type TypeErasedRef<'n> = &'n TypeErasedNode<'n>;

0 commit comments

Comments
 (0)