From 9e9612cf1f58be11f3944296baef16ecd59b15a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bel=C3=A9n=20Albeza?= Date: Tue, 15 Apr 2025 16:14:21 +0200 Subject: [PATCH] :bug: Fix broken test build for rust wasm --- render-wasm/src/performance.rs | 4 ++++ render-wasm/src/wapi.rs | 32 +++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/render-wasm/src/performance.rs b/render-wasm/src/performance.rs index b1198f662..b19fafa0e 100644 --- a/render-wasm/src/performance.rs +++ b/render-wasm/src/performance.rs @@ -1,3 +1,7 @@ +#[allow(unused_imports)] +#[cfg(target_arch = "wasm32")] +use crate::get_now; + #[allow(dead_code)] #[cfg(target_arch = "wasm32")] pub fn get_time() -> i32 { diff --git a/render-wasm/src/wapi.rs b/render-wasm/src/wapi.rs index ace2a2072..92e03d82c 100644 --- a/render-wasm/src/wapi.rs +++ b/render-wasm/src/wapi.rs @@ -1,25 +1,35 @@ #[macro_export] macro_rules! request_animation_frame { - () => { + () => {{ #[cfg(target_arch = "wasm32")] - { - extern "C" { - pub fn wapi_requestAnimationFrame() -> i32; - } - unsafe { wapi_requestAnimationFrame() } + unsafe extern "C" { + pub fn wapi_requestAnimationFrame() -> i32; } - }; + + #[cfg(target_arch = "wasm32")] + let result = unsafe { wapi_requestAnimationFrame() }; + #[cfg(not(target_arch = "wasm32"))] + let result = 0; + + result + }}; } #[macro_export] macro_rules! cancel_animation_frame { ($frame_id:expr) => { #[cfg(target_arch = "wasm32")] + unsafe extern "C" { + pub fn wapi_cancelAnimationFrame(frame_id: i32); + } + { - extern "C" { - pub fn wapi_cancelAnimationFrame(frame_id: i32); - } - unsafe { wapi_cancelAnimationFrame($frame_id) } + #[cfg(target_arch = "wasm32")] + unsafe { + wapi_cancelAnimationFrame($frame_id) + }; + #[cfg(not(target_arch = "wasm32"))] + let _ = $frame_id; } }; }