Skip to content

Commit 5c0a674

Browse files
committed
lib: Replace smol with inner crates to ensure compilation for WASM
1 parent e0f3833 commit 5c0a674

File tree

10 files changed

+117
-79
lines changed

10 files changed

+117
-79
lines changed

Cargo.lock

Lines changed: 5 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ dialoguer = "0.12"
3636
env_logger = "0.11"
3737
eyre = "0.6.5"
3838
futures = "0.3.12"
39+
futures-lite = "2.6"
3940
hex = "0.4.2"
4041
hkdf = "0.12.2"
4142
indicatif = "0.18"
@@ -56,6 +57,11 @@ sha-1 = "0.10.0"
5657
sha2 = "0.10.0"
5758
smol = "2.0"
5859
smol-macros = "0.1"
60+
async-executor = "1.13"
61+
async-fs = "2.0"
62+
async-io = "2.2.0"
63+
async-net = "2.0"
64+
async-task = "4.7"
5965
spake2 = "0.4.0"
6066
stun_codec = "0.4.0"
6167
tar = "0.4.33"
@@ -101,9 +107,9 @@ hex = { workspace = true, features = ["serde"] }
101107
rand = { workspace = true }
102108
base64 = { workspace = true }
103109
time = { workspace = true, features = ["formatting"] }
104-
smol = { workspace = true }
105-
smol-macros = { workspace = true }
110+
async-executor = { workspace = true }
106111
macro_rules_attribute = { workspace = true }
112+
futures-lite = { workspace = true }
107113

108114
derive_more = { workspace = true, features = ["display", "deref", "from"] }
109115
thiserror = { workspace = true }
@@ -126,6 +132,7 @@ noise-rust-crypto = { workspace = true, optional = true }
126132
async-std = { version = "1.12.0", features = ["attributes", "unstable"] }
127133
async-trait = { workspace = true, optional = true }
128134
noise-protocol = { workspace = true, optional = true }
135+
async-task = { workspace = true }
129136
# Transfer dependencies
130137

131138
rmp-serde = { workspace = true, optional = true }
@@ -138,7 +145,9 @@ tar = { workspace = true, optional = true }
138145
[target.'cfg(not(target_family = "wasm"))'.dependencies]
139146
libc = "0.2.101"
140147
async-tungstenite = { version = "0.30", features = ["async-std-runtime"] }
141-
async-io = "2.2.0"
148+
async-io = { workspace = true }
149+
async-net = { workspace = true }
150+
async-fs = { workspace = true }
142151

143152
# Transit
144153

src/core.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl<V: serde::Serialize + Send + Sync + 'static> MailboxConnection<V> {
108108
/// # Examples
109109
///
110110
/// ```no_run
111-
/// # fn main() -> eyre::Result<()> { smol::block_on(async {
111+
/// # fn main() -> eyre::Result<()> { async_io::block_on(async {
112112
/// use magic_wormhole::{AppConfig, MailboxConnection, transfer::APP_CONFIG};
113113
/// let config = APP_CONFIG;
114114
/// let mailbox_connection = MailboxConnection::create(config, 2).await?;
@@ -134,7 +134,7 @@ impl<V: serde::Serialize + Send + Sync + 'static> MailboxConnection<V> {
134134
/// ```no_run
135135
/// # #[cfg(feature = "entropy")]
136136
/// # {
137-
/// # fn main() -> eyre::Result<()> { smol::block_on(async {
137+
/// # fn main() -> eyre::Result<()> { async_io::block_on(async {
138138
/// use magic_wormhole::{MailboxConnection, transfer::APP_CONFIG};
139139
/// let config = APP_CONFIG;
140140
/// let mailbox_connection =
@@ -188,7 +188,7 @@ impl<V: serde::Serialize + Send + Sync + 'static> MailboxConnection<V> {
188188
/// # Examples
189189
///
190190
/// ```no_run
191-
/// # fn main() -> eyre::Result<()> { smol::block_on(async {
191+
/// # fn main() -> eyre::Result<()> { async_io::block_on(async {
192192
/// use magic_wormhole::{Code, MailboxConnection, Nameplate, transfer::APP_CONFIG};
193193
/// let config = APP_CONFIG;
194194
/// let code = "5-password".parse()?;
@@ -235,7 +235,7 @@ impl<V: serde::Serialize + Send + Sync + 'static> MailboxConnection<V> {
235235
/// ```
236236
/// # fn main() -> eyre::Result<()> { use magic_wormhole::WormholeError;
237237
/// # #[cfg(feature = "entropy")]
238-
/// return smol::block_on(async {
238+
/// return async_io::block_on(async {
239239
/// use magic_wormhole::{transfer::APP_CONFIG, MailboxConnection, Mood};
240240
/// let config = APP_CONFIG;
241241
/// let mailbox_connection = MailboxConnection::create_with_password(config, "secret-code-password".parse()?)

src/core/test.rs

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@ use crate::{
1212
};
1313
use test_log::test;
1414

15+
macro_rules! test {
16+
(
17+
$(#[$attr:meta])*
18+
async fn $name:ident () $(-> $ret:ty)? $body:block
19+
) => {
20+
$(#[$attr])*
21+
#[test]
22+
fn $name() $(-> $ret)? {
23+
async_io::block_on(async {
24+
$body
25+
})
26+
}
27+
}
28+
}
29+
1530
pub const TEST_APPID: AppID = AppID(std::borrow::Cow::Borrowed(
1631
"magic-wormhole.github.io/magic-wormhole.rs/test",
1732
));
@@ -30,7 +45,7 @@ const TIMEOUT: Duration = Duration::from_secs(60);
3045
///
3146
/// ```no_run
3247
/// use magic_wormhole as mw;
33-
/// # smol::block_on(async {
48+
/// # async_io::block_on(async {
3449
/// # let derived_key = unimplemented!();
3550
/// # let their_abilities = unimplemented!();
3651
/// # let their_hints = unimplemented!();
@@ -53,7 +68,7 @@ fn default_relay_hints() -> Vec<transit::RelayHint> {
5368
]
5469
}
5570

56-
#[test(macro_rules_attribute::apply(smol_macros::test!))]
71+
#[test(macro_rules_attribute::apply(test!))]
5772
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
5873
async fn test_connect_with_unknown_code_and_allocate_passes() {
5974
let code = generate_random_code();
@@ -70,7 +85,7 @@ async fn test_connect_with_unknown_code_and_allocate_passes() {
7085
.unwrap()
7186
}
7287

73-
#[test(macro_rules_attribute::apply(smol_macros::test!))]
88+
#[test(macro_rules_attribute::apply(test!))]
7489
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
7590
async fn test_connect_with_unknown_code_and_no_allocate_fails() {
7691
tracing::info!("hola!");
@@ -117,7 +132,7 @@ async fn file_offers()
117132
move || {
118133
let data = data.clone();
119134
Box::pin(async move {
120-
Ok(Box::new(smol::io::Cursor::new(data))
135+
Ok(Box::new(async_io::Cursor::new(data))
121136
as Box<
122137
dyn crate::transfer::offer::AsyncReadSeek
123138
+ std::marker::Send
@@ -134,7 +149,7 @@ async fn file_offers()
134149
#[cfg(not(target_family = "wasm"))]
135150
let (data, offer) = {
136151
let path = format!("tests/{name}");
137-
let data = smol::fs::read(&path).await.unwrap();
152+
let data = async_fs::read(&path).await.unwrap();
138153
let offer = transfer::offer::OfferSend::new_file_or_folder(name.into(), &path)
139154
.await
140155
.unwrap();
@@ -227,7 +242,7 @@ async fn file_offers()
227242

228243
/** Send a file using the Rust implementation. This does not guarantee compatibility with Python! ;) */
229244
#[cfg(feature = "transfer")]
230-
#[test(macro_rules_attribute::apply(smol_macros::test!))]
245+
#[test(macro_rules_attribute::apply(test!))]
231246
// TODO Wasm test disabled, it crashes
232247
// #[cfg_attr(target_arch = "wasm32", test(wasm_bindgen_test::wasm_bindgen_test))]
233248
async fn test_file_rust2rust() {
@@ -307,7 +322,7 @@ async fn test_file_rust2rust() {
307322
/** Test the functionality used by the `send-many` subcommand.
308323
*/
309324
#[cfg(feature = "transfer")]
310-
#[test(macro_rules_attribute::apply(smol_macros::test!))]
325+
#[test(macro_rules_attribute::apply(test!))]
311326
// TODO Wasm test disabled, it crashes
312327
// #[cfg_attr(target_arch = "wasm32", test(wasm_bindgen_test::wasm_bindgen_test))]
313328
async fn test_send_many() {
@@ -327,15 +342,15 @@ async fn test_send_many() {
327342

328343
/* Send many */
329344
let sender_code = code.clone();
330-
let senders = smol::spawn(async move {
331-
// let mut senders = Vec::<smol::Task<std::result::Result<std::vec::Vec<u8>, eyre::Error>>>::new();
332-
let mut senders: Vec<smol::Task<eyre::Result<()>>> = Vec::new();
345+
let senders = crate::util::spawn(async move {
346+
// let mut senders = Vec::<async_task::Task<std::result::Result<std::vec::Vec<u8>, eyre::Error>>>::new();
347+
let mut senders: Vec<async_task::Task<eyre::Result<()>>> = Vec::new();
333348

334349
/* The first time, we reuse the current session for sending */
335350
{
336351
tracing::info!("Sending file #{}", 0);
337352
let wormhole = crate::Wormhole::connect(mailbox).await?;
338-
senders.push(smol::spawn(async move {
353+
senders.push(crate::util::spawn(async move {
339354
eyre::Result::Ok(
340355
crate::transfer::send(
341356
wormhole,
@@ -362,7 +377,7 @@ async fn test_send_many() {
362377
.await?,
363378
)
364379
.await?;
365-
senders.push(smol::spawn(async move {
380+
senders.push(crate::util::spawn(async move {
366381
eyre::Result::Ok(
367382
crate::transfer::send(
368383
wormhole,
@@ -381,7 +396,7 @@ async fn test_send_many() {
381396
});
382397

383398
// Sleep one second
384-
smol::Timer::after(std::time::Duration::from_secs(1)).await;
399+
async_io::Timer::after(std::time::Duration::from_secs(1)).await;
385400

386401
/* Receive many */
387402
for i in 0..5usize {
@@ -443,12 +458,12 @@ async fn test_send_many() {
443458
}
444459

445460
/// Try to send a file, but use a bad code, and see how it's handled
446-
#[test(macro_rules_attribute::apply(smol_macros::test!))]
461+
#[test(macro_rules_attribute::apply(test!))]
447462
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
448463
async fn test_wrong_code() {
449464
let (code_tx, code_rx) = futures::channel::oneshot::channel();
450465

451-
let sender_task = smol::spawn(async {
466+
let sender_task = crate::util::spawn(async {
452467
let mailbox = MailboxConnection::create(APP_CONFIG, 2).await.unwrap();
453468
if let Some(welcome) = &mailbox.welcome {
454469
tracing::info!("Got welcome: {}", welcome);
@@ -463,7 +478,7 @@ async fn test_wrong_code() {
463478
eyre::Result::<_>::Ok(())
464479
});
465480

466-
let receiver_task = smol::spawn(async {
481+
let receiver_task = crate::util::spawn(async {
467482
let nameplate = code_rx.await?;
468483
tracing::info!("Got nameplate over local: {}", &nameplate);
469484
let result = crate::Wormhole::connect(
@@ -488,7 +503,7 @@ async fn test_wrong_code() {
488503
}
489504

490505
/** Connect three people to the party and watch it explode … gracefully */
491-
#[test(macro_rules_attribute::apply(smol_macros::test!))]
506+
#[test(macro_rules_attribute::apply(test!))]
492507
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
493508
async fn test_crowded() {
494509
let initial_mailbox_connection = MailboxConnection::create(APP_CONFIG, 2).await.unwrap();
@@ -511,7 +526,7 @@ async fn test_crowded() {
511526
}
512527
}
513528

514-
#[macro_rules_attribute::apply(smol_macros::test!)]
529+
#[macro_rules_attribute::apply(test!)]
515530
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
516531
async fn test_connect_with_code_expecting_nameplate() {
517532
let code = generate_random_code();

0 commit comments

Comments
 (0)