Coverage Report

Created: 2026-01-25 15:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/home/noah/src/trueno/src/backends/gpu/runtime.rs
Line
Count
Source
1
//! Cross-platform async runtime helpers for GPU operations.
2
//!
3
//! - Native: Uses `pollster::block_on` for sync wrappers
4
//! - WASM: Sync wrappers unavailable; use async methods directly
5
6
/// Block on async code (native only).
7
///
8
/// On WASM, this function is not available - use async methods directly
9
/// with `wasm_bindgen_futures::spawn_local` or await.
10
#[cfg(all(feature = "gpu", not(target_arch = "wasm32")))]
11
640
pub fn block_on<F: std::future::Future>(f: F) -> F::Output {
12
640
    pollster::block_on(f)
13
640
}
14
15
/// Check if sync GPU operations are available.
16
///
17
/// Returns `true` on native platforms, `false` on WASM.
18
#[cfg(not(target_arch = "wasm32"))]
19
0
pub const fn sync_available() -> bool {
20
0
    true
21
0
}
22
23
#[cfg(target_arch = "wasm32")]
24
pub const fn sync_available() -> bool {
25
    false
26
}
27
28
/// Spawn async task for WASM.
29
#[cfg(all(feature = "gpu-wasm", target_arch = "wasm32"))]
30
pub fn spawn_local<F>(f: F)
31
where
32
    F: std::future::Future<Output = ()> + 'static,
33
{
34
    wasm_bindgen_futures::spawn_local(f);
35
}
36
37
/// Log to console (WASM).
38
#[cfg(all(feature = "gpu-wasm", target_arch = "wasm32"))]
39
pub fn console_log(s: &str) {
40
    web_sys::console::log_1(&s.into());
41
}
42
43
#[cfg(not(target_arch = "wasm32"))]
44
0
pub fn console_log(s: &str) {
45
0
    eprintln!("{}", s);
46
0
}