Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite9cb238

Browse files
fix wasm and nostd builds
Co-authored-by: Jacob Rothstein <hi@jbr.me>
1 parent6a6623c commite9cb238

File tree

6 files changed

+65
-37
lines changed

6 files changed

+65
-37
lines changed

‎.github/workflows/ci.yml

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,6 @@ jobs:
2929
toolchain:${{ matrix.rust }}
3030
override:true
3131

32-
-name:Cache cargo registry
33-
uses:actions/cache@v2
34-
with:
35-
path:~/.cargo/registry
36-
key:${{ matrix.os }}-${{ matrix.rust }}-cargo-registry-${{ hashFiles('**/Cargo.toml') }}
37-
38-
-name:Cache cargo index
39-
uses:actions/cache@v2
40-
with:
41-
path:~/.cargo/git
42-
key:${{ matrix.os }}-${{ matrix.rust }}-cargo-index-${{ hashFiles('**/Cargo.toml') }}
43-
44-
-name:Cache cargo build
45-
uses:actions/cache@v2
46-
with:
47-
path:target
48-
key:${{ matrix.os }}-${{ matrix.rust }}-cargo-build-target-${{ hashFiles('**/Cargo.toml') }}
49-
5032
-name:check
5133
uses:actions-rs/cargo@v1
5234
with:
@@ -160,6 +142,41 @@ jobs:
160142
-name:test
161143
run:cross test --all --features unstable --target ${{ matrix.target }}
162144

145+
check_wasm:
146+
name:Check wasm targets
147+
runs-on:ubuntu-latest
148+
strategy:
149+
matrix:
150+
rust:[nightly, beta, stable]
151+
152+
steps:
153+
-uses:actions/checkout@master
154+
155+
-name:Install rust with wasm32-unknown-unknown
156+
uses:actions-rs/toolchain@v1
157+
with:
158+
toolchain:${{ matrix.rust }}
159+
target:wasm32-unknown-unknown
160+
override:true
161+
162+
-name:Cache cargo registry
163+
uses:actions/cache@v2
164+
with:
165+
path:~/.cargo/registry
166+
key:wasm32-${{ matrix.rust }}-cargo-registry-${{ hashFiles('**/Cargo.toml') }}
167+
168+
-name:check
169+
uses:actions-rs/cargo@v1
170+
with:
171+
command:check
172+
args:--target wasm32-unknown-unknown
173+
174+
-name:check unstable
175+
uses:actions-rs/cargo@v1
176+
with:
177+
command:check
178+
args:--target wasm32-unknown-unknown --tests --all --features unstable
179+
163180
check_fmt_and_docs:
164181
name:Checking fmt and docs
165182
runs-on:ubuntu-latest

‎Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ default = [
3333
"log",
3434
"num_cpus",
3535
"pin-project-lite",
36+
"gloo-timers",
3637
]
3738
docs = ["attributes","unstable","default"]
3839
unstable = [
3940
"std",
40-
"futures-timer",
41+
"async-io"
4142
]
4243
attributes = ["async-attributes"]
4344
std = [
@@ -74,7 +75,6 @@ once_cell = { version = "1.3.1", optional = true }
7475
pin-project-lite = {version ="0.1.4",optional =true }
7576
pin-utils = {version ="0.1.0-alpha.4",optional =true }
7677
slab = {version ="0.4.2",optional =true }
77-
futures-timer = {version ="3.0.2",optional =true }
7878

7979
# Devdepencency, but they are not allowed to be optional :/
8080
surf = {version ="1.0.3",optional =true }
@@ -86,7 +86,7 @@ blocking = { version = "1.0.0", optional = true }
8686
futures-lite = {version ="1.0.0",optional =true }
8787

8888
[target.'cfg(target_arch="wasm32")'.dependencies]
89-
futures-timer = {version ="3.0.2",optional =true,features = ["wasm-bindgen"] }
89+
gloo-timers = {version ="0.2.1",features = ["futures"],optional =true }
9090
wasm-bindgen-futures = {version ="0.4.10",optional =true }
9191
futures-channel = {version ="0.3.4",optional =true }
9292

‎src/task/builder.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::cell::Cell;
21
use std::future::Future;
32
use std::pin::Pin;
43
use std::sync::Arc;
@@ -7,7 +6,7 @@ use std::task::{Context, Poll};
76
use pin_project_lite::pin_project;
87

98
usecrate::io;
10-
usecrate::task::{self,JoinHandle,Task,TaskLocalsWrapper};
9+
usecrate::task::{JoinHandle,Task,TaskLocalsWrapper};
1110

1211
/// Task builder that configures the settings of a new task.
1312
#[derive(Debug,Default)]
@@ -61,7 +60,7 @@ impl Builder {
6160
});
6261

6362
let task = wrapped.tag.task().clone();
64-
let handle = task::executor::spawn(wrapped);
63+
let handle =crate::task::executor::spawn(wrapped);
6564

6665
Ok(JoinHandle::new(handle, task))
6766
}
@@ -81,7 +80,7 @@ impl Builder {
8180
});
8281

8382
let task = wrapped.tag.task().clone();
84-
let handle = task::executor::local(wrapped);
83+
let handle =crate::task::executor::local(wrapped);
8584

8685
Ok(JoinHandle::new(handle, task))
8786
}
@@ -143,6 +142,8 @@ impl Builder {
143142
where
144143
F:Future<Output =T>,
145144
{
145+
use std::cell::Cell;
146+
146147
let wrapped =self.build(future);
147148

148149
// Log this `block_on` operation.
@@ -167,7 +168,7 @@ impl Builder {
167168
TaskLocalsWrapper::set_current(&wrapped.tag, ||{
168169
let res =if should_run{
169170
// The first call should run the executor
170-
task::executor::run(wrapped)
171+
crate::task::executor::run(wrapped)
171172
}else{
172173
futures_lite::future::block_on(wrapped)
173174
};

‎src/task/join_handle.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,17 @@ impl<T> Drop for JoinHandle<T> {
7878
impl<T>FutureforJoinHandle<T>{
7979
typeOutput =T;
8080

81+
#[cfg(not(target_os ="unknown"))]
8182
fnpoll(mutself:Pin<&mutSelf>,cx:&mutContext<'_>) ->Poll<Self::Output>{
8283
Pin::new(&mutself.handle.as_mut().unwrap()).poll(cx)
8384
}
85+
86+
#[cfg(target_arch ="wasm32")]
87+
fnpoll(mutself:Pin<&mutSelf>,cx:&mutContext<'_>) ->Poll<Self::Output>{
88+
matchPin::new(&mutself.handle.as_mut().unwrap()).poll(cx){
89+
Poll::Ready(Ok(t)) =>Poll::Ready(t),
90+
Poll::Ready(Err(_)) =>unreachable!("channel must not be canceled"),
91+
Poll::Pending =>Poll::Pending,
92+
}
93+
}
8494
}

‎src/utils.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ pub(crate) trait Context {
5959
fncontext(self,message:implFn() ->String) ->Self;
6060
}
6161

62-
#[cfg(all(not(target_os ="unknown"), feature ="default"))]
62+
#[cfg(all(
63+
not(target_os ="unknown"),
64+
any(feature ="default", feature ="unstable")
65+
))]
6366
mod timer{
6467
pubtypeTimer = async_io::Timer;
6568
}
@@ -69,20 +72,19 @@ pub(crate) fn timer_after(dur: std::time::Duration) -> timer::Timer {
6972
Timer::after(dur)
7073
}
7174

72-
#[cfg(any(
73-
all(target_arch ="wasm32", feature ="default"),
74-
all(feature ="unstable", not(feature ="default"))
75-
))]
75+
#[cfg(any(all(target_arch ="wasm32", feature ="default"),))]
7676
mod timer{
7777
use std::pin::Pin;
7878
use std::task::Poll;
7979

80+
use gloo_timers::future::TimeoutFuture;
81+
8082
#[derive(Debug)]
81-
pub(crate)structTimer(futures_timer::Delay);
83+
pub(crate)structTimer(TimeoutFuture);
8284

8385
implTimer{
8486
pub(crate)fnafter(dur: std::time::Duration) ->Self{
85-
Timer(futures_timer::Delay::new(dur))
87+
Timer(TimeoutFuture::new(dur.as_millis()asu32))
8688
}
8789
}
8890

‎tests/collect.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[cfg(feature ="unstable")]
22
#[test]
3-
fntest_send()-> async_std::io::Result<()>{
3+
fntest_send(){
44
use async_std::prelude::*;
55
use async_std::{stream, task};
66

@@ -14,7 +14,5 @@ fn test_send() -> async_std::io::Result<()> {
1414

1515
// This line triggers a compilation error
1616
test_send_trait(&fut);
17-
18-
Ok(())
19-
})
17+
});
2018
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp