Skip to content

Commit c2c13d4

Browse files
committed
Rm build.rs and replace tokio_wasi & tokio_wasm_not_wasi
Replace `tokio_wasi` with `target_os = "wasi"` and replace latter with `cfg_is_wasm_not_wasi!` or `all(target_family = "wasm", not(target_os = "wasi"))`. Signed-off-by: Jiahao XU <[email protected]>
1 parent 1d1e5e2 commit c2c13d4

File tree

104 files changed

+240
-260
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+240
-260
lines changed

tokio/build.rs

-15
This file was deleted.

tokio/src/io/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ cfg_io_driver_impl! {
223223
pub use ready::Ready;
224224
}
225225

226-
#[cfg_attr(tokio_wasi, allow(unused_imports))]
226+
#[cfg_attr(target_os = "wasi", allow(unused_imports))]
227227
mod poll_evented;
228228

229229
#[cfg(not(loom))]
230-
#[cfg_attr(tokio_wasi, allow(unused_imports))]
230+
#[cfg_attr(target_os = "wasi", allow(unused_imports))]
231231
pub(crate) use poll_evented::PollEvented;
232232
}
233233

tokio/src/lib.rs

-20
Original file line numberDiff line numberDiff line change
@@ -456,26 +456,6 @@ compile_error! {
456456
"Tokio requires the platform pointer width to be 32, 64, or 128 bits"
457457
}
458458

459-
// Ensure that our build script has correctly set cfg flags for wasm.
460-
//
461-
// Each condition is written all(a, not(b)). This should be read as
462-
// "if a, then we must also have b".
463-
#[cfg(any(
464-
all(target_arch = "wasm32", not(target_family = "wasm")),
465-
all(target_arch = "wasm64", not(target_family = "wasm")),
466-
all(target_family = "wasm", not(target_family = "wasm")),
467-
all(target_os = "wasi", not(target_family = "wasm")),
468-
all(target_os = "wasi", not(tokio_wasi)),
469-
all(target_os = "wasi", tokio_wasm_not_wasi),
470-
all(
471-
target_family = "wasm",
472-
not(any(target_arch = "wasm32", target_arch = "wasm64"))
473-
),
474-
all(tokio_wasm_not_wasi, not(target_family = "wasm")),
475-
all(tokio_wasi, not(target_family = "wasm"))
476-
))]
477-
compile_error!("Tokio's build script has incorrectly detected wasm.");
478-
479459
#[cfg(all(
480460
not(tokio_unstable),
481461
target_family = "wasm",

