Skip to main content

libc/new/
mod.rs

1//! This module contains the future directory structure. If possible, new definitions should
2//! get added here.
3//!
4//! Eventually everything should be moved over, and we will move this directory to the top
5//! level in `src`.
6//!
7//! # Basic structure
8//!
9//! Each child module here represents a library or group of libraries that we are binding. Each of
10//! these has several submodules, representing either a directory or a header file in that library.
11//!
12//! `#include`s turn into `pub use ...*;` statements. Then at the root level (here), we choose
13//! which top-level headers we want to reexport the definitions for.
14//!
15//! All modules are only crate-public since we don't reexport this structure.
16
17mod common;
18
19/* The `pub(crate) use ...` statements are commented while the modules are empty */
20
21// Platform libraries and combined platform+libc
22//
23// Not supported or not needed:
24// * amdhsa
25// * cuda
26// * lynxos178
27// * managarm
28// * motor
29// * none
30// * psp
31// * psx
32// * uefi
33// * unknown
34// * vexos
35// * zkvm
36//
37// Combined to target_vendor = "apple"
38// * ios
39// * macos
40// * tvos
41// * visionos
42// * watchos
43cfg_if! {
44    if #[cfg(target_os = "aix")] {
45        mod aix;
46        pub(crate) use aix::*;
47    } else if #[cfg(target_os = "android")] {
48        mod bionic_libc;
49        pub(crate) use bionic_libc::*;
50    } else if #[cfg(target_vendor = "apple")] {
51        mod apple;
52        pub(crate) use apple::*;
53    } else if #[cfg(target_os = "cygwin")] {
54        mod cygwin;
55        pub(crate) use cygwin::*;
56    } else if #[cfg(target_os = "dragonfly")] {
57        mod dragonfly;
58        pub(crate) use dragonfly::*;
59    } else if #[cfg(target_os = "emscripten")] {
60        mod emscripten;
61        pub use emscripten::sched::*;
62        pub(crate) use emscripten::*;
63    } else if #[cfg(target_os = "espidf")] {
64        mod espidf;
65        // pub(crate) use espidf::*;
66    } else if #[cfg(target_os = "freebsd")] {
67        mod freebsd;
68        pub(crate) use freebsd::*;
69    } else if #[cfg(target_os = "fuchsia")] {
70        mod fuchsia;
71        pub(crate) use fuchsia::*;
72    } else if #[cfg(target_os = "haiku")] {
73        mod haiku;
74        pub(crate) use haiku::*;
75    } else if #[cfg(target_os = "hermit")] {
76        mod hermit_abi;
77        // pub(crate) use hermit_abi::*;
78    } else if #[cfg(target_os = "horizon")] {
79        mod horizon;
80        // pub(crate) use horizon::*;
81    } else if #[cfg(target_os = "hurd")] {
82        mod hurd;
83        // pub(crate) use hurd::*;
84    } else if #[cfg(target_os = "illumos")] {
85        mod illumos;
86        pub(crate) use illumos::*;
87    } else if #[cfg(target_os = "l4re")] {
88        mod l4re;
89        // pub(crate) use l4re::*;
90    } else if #[cfg(target_os = "linux")] {
91        mod linux_uapi;
92        pub(crate) use linux_uapi::*;
93    } else if #[cfg(target_os = "netbsd")] {
94        mod netbsd;
95        pub(crate) use netbsd::*;
96    } else if #[cfg(any(target_os = "nto", target_os = "qnx"))] {
97        mod nto;
98        pub(crate) use nto::*;
99    } else if #[cfg(target_os = "nuttx")] {
100        mod nuttx;
101        pub(crate) use nuttx::*;
102    } else if #[cfg(target_os = "openbsd")] {
103        mod openbsd;
104        pub(crate) use openbsd::*;
105    } else if #[cfg(target_os = "qurt")] {
106        pub mod qurt;
107    } else if #[cfg(target_os = "redox")] {
108        mod redox;
109        // pub(crate) use redox::*;
110    } else if #[cfg(target_os = "rtems")] {
111        mod rtems;
112        // pub(crate) use rtems::*;
113    } else if #[cfg(target_os = "solaris")] {
114        mod solaris;
115        pub(crate) use solaris::*;
116    } else if #[cfg(target_os = "solid_asp3")] {
117        mod solid;
118        // pub(crate) use solid::*;
119    } else if #[cfg(target_os = "teeos")] {
120        mod teeos;
121        // pub(crate) use teeos::*;
122    } else if #[cfg(target_os = "trusty")] {
123        mod trusty;
124        // pub(crate) use trusty::*;
125    } else if #[cfg(target_os = "vita")] {
126        mod vita;
127        // pub(crate) use vita::*;
128    } else if #[cfg(target_os = "vxworks")] {
129        mod vxworks;
130        pub(crate) use vxworks::*;
131    } else if #[cfg(target_os = "wasi")] {
132        mod wasi;
133        // pub(crate) use wasi::*;
134    } else if #[cfg(target_os = "windows")] {
135        mod ucrt;
136        // pub(crate) use ucrt::*;
137    } else if #[cfg(target_os = "xous")] {
138        mod xous;
139        // pub(crate) use xous::*;
140    }
141}
142
143// Multi-platform libc
144cfg_if! {
145    // FIXME(vxworks): vxworks sets `target_env = "gnu"` but maybe shouldn't.
146    if #[cfg(all(
147        target_family = "unix",
148        target_env = "gnu",
149        not(target_os = "vxworks")
150    ))] {
151        mod glibc;
152        pub(crate) use glibc::*;
153    } else if #[cfg(any(target_env = "musl", target_env = "ohos"))] {
154        // OhOS also uses the musl libc
155        mod musl;
156        pub use musl::sched::*;
157        pub(crate) use musl::*;
158    } else if #[cfg(target_env = "newlib")] {
159        mod newlib;
160        pub(crate) use newlib::*;
161    } else if #[cfg(target_env = "relibc")] {
162        mod relibc;
163        pub(crate) use relibc::*;
164    } else if #[cfg(target_env = "sgx")] {
165        mod sgx;
166        // pub(crate) use sgx::*;
167    } else if #[cfg(target_env = "uclibc")] {
168        mod uclibc;
169        pub(crate) use uclibc::*;
170    }
171}
172
173// Per-OS headers we export
174cfg_if! {
175    if #[cfg(target_os = "android")] {
176        use bionic_libc::kernel_uapi::linux;
177        pub use linux::types::*;
178        pub use sys::socket::*;
179    } else if #[cfg(target_os = "linux")] {
180        pub use linux::can::bcm::*;
181        pub use linux::can::error::*;
182        pub use linux::can::j1939::*;
183        pub use linux::can::netlink::*;
184        pub use linux::can::raw::*;
185        pub use linux::futex::*;
186        pub use linux::if_addr::*;
187        pub use linux::if_link::*;
188        pub use linux::if_packet::*;
189        pub use linux::keyctl::*;
190        pub use linux::membarrier::*;
191        pub use linux::mount::*;
192        pub use linux::netlink::*;
193        pub use linux::pidfd::*;
194        pub use linux::sctp::*;
195        pub use linux::tls::*;
196        pub use linux::types::*;
197        #[cfg(target_env = "gnu")]
198        pub use net::route::*;
199    } else if #[cfg(target_vendor = "apple")] {
200        pub use net::bpf::*;
201        pub use netinet6::in6_var::*;
202        pub use pthread_::introspection::*;
203        pub use pthread_::pthread_spis::*;
204        pub use pthread_::spawn::*;
205        pub use pthread_::stack_np::*;
206        pub use signal::*;
207        pub use sys::ioccom::*;
208        pub use sys::sockio::*;
209        pub use sys::ttycom::*;
210    } else if #[cfg(target_os = "l4re")] {
211        pub use l4re::packet::*;
212    } else if #[cfg(target_os = "netbsd")] {
213        pub use net::if_::*;
214        pub use sys::file::*;
215        pub use sys::ipc::*;
216        pub use sys::socket::*;
217        pub use sys::statvfs::*;
218        pub use sys::time::*;
219        pub use sys::timex::*;
220        pub use sys::types::*;
221        pub use utmp_::*;
222        pub use utmpx_::*;
223    } else if #[cfg(target_os = "openbsd")] {
224        pub use sys::ipc::*;
225    } else if #[cfg(any(target_os = "nto", target_os = "qnx"))] {
226        pub use net::bpf::*;
227        pub use net::if_::*;
228    } else if #[cfg(target_os = "freebsd")] {
229        pub use net::dlt::*;
230        pub use netinet6::in6_var::*;
231        pub use sys::file::*;
232        pub use sys::ioccom::*;
233        pub use sys::socket::*;
234    }
235}
236
237// Per-env headers we export
238cfg_if! {
239    if #[cfg(any(target_env = "musl", target_env = "ohos"))] {
240        pub use sys::socket::*;
241    }
242}
243
244// Per-family headers we export
245cfg_if! {
246    if #[cfg(all(target_family = "unix", not(target_os = "qurt")))] {
247        // FIXME(pthread): eventually all platforms should use this module
248        #[cfg(any(
249            target_os = "android",
250            target_os = "emscripten",
251            target_os = "l4re",
252            target_os = "linux"
253        ))]
254        pub use pthread::*;
255        pub use unistd::*;
256    }
257}