1#![allow(unused_macros)]
2
3macro_rules! feature {
4 (
5 #![$meta:meta]
6 $($item:item)*
7 ) => {
8 $(
9 #[cfg($meta)]
10 #[cfg_attr(docsrs, doc(cfg($meta)))]
11 $item
12 )*
13 }
14}
15
16/// Enables Windows-specific code.
17/// Use this macro instead of `cfg(windows)` to generate docs properly.
18macro_rules! cfg_windows {
19 ($($item:item)*) => {
20 $(
21 #[cfg(any(all(doc, docsrs), windows))]
22 #[cfg_attr(docsrs, doc(cfg(windows)))]
23 $item
24 )*
25 }
26}
27
28/// Enables Unix-specific code.
29/// Use this macro instead of `cfg(unix)` to generate docs properly.
30macro_rules! cfg_unix {
31 ($($item:item)*) => {
32 $(
33 #[cfg(any(all(doc, docsrs), unix))]
34 #[cfg_attr(docsrs, doc(cfg(unix)))]
35 $item
36 )*
37 }
38}
39
40/// Enables unstable Windows-specific code.
41/// Use this macro instead of `cfg(windows)` to generate docs properly.
42macro_rules! cfg_unstable_windows {
43 ($($item:item)*) => {
44 $(
45 #[cfg(all(any(all(doc, docsrs), windows), tokio_unstable))]
46 #[cfg_attr(docsrs, doc(cfg(all(windows, tokio_unstable))))]
47 $item
48 )*
49 }
50}
51
52/// Enables `enter::block_on`.
53macro_rules! cfg_block_on {
54 ($($item:item)*) => {
55 $(
56 #[cfg(any(
57 feature = "fs",
58 feature = "net",
59 feature = "io-std",
60 feature = "rt",
61 ))]
62 $item
63 )*
64 }
65}
66
67/// Enables internal `AtomicWaker` impl.
68macro_rules! cfg_atomic_waker_impl {
69 ($($item:item)*) => {
70 $(
71 #[cfg(any(
72 feature = "net",
73 feature = "process",
74 feature = "rt",
75 feature = "signal",
76 feature = "time",
77 ))]
78 #[cfg(not(loom))]
79 $item
80 )*
81 }
82}
83
84macro_rules! cfg_aio {
85 ($($item:item)*) => {
86 $(
87 #[cfg(all(any(docsrs, target_os = "freebsd"), feature = "net"))]
88 #[cfg_attr(docsrs,
89 doc(cfg(all(target_os = "freebsd", feature = "net")))
90 )]
91 $item
92 )*
93 }
94}
95
96macro_rules! cfg_fs {
97 ($($item:item)*) => {
98 $(
99 #[cfg(feature = "fs")]
100 #[cfg(not(target_os = "wasi"))]
101 #[cfg_attr(docsrs, doc(cfg(feature = "fs")))]
102 $item
103 )*
104 }
105}
106
107macro_rules! cfg_io_blocking {
108 ($($item:item)*) => {
109 $( #[cfg(any(
110 feature = "io-std",
111 feature = "fs",
112 all(windows, feature = "process"),
113 ))] $item )*
114 }
115}
116
117macro_rules! cfg_io_driver {
118 ($($item:item)*) => {
119 $(
120 #[cfg(any(
121 feature = "net",
122 all(unix, feature = "process"),
123 all(unix, feature = "signal"),
124 ))]
125 #[cfg_attr(docsrs, doc(cfg(any(
126 feature = "net",
127 all(unix, feature = "process"),
128 all(unix, feature = "signal"),
129 ))))]
130 $item
131 )*
132 }
133}
134
135macro_rules! cfg_io_driver_impl {
136 ( $( $item:item )* ) => {
137 $(
138 #[cfg(any(
139 feature = "net",
140 all(unix, feature = "process"),
141 all(unix, feature = "signal"),
142 ))]
143 $item
144 )*
145 }
146}
147
148macro_rules! cfg_not_io_driver {
149 ($($item:item)*) => {
150 $(
151 #[cfg(not(any(
152 feature = "net",
153 all(unix, feature = "process"),
154 all(unix, feature = "signal"),
155 )))]
156 $item
157 )*
158 }
159}
160
161macro_rules! cfg_io_readiness {
162 ($($item:item)*) => {
163 $(
164 #[cfg(feature = "net")]
165 $item
166 )*
167 }
168}
169
170macro_rules! cfg_io_std {
171 ($($item:item)*) => {
172 $(
173 #[cfg(feature = "io-std")]
174 #[cfg_attr(docsrs, doc(cfg(feature = "io-std")))]
175 $item
176 )*
177 }
178}
179
180macro_rules! cfg_io_util {
181 ($($item:item)*) => {
182 $(
183 #[cfg(feature = "io-util")]
184 #[cfg_attr(docsrs, doc(cfg(feature = "io-util")))]
185 $item
186 )*
187 }
188}
189
190macro_rules! cfg_not_io_util {
191 ($($item:item)*) => {
192 $( #[cfg(not(feature = "io-util"))] $item )*
193 }
194}
195
196macro_rules! cfg_loom {
197 ($($item:item)*) => {
198 $( #[cfg(loom)] $item )*
199 }
200}
201
202macro_rules! cfg_not_loom {
203 ($($item:item)*) => {
204 $( #[cfg(not(loom))] $item )*
205 }
206}
207
208macro_rules! cfg_macros {
209 ($($item:item)*) => {
210 $(
211 #[cfg(feature = "macros")]
212 #[cfg_attr(docsrs, doc(cfg(feature = "macros")))]
213 $item
214 )*
215 }
216}
217
218macro_rules! cfg_metrics {
219 ($($item:item)*) => {
220 $(
221 // For now, metrics is only disabled in loom tests.
222 // When stabilized, it might have a dedicated feature flag.
223 #[cfg(all(tokio_unstable, not(loom)))]
224 #[cfg_attr(docsrs, doc(cfg(tokio_unstable)))]
225 $item
226 )*
227 }
228}
229
230macro_rules! cfg_not_metrics {
231 ($($item:item)*) => {
232 $(
233 #[cfg(not(all(tokio_unstable, not(loom))))]
234 $item
235 )*
236 }
237}
238
239macro_rules! cfg_not_rt_and_metrics_and_net {
240 ($($item:item)*) => {
241 $( #[cfg(not(all(feature = "net", feature = "rt", all(tokio_unstable, not(loom)))))]$item )*
242 }
243}
244
245macro_rules! cfg_net_or_process {
246 ($($item:item)*) => {
247 $(
248 #[cfg(any(feature = "net", feature = "process"))]
249 #[cfg_attr(docsrs, doc(cfg(any(feature = "net", feature = "process"))))]
250 $item
251 )*
252 }
253}
254
255macro_rules! cfg_net {
256 ($($item:item)*) => {
257 $(
258 #[cfg(feature = "net")]
259 #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
260 $item
261 )*
262 }
263}
264
265macro_rules! cfg_net_unix {
266 ($($item:item)*) => {
267 $(
268 #[cfg(all(unix, feature = "net"))]
269 #[cfg_attr(docsrs, doc(cfg(all(unix, feature = "net"))))]
270 $item
271 )*
272 }
273}
274
275macro_rules! cfg_net_windows {
276 ($($item:item)*) => {
277 $(
278 #[cfg(all(any(all(doc, docsrs), windows), feature = "net"))]
279 #[cfg_attr(docsrs, doc(cfg(all(windows, feature = "net"))))]
280 $item
281 )*
282 }
283}
284
285macro_rules! cfg_process {
286 ($($item:item)*) => {
287 $(
288 #[cfg(feature = "process")]
289 #[cfg_attr(docsrs, doc(cfg(feature = "process")))]
290 #[cfg(not(loom))]
291 #[cfg(not(target_os = "wasi"))]
292 $item
293 )*
294 }
295}
296
297macro_rules! cfg_process_driver {
298 ($($item:item)*) => {
299 #[cfg(unix)]
300 #[cfg(not(loom))]
301 cfg_process! { $($item)* }
302 }
303}
304
305macro_rules! cfg_not_process_driver {
306 ($($item:item)*) => {
307 $(
308 #[cfg(not(all(unix, not(loom), feature = "process")))]
309 $item
310 )*
311 }
312}
313
314macro_rules! cfg_signal {
315 ($($item:item)*) => {
316 $(
317 #[cfg(feature = "signal")]
318 #[cfg_attr(docsrs, doc(cfg(feature = "signal")))]
319 #[cfg(not(loom))]
320 #[cfg(not(target_os = "wasi"))]
321 $item
322 )*
323 }
324}
325
326macro_rules! cfg_signal_internal {
327 ($($item:item)*) => {
328 $(
329 #[cfg(any(feature = "signal", all(unix, feature = "process")))]
330 #[cfg(not(loom))]
331 $item
332 )*
333 }
334}
335
336macro_rules! cfg_signal_internal_and_unix {
337 ($($item:item)*) => {
338 #[cfg(unix)]
339 cfg_signal_internal! { $($item)* }
340 }
341}
342
343macro_rules! cfg_not_signal_internal {
344 ($($item:item)*) => {
345 $(
346 #[cfg(any(loom, not(unix), not(any(feature = "signal", all(unix, feature = "process")))))]
347 $item
348 )*
349 }
350}
351
352macro_rules! cfg_sync {
353 ($($item:item)*) => {
354 $(
355 #[cfg(feature = "sync")]
356 #[cfg_attr(docsrs, doc(cfg(feature = "sync")))]
357 $item
358 )*
359 }
360}
361
362macro_rules! cfg_not_sync {
363 ($($item:item)*) => {
364 $( #[cfg(not(feature = "sync"))] $item )*
365 }
366}
367
368macro_rules! cfg_rt {
369 ($($item:item)*) => {
370 $(
371 #[cfg(feature = "rt")]
372 #[cfg_attr(docsrs, doc(cfg(feature = "rt")))]
373 $item
374 )*
375 }
376}
377
378macro_rules! cfg_not_rt {
379 ($($item:item)*) => {
380 $( #[cfg(not(feature = "rt"))] $item )*
381 }
382}
383
384macro_rules! cfg_rt_multi_thread {
385 ($($item:item)*) => {
386 $(
387 #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))]
388 #[cfg_attr(docsrs, doc(cfg(feature = "rt-multi-thread")))]
389 $item
390 )*
391 }
392}
393
394macro_rules! cfg_not_rt_multi_thread {
395 ($($item:item)*) => {
396 $( #[cfg(not(feature = "rt-multi-thread"))] $item )*
397 }
398}
399
400macro_rules! cfg_taskdump {
401 ($($item:item)*) => {
402 $(
403 #[cfg(all(
404 tokio_unstable,
405 tokio_taskdump,
406 feature = "rt",
407 target_os = "linux",
408 any(
409 target_arch = "aarch64",
410 target_arch = "x86",
411 target_arch = "x86_64"
412 )
413 ))]
414 $item
415 )*
416 };
417}
418
419macro_rules! cfg_not_taskdump {
420 ($($item:item)*) => {
421 $(
422 #[cfg(not(all(
423 tokio_unstable,
424 tokio_taskdump,
425 feature = "rt",
426 target_os = "linux",
427 any(
428 target_arch = "aarch64",
429 target_arch = "x86",
430 target_arch = "x86_64"
431 )
432 )))]
433 $item
434 )*
435 };
436}
437
438macro_rules! cfg_test_util {
439 ($($item:item)*) => {
440 $(
441 #[cfg(feature = "test-util")]
442 #[cfg_attr(docsrs, doc(cfg(feature = "test-util")))]
443 $item
444 )*
445 }
446}
447
448macro_rules! cfg_not_test_util {
449 ($($item:item)*) => {
450 $( #[cfg(not(feature = "test-util"))] $item )*
451 }
452}
453
454macro_rules! cfg_time {
455 ($($item:item)*) => {
456 $(
457 #[cfg(feature = "time")]
458 #[cfg_attr(docsrs, doc(cfg(feature = "time")))]
459 $item
460 )*
461 }
462}
463
464macro_rules! cfg_not_time {
465 ($($item:item)*) => {
466 $( #[cfg(not(feature = "time"))] $item )*
467 }
468}
469
470macro_rules! cfg_trace {
471 ($($item:item)*) => {
472 $(
473 #[cfg(all(tokio_unstable, feature = "tracing"))]
474 #[cfg_attr(docsrs, doc(cfg(all(tokio_unstable, feature = "tracing"))))]
475 $item
476 )*
477 };
478}
479
480macro_rules! cfg_unstable {
481 ($($item:item)*) => {
482 $(
483 #[cfg(tokio_unstable)]
484 #[cfg_attr(docsrs, doc(cfg(tokio_unstable)))]
485 $item
486 )*
487 };
488}
489
490macro_rules! cfg_not_trace {
491 ($($item:item)*) => {
492 $(
493 #[cfg(any(not(tokio_unstable), not(feature = "tracing")))]
494 $item
495 )*
496 }
497}
498
499macro_rules! cfg_coop {
500 ($($item:item)*) => {
501 $(
502 #[cfg(any(
503 feature = "fs",
504 feature = "io-std",
505 feature = "net",
506 feature = "process",
507 feature = "rt",
508 feature = "signal",
509 feature = "sync",
510 feature = "time",
511 ))]
512 $item
513 )*
514 }
515}
516
517macro_rules! cfg_not_coop {
518 ($($item:item)*) => {
519 $(
520 #[cfg(not(any(
521 feature = "fs",
522 feature = "io-std",
523 feature = "net",
524 feature = "process",
525 feature = "rt",
526 feature = "signal",
527 feature = "sync",
528 feature = "time",
529 )))]
530 $item
531 )*
532 }
533}
534
535macro_rules! cfg_has_atomic_u64 {
536 ($($item:item)*) => {
537 $(
538 #[cfg(target_has_atomic = "64")]
539 $item
540 )*
541 }
542}
543
544macro_rules! cfg_not_has_atomic_u64 {
545 ($($item:item)*) => {
546 $(
547 #[cfg(not(target_has_atomic = "64"))]
548 $item
549 )*
550 }
551}
552
553macro_rules! cfg_has_const_mutex_new {
554 ($($item:item)*) => {
555 $(
556 #[cfg(not(all(loom, test)))]
557 $item
558 )*
559 }
560}
561
562macro_rules! cfg_not_has_const_mutex_new {
563 ($($item:item)*) => {
564 $(
565 #[cfg(all(loom, test))]
566 $item
567 )*
568 }
569}
570
571macro_rules! cfg_not_wasi {
572 ($($item:item)*) => {
573 $(
574 #[cfg(not(target_os = "wasi"))]
575 $item
576 )*
577 }
578}
579
580macro_rules! cfg_is_wasm_not_wasi {
581 ($($item:item)*) => {
582 $(
583 #[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
584 $item
585 )*
586 }
587}
588