From 40ab00aa0870bae7321c87b30cd5c18ccf846dbc Mon Sep 17 00:00:00 2001 From: satan Date: Tue, 19 Sep 2023 10:48:31 +0200 Subject: [PATCH] [fix]: Fixed removing tokio dep from wasm targeted builds --- Cargo.lock | 6 +++--- shared/src/types/io.rs | 30 +++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e100cceb45..f6099f4871 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4026,14 +4026,14 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.6" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" +checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" dependencies = [ "libc", "log", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] diff --git a/shared/src/types/io.rs b/shared/src/types/io.rs index 13798cc5b2..462dbef95f 100644 --- a/shared/src/types/io.rs +++ b/shared/src/types/io.rs @@ -42,18 +42,41 @@ pub trait Io { eprintln!("{}", output.as_ref()); } - async fn read() -> tokio::io::Result { - read_aux(tokio::io::stdin()).await + async fn read() -> std::io::Result { + #[cfg(not(target_family = "wasm"))] + { + read_aux(tokio::io::stdin()).await + } + #[cfg(target_family = "wasm")] + { + unreachable!("Wasm should not perform general IO") + } } async fn prompt(question: impl AsRef) -> String { - prompt_aux(tokio::io::stdin(), tokio::io::stdout(), question.as_ref()) + #[cfg(not(target_family = "wasm"))] + { + prompt_aux( + tokio::io::stdin(), + tokio::io::stdout(), + question.as_ref(), + ) .await + } + #[cfg(target_family = "wasm")] + { + unreachable!( + "Wasm should not perform general IO; received call for input \ + with question\n: {}", + question.as_ref() + ) + } } } /// A generic function for displaying a prompt to users and reading /// in their response. +#[cfg(not(target_family = "wasm"))] pub async fn prompt_aux( mut reader: R, mut writer: W, @@ -74,6 +97,7 @@ where } /// A generic function for reading input from users +#[cfg(not(target_family = "wasm"))] pub async fn read_aux(mut reader: R) -> tokio::io::Result where R: tokio::io::AsyncReadExt + Unpin,