From 6f8936bb38fa734a4a56e8ab11e65b75ac2a3adf Mon Sep 17 00:00:00 2001 From: Ido Date: Sat, 10 Aug 2024 13:32:55 +0300 Subject: [PATCH] Target family macros for wasm and no wasm runtimes --- flutter_ffi_plugin/template/native/hub/Cargo.toml | 9 ++++++--- flutter_ffi_plugin/template/native/hub/src/lib.rs | 8 ++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/flutter_ffi_plugin/template/native/hub/Cargo.toml b/flutter_ffi_plugin/template/native/hub/Cargo.toml index 95ebfc3d..14ec98a6 100644 --- a/flutter_ffi_plugin/template/native/hub/Cargo.toml +++ b/flutter_ffi_plugin/template/native/hub/Cargo.toml @@ -14,8 +14,11 @@ crate-type = ["lib", "cdylib", "staticlib"] [dependencies] rinf = "6.15.0" prost = "0.12.6" + +[target.'cfg(not(target_family = "wasm"))'.dependencies] tokio = { version = "1", features = ["sync", "rt"] } -# Uncomment below to target the web. -# tokio_with_wasm = { version = "0.6.0", features = ["sync", "rt"] } -# wasm-bindgen = "0.2.92" +# Web +[target.'cfg(target_family = "wasm")'.dependencies] +tokio_with_wasm = { version = "0.6.0", features = ["sync", "rt"] } +wasm-bindgen = { version = "0.2.92" } diff --git a/flutter_ffi_plugin/template/native/hub/src/lib.rs b/flutter_ffi_plugin/template/native/hub/src/lib.rs index 60f4aa22..38166bbe 100644 --- a/flutter_ffi_plugin/template/native/hub/src/lib.rs +++ b/flutter_ffi_plugin/template/native/hub/src/lib.rs @@ -5,8 +5,12 @@ mod common; mod messages; use crate::common::*; -use tokio; // Comment this line to target the web. -// use tokio_with_wasm::alias as tokio; // Uncomment this line to target the web. + +#[cfg(not(target_family = "wasm"))] +use tokio; + +#[cfg(target_family = "wasm")] +use tokio_with_wasm::alias as tokio; rinf::write_interface!();