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 = "helenos")] {
76        mod helenos;
77        pub(crate) use helenos::*;
78    } else if #[cfg(target_os = "hermit")] {
79        mod hermit_abi;
80        // pub(crate) use hermit_abi::*;
81    } else if #[cfg(target_os = "horizon")] {
82        mod horizon;
83        // pub(crate) use horizon::*;
84    } else if #[cfg(target_os = "hurd")] {
85        mod hurd;
86        // pub(crate) use hurd::*;
87    } else if #[cfg(target_os = "illumos")] {
88        mod illumos;
89        pub(crate) use illumos::*;
90    } else if #[cfg(target_os = "l4re")] {
91        mod l4re;
92        // pub(crate) use l4re::*;
93    } else if #[cfg(target_os = "linux")] {
94        mod linux_uapi;
95        pub(crate) use linux_uapi::*;
96    } else if #[cfg(target_os = "netbsd")] {
97        mod netbsd;
98        pub(crate) use netbsd::*;
99    } else if #[cfg(any(target_os = "nto", target_os = "qnx"))] {
100        mod nto;
101        pub(crate) use nto::*;
102    } else if #[cfg(target_os = "nuttx")] {
103        mod nuttx;
104        pub(crate) use nuttx::*;
105    } else if #[cfg(target_os = "openbsd")] {
106        mod openbsd;
107        pub(crate) use openbsd::*;
108    } else if #[cfg(target_os = "qurt")] {
109        pub mod qurt;
110    } else if #[cfg(target_os = "redox")] {
111        mod redox;
112        // pub(crate) use redox::*;
113    } else if #[cfg(target_os = "rtems")] {
114        mod rtems;
115        // pub(crate) use rtems::*;
116    } else if #[cfg(target_os = "solaris")] {
117        mod solaris;
118        pub(crate) use solaris::*;
119    } else if #[cfg(target_os = "solid_asp3")] {
120        mod solid;
121        // pub(crate) use solid::*;
122    } else if #[cfg(target_os = "teeos")] {
123        mod teeos;
124        // pub(crate) use teeos::*;
125    } else if #[cfg(target_os = "trusty")] {
126        mod trusty;
127        // pub(crate) use trusty::*;
128    } else if #[cfg(target_os = "vita")] {
129        mod vita;
130        // pub(crate) use vita::*;
131    } else if #[cfg(target_os = "vxworks")] {
132        mod vxworks;
133        pub(crate) use vxworks::*;
134    } else if #[cfg(target_os = "wasi")] {
135        mod wasi;
136        // pub(crate) use wasi::*;
137    } else if #[cfg(target_os = "windows")] {
138        mod ucrt;
139        // pub(crate) use ucrt::*;
140    } else if #[cfg(target_os = "xous")] {
141        mod xous;
142        // pub(crate) use xous::*;
143    }
144}
145
146// Multi-platform libc
147cfg_if! {
148    // FIXME(vxworks): vxworks sets `target_env = "gnu"` but maybe shouldn't.
149    if #[cfg(all(
150        target_family = "unix",
151        target_env = "gnu",
152        not(target_os = "vxworks")
153    ))] {
154        mod glibc;
155        pub(crate) use glibc::*;
156    } else if #[cfg(any(target_env = "musl", target_env = "ohos"))] {
157        // OhOS also uses the musl libc
158        mod musl;
159        pub use musl::sched::*;
160        pub(crate) use musl::*;
161    } else if #[cfg(target_env = "newlib")] {
162        mod newlib;
163        pub(crate) use newlib::*;
164    } else if #[cfg(target_env = "relibc")] {
165        mod relibc;
166        pub(crate) use relibc::*;
167    } else if #[cfg(target_env = "sgx")] {
168        mod sgx;
169        // pub(crate) use sgx::*;
170    } else if #[cfg(target_env = "uclibc")] {
171        mod uclibc;
172        pub(crate) use uclibc::*;
173    }
174}
175
176// Per-OS headers we export
177cfg_if! {
178    if #[cfg(target_os = "android")] {
179        use bionic_libc::kernel_uapi::linux;
180        pub use linux::types::*;
181        pub use sys::socket::*;
182    } else if #[cfg(target_os = "linux")] {
183        pub use asm::socket::*;
184        pub use linux::can::bcm::*;
185        pub use linux::can::error::*;
186        pub use linux::can::j1939::*;
187        pub use linux::can::netlink::*;
188        pub use linux::can::raw::*;
189        pub use linux::futex::*;
190        pub use linux::if_addr::*;
191        pub use linux::if_link::*;
192        pub use linux::if_packet::*;
193        pub use linux::keyctl::*;
194        pub use linux::membarrier::*;
195        pub use linux::mount::*;
196        pub use linux::netlink::*;
197        pub use linux::pidfd::*;
198        pub use linux::sctp::*;
199        pub use linux::tls::*;
200        pub use linux::types::*;
201
202        #[cfg(target_env = "gnu")]
203        pub use self::{
204            net::route::*,
205            signal::*,
206            sys::socket::*,
207            sys::statvfs::*,
208        };
209        #[cfg(target_env = "uclibc")]
210        pub use self::{
211            socket::*,
212            sysdeps::linux::common::bits::siginfo::*,
213        };
214    } else if #[cfg(target_vendor = "apple")] {
215        #[cfg(target_os = "macos")]
216        pub use net::bpf::*;
217        pub use netinet::tcp::*;
218        #[cfg(target_os = "macos")]
219        pub use netinet6::in6_var::*;
220        pub use pthread_::introspection::*;
221        pub use pthread_::pthread_spis::*;
222        pub use pthread_::spawn::*;
223        pub use pthread_::stack_np::*;
224        pub use signal::*;
225        pub use sys::ioccom::*;
226        pub use sys::sockio::*;
227        pub use sys::ttycom::*;
228    } else if #[cfg(target_os = "l4re")] {
229        pub use l4re::packet::*;
230    } else if #[cfg(target_os = "netbsd")] {
231        pub use net::if_::*;
232        pub use sys::file::*;
233        pub use sys::ipc::*;
234        pub use sys::socket::*;
235        pub use sys::statvfs::*;
236        pub use sys::time::*;
237        pub use sys::timex::*;
238        pub use sys::types::*;
239        pub use utmp_::*;
240        pub use utmpx_::*;
241    } else if #[cfg(target_os = "openbsd")] {
242        pub use sys::ipc::*;
243        pub use sys::sensors::*;
244        pub use sys::sysctl::*;
245    } else if #[cfg(any(target_os = "nto", target_os = "qnx"))] {
246        pub use net::bpf::*;
247        pub use net::if_::*;
248    } else if #[cfg(target_os = "freebsd")] {
249        pub use net::dlt::*;
250        // FIXME(1.0,remove): these bindings should be left in a public submodule.
251        pub use net::if_mib::*;
252        pub use net::route::*;
253        pub use netinet6::in6_var::*;
254        pub use sys::file::*;
255        pub use sys::ioccom::*;
256        pub use sys::socket::*;
257    } else if #[cfg(target_os = "helenos")] {
258        pub use abi::errno::*;
259        pub use bits::*;
260        pub use dirent_mod::*;
261        pub use errno::*;
262        pub use fibril_synch::*;
263        pub use inet::dnsr::*;
264        pub use inet::tcp::*;
265        pub use stdlib::*;
266        pub use vfs::vfs::*;
267    }
268}
269
270// Per-env headers we export
271cfg_if! {
272    if #[cfg(any(target_env = "musl", target_env = "ohos"))] {
273        pub use signal::*;
274        pub use sys::socket::*;
275    }
276}
277
278// Per-family headers we export
279cfg_if! {
280    if #[cfg(all(target_family = "unix", not(target_os = "qurt")))] {
281        // FIXME(pthread): eventually all platforms should use this module
282        #[cfg(any(
283            target_os = "android",
284            target_os = "emscripten",
285            target_os = "l4re",
286            target_os = "linux"
287        ))]
288        pub use pthread::*;
289        pub use unistd::*;
290    }
291}