tokio/src/macros/cfg.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ macro_rules! cfg_fs {
8585
($($item:item)*) => {
8686
$(
8787
#[cfg(feature = "fs")]
88-
#[cfg(not(tokio_wasi))]
88+
#[cfg(not(target_os = "wasi"))]
8989
#[cfg_attr(docsrs, doc(cfg(feature = "fs")))]
9090
$item
9191
)*
@@ -276,7 +276,7 @@ macro_rules! cfg_process {
276276
#[cfg(feature = "process")]
277277
#[cfg_attr(docsrs, doc(cfg(feature = "process")))]
278278
#[cfg(not(loom))]
279-
#[cfg(not(tokio_wasi))]
279+
#[cfg(not(target_os = "wasi"))]
280280
$item
281281
)*
282282
}
@@ -305,7 +305,7 @@ macro_rules! cfg_signal {
305305
#[cfg(feature = "signal")]
306306
#[cfg_attr(docsrs, doc(cfg(feature = "signal")))]
307307
#[cfg(not(loom))]
308-
#[cfg(not(tokio_wasi))]
308+
#[cfg(not(target_os = "wasi"))]
309309
$item
310310
)*
311311
}
@@ -372,7 +372,7 @@ macro_rules! cfg_not_rt {
372372
macro_rules! cfg_rt_multi_thread {
373373
($($item:item)*) => {
374374
$(
375-
#[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))]
375+
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
376376
#[cfg_attr(docsrs, doc(cfg(feature = "rt-multi-thread")))]
377377
$item
378378
)*
@@ -585,7 +585,7 @@ macro_rules! cfg_not_has_const_mutex_new {
585585
macro_rules! cfg_not_wasi {
586586
($($item:item)*) => {
587587
$(
588-
#[cfg(not(tokio_wasi))]
588+
#[cfg(not(target_os = "wasi"))]
589589
$item
590590
)*
591591
}
@@ -594,7 +594,7 @@ macro_rules! cfg_not_wasi {
594594
macro_rules! cfg_is_wasm_not_wasi {
595595
($($item:item)*) => {
596596
$(
597-
#[cfg(tokio_wasm_not_wasi)]
597+
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
598598
$item
599599
)*
600600
}

tokio/src/net/tcp/listener.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ impl TcpListener {
281281
.map(|raw_socket| unsafe { std::net::TcpListener::from_raw_socket(raw_socket) })
282282
}
283283

284-
#[cfg(tokio_wasi)]
284+
#[cfg(target_os = "wasi")]
285285
{
286286
use std::os::wasi::io::{FromRawFd, IntoRawFd};
287287
self.io
@@ -416,7 +416,7 @@ mod sys {
416416
}
417417

418418
cfg_unstable! {
419-
#[cfg(tokio_wasi)]
419+
#[cfg(target_os = "wasi")]
420420
mod sys {
421421
use super::TcpListener;
422422
use std::os::wasi::prelude::*;

tokio/src/net/tcp/stream.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl TcpStream {
258258
.map(|raw_socket| unsafe { std::net::TcpStream::from_raw_socket(raw_socket) })
259259
}
260260

261-
#[cfg(tokio_wasi)]
261+
#[cfg(target_os = "wasi")]
262262
{
263263
use std::os::wasi::io::{FromRawFd, IntoRawFd};
264264
self.io
@@ -1405,7 +1405,7 @@ cfg_windows! {
14051405
}
14061406
}
14071407

1408-
#[cfg(all(tokio_unstable, tokio_wasi))]
1408+
#[cfg(all(tokio_unstable, target_os = "wasi"))]
14091409
mod sys {
14101410
use super::TcpStream;
14111411
use std::os::wasi::prelude::*;

tokio/src/runtime/blocking/pool.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ const KEEP_ALIVE: Duration = Duration::from_secs(10);
173173
/// Tasks will be scheduled as non-mandatory, meaning they may not get executed
174174
/// in case of runtime shutdown.
175175
#[track_caller]
176-
#[cfg_attr(tokio_wasi, allow(dead_code))]
176+
#[cfg_attr(target_os = "wasi", allow(dead_code))]
177177
pub(crate) fn spawn_blocking<F, R>(func: F) -> JoinHandle<R>
178178
where
179179
F: FnOnce() -> R + Send + 'static,

tokio/src/runtime/blocking/schedule.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ impl BlockingSchedule {
2323
scheduler::Handle::CurrentThread(handle) => {
2424
handle.driver.clock.inhibit_auto_advance();
2525
}
26-
#[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))]
26+
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
2727
scheduler::Handle::MultiThread(_) => {}
28-
#[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))]
28+
#[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))]
2929
scheduler::Handle::MultiThreadAlt(_) => {}
3030
}
3131
}
@@ -45,9 +45,9 @@ impl task::Schedule for BlockingSchedule {
4545
handle.driver.clock.allow_auto_advance();
4646
handle.driver.unpark();
4747
}
48-
#[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))]
48+
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
4949
scheduler::Handle::MultiThread(_) => {}
50-
#[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))]
50+
#[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))]
5151
scheduler::Handle::MultiThreadAlt(_) => {}
5252
}
5353
}

tokio/src/runtime/builder.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ pub(crate) type ThreadNameFn = std::sync::Arc<dyn Fn() -> String + Send + Sync +
197197
#[derive(Clone, Copy)]
198198
pub(crate) enum Kind {
199199
CurrentThread,
200-
#[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))]
200+
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
201201
MultiThread,
202-
#[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))]
202+
#[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))]
203203
MultiThreadAlt,
204204
}
205205

@@ -676,9 +676,9 @@ impl Builder {
676676
pub fn build(&mut self) -> io::Result<Runtime> {
677677
match &self.kind {
678678
Kind::CurrentThread => self.build_current_thread_runtime(),
679-
#[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))]
679+
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
680680
Kind::MultiThread => self.build_threaded_runtime(),
681-
#[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))]
681+
#[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))]
682682
Kind::MultiThreadAlt => self.build_alt_threaded_runtime(),
683683
}
684684
}
@@ -687,9 +687,9 @@ impl Builder {
687687
driver::Cfg {
688688
enable_pause_time: match self.kind {
689689
Kind::CurrentThread => true,
690-
#[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))]
690+
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
691691
Kind::MultiThread => false,
692-
#[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))]
692+
#[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))]
693693
Kind::MultiThreadAlt => false,
694694
},
695695
enable_io: self.enable_io,

tokio/src/runtime/coop.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,9 @@ cfg_coop! {
246246
mod test {
247247
use super::*;
248248

249-
#[cfg(tokio_wasm_not_wasi)]
250-
use wasm_bindgen_test::wasm_bindgen_test as test;
249+
cfg_is_wasm_not_wasi! {
250+
use wasm_bindgen_test::wasm_bindgen_test as test;
251+
}
251252

252253
fn get() -> Budget {
253254
context::budget(|cell| cell.get()).unwrap_or(Budget::unconstrained())

tokio/src/runtime/handle.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,9 @@ impl Handle {
355355
pub fn runtime_flavor(&self) -> RuntimeFlavor {
356356
match self.inner {
357357
scheduler::Handle::CurrentThread(_) => RuntimeFlavor::CurrentThread,
358-
#[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))]
358+
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
359359
scheduler::Handle::MultiThread(_) => RuntimeFlavor::MultiThread,
360-
#[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))]
360+
#[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))]
361361
scheduler::Handle::MultiThreadAlt(_) => RuntimeFlavor::MultiThreadAlt,
362362
}
363363
}
@@ -385,9 +385,9 @@ impl Handle {
385385
pub fn id(&self) -> runtime::Id {
386386
let owned_id = match &self.inner {
387387
scheduler::Handle::CurrentThread(handle) => handle.owned_id(),
388-
#[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))]
388+
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
389389
scheduler::Handle::MultiThread(handle) => handle.owned_id(),
390-
#[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))]
390+
#[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))]
391391
scheduler::Handle::MultiThreadAlt(handle) => handle.owned_id(),
392392
};
393393
owned_id.into()
@@ -529,7 +529,7 @@ cfg_taskdump! {
529529
pub async fn dump(&self) -> crate::runtime::Dump {
530530
match &self.inner {
531531
scheduler::Handle::CurrentThread(handle) => handle.dump(),
532-
#[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))]
532+
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
533533
scheduler::Handle::MultiThread(handle) => {
534534
// perform the trace in a separate thread so that the
535535
// trace itself does not appear in the taskdump.
@@ -539,7 +539,7 @@ cfg_taskdump! {
539539
handle.dump().await
540540
}).await
541541
},
542-
#[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))]
542+
#[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))]
543543
scheduler::Handle::MultiThreadAlt(_) => panic!("task dump not implemented for this runtime flavor"),
544544
}
545545
}

tokio/src/runtime/io/driver.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub(crate) struct Handle {
4545

4646
/// Used to wake up the reactor from a call to `turn`.
4747
/// Not supported on Wasi due to lack of threading support.
48-
#[cfg(not(tokio_wasi))]
48+
#[cfg(not(target_os = "wasi"))]
4949
waker: mio::Waker,
5050

5151
pub(crate) metrics: IoDriverMetrics,
@@ -97,7 +97,7 @@ impl Driver {
9797
/// creation.
9898
pub(crate) fn new(nevents: usize) -> io::Result<(Driver, Handle)> {
9999
let poll = mio::Poll::new()?;
100-
#[cfg(not(tokio_wasi))]
100+
#[cfg(not(target_os = "wasi"))]
101101
let waker = mio::Waker::new(poll.registry(), TOKEN_WAKEUP)?;
102102
let registry = poll.registry().try_clone()?;
103103

@@ -114,7 +114,7 @@ impl Driver {
114114
registry,
115115
registrations,
116116
synced: Mutex::new(synced),
117-
#[cfg(not(tokio_wasi))]
117+
#[cfg(not(target_os = "wasi"))]
118118
waker,
119119
metrics: IoDriverMetrics::default(),
120120
};
@@ -156,7 +156,7 @@ impl Driver {
156156
match self.poll.poll(events, max_wait) {
157157
Ok(_) => {}
158158
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {}
159-
#[cfg(tokio_wasi)]
159+
#[cfg(target_os = "wasi")]
160160
Err(e) if e.kind() == io::ErrorKind::InvalidInput => {
161161
// In case of wasm32_wasi this error happens, when trying to poll without subscriptions
162162
// just return from the park, as there would be nothing, which wakes us up.
@@ -212,7 +212,7 @@ impl Handle {
212212
/// blocked in `turn`, then the next call to `turn` will not block and
213213
/// return immediately.
214214
pub(crate) fn unpark(&self) {
215-
#[cfg(not(tokio_wasi))]
215+
#[cfg(not(target_os = "wasi"))]
216216
self.waker.wake().expect("failed to wake I/O driver");
217217
}
218218

tokio/src/runtime/io/registration.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl Registration {
118118

119119
// Uses the poll path, requiring the caller to ensure mutual exclusion for
120120
// correctness. Only the last task to call this function is notified.
121-
#[cfg(not(tokio_wasi))]
121+
#[cfg(not(target_os = "wasi"))]
122122
pub(crate) fn poll_read_io<R>(
123123
&self,
124124
cx: &mut Context<'_>,

tokio/src/runtime/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ cfg_rt! {
212212
use config::Config;
213213

214214
mod blocking;
215-
#[cfg_attr(tokio_wasi, allow(unused_imports))]
215+
#[cfg_attr(target_os = "wasi", allow(unused_imports))]
216216
pub(crate) use blocking::spawn_blocking;
217217

218218
cfg_trace! {

tokio/src/runtime/runtime.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ pub(super) enum Scheduler {
125125
CurrentThread(CurrentThread),
126126

127127
/// Execute tasks across multiple threads.
128-
#[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))]
128+
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
129129
MultiThread(MultiThread),
130130

131131
/// Execute tasks across multiple threads.
132-
#[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))]
132+
#[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))]
133133
MultiThreadAlt(MultiThreadAlt),
134134
}
135135

@@ -345,9 +345,9 @@ impl Runtime {
345345

346346
match &self.scheduler {
347347
Scheduler::CurrentThread(exec) => exec.block_on(&self.handle.inner, future),
348-
#[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))]
348+
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
349349
Scheduler::MultiThread(exec) => exec.block_on(&self.handle.inner, future),
350-
#[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))]
350+
#[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))]
351351
Scheduler::MultiThreadAlt(exec) => exec.block_on(&self.handle.inner, future),
352352
}
353353
}
@@ -463,13 +463,13 @@ impl Drop for Runtime {
463463
let _guard = context::try_set_current(&self.handle.inner);
464464
current_thread.shutdown(&self.handle.inner);
465465
}
466-
#[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))]
466+
#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
467467
Scheduler::MultiThread(multi_thread) => {
468468
// The threaded scheduler drops its tasks on its worker threads, which is
469469
// already in the runtime's context.
470470
multi_thread.shutdown(&self.handle.inner);
471471
}
472-
#[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))]
472+
#[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))]
473473
Scheduler::MultiThreadAlt(multi_thread) => {
474474
// The threaded scheduler drops its tasks on its worker threads, which is
475475
// already in the runtime's context.

tokio/src/runtime/scheduler/inject/shared.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ impl<T: 'static> Shared<T> {
3838
}
3939

4040
// Kind of annoying to have to include the cfg here
41-
#[cfg(any(tokio_taskdump, all(feature = "rt-multi-thread", not(tokio_wasi))))]
41+
#[cfg(any(
42+
tokio_taskdump,
43+
all(feature = "rt-multi-thread", not(target_os = "wasi"))
44+
))]
4245
pub(crate) fn is_closed(&self, synced: &Synced) -> bool {
4346
synced.is_closed
4447
}

0 commit comments

Comments
 (0)