]> git.lizzy.rs Git - rust.git/blob - library/std/src/sys/mod.rs
Auto merge of #84394 - m-ou-se:upgrade-ci-dep-expat, r=Mark-Simulacrum
[rust.git] / library / std / src / sys / mod.rs
1 //! Platform-dependent platform abstraction.
2 //!
3 //! The `std::sys` module is the abstracted interface through which
4 //! `std` talks to the underlying operating system. It has different
5 //! implementations for different operating system families, today
6 //! just Unix and Windows, and initial support for Redox.
7 //!
8 //! The centralization of platform-specific code in this module is
9 //! enforced by the "platform abstraction layer" tidy script in
10 //! `tools/tidy/src/pal.rs`.
11 //!
12 //! This module is closely related to the platform-independent system
13 //! integration code in `std::sys_common`. See that module's
14 //! documentation for details.
15 //!
16 //! In the future it would be desirable for the independent
17 //! implementations of this module to be extracted to their own crates
18 //! that `std` can link to, thus enabling their implementation
19 //! out-of-tree via crate replacement. Though due to the complex
20 //! inter-dependencies within `std` that will be a challenging goal to
21 //! achieve.
22
23 #![allow(missing_debug_implementations)]
24
25 mod common;
26
27 cfg_if::cfg_if! {
28     if #[cfg(target_os = "vxworks")] {
29         mod vxworks;
30         pub use self::vxworks::*;
31     } else if #[cfg(unix)] {
32         mod unix;
33         pub use self::unix::*;
34     } else if #[cfg(windows)] {
35         mod windows;
36         pub use self::windows::*;
37     } else if #[cfg(target_os = "hermit")] {
38         mod hermit;
39         pub use self::hermit::*;
40     } else if #[cfg(target_os = "wasi")] {
41         mod wasi;
42         pub use self::wasi::*;
43     } else if #[cfg(target_arch = "wasm32")] {
44         mod wasm;
45         pub use self::wasm::*;
46     } else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
47         mod sgx;
48         pub use self::sgx::*;
49     } else {
50         mod unsupported;
51         pub use self::unsupported::*;
52     }
53 }
54
55 // Import essential modules from both platforms when documenting. These are
56 // then later used in the `std::os` module when documenting, for example,
57 // Windows when we're compiling for Linux.
58
59 #[cfg(doc)]
60 cfg_if::cfg_if! {
61     if #[cfg(unix)] {
62         // On unix we'll document what's already available
63         #[stable(feature = "rust1", since = "1.0.0")]
64         pub use self::ext as unix_ext;
65     } else if #[cfg(any(target_os = "hermit",
66                         all(target_arch = "wasm32", not(target_os = "wasi")),
67                         all(target_vendor = "fortanix", target_env = "sgx")))] {
68         // On non-WASI wasm right now the module below doesn't compile
69         // (missing things in `libc` which is empty) so just omit everything
70         // with an empty module
71         #[unstable(issue = "none", feature = "std_internals")]
72         #[allow(missing_docs)]
73         pub mod unix_ext {}
74     } else {
75         #[path = "unix/ext/mod.rs"]
76         pub mod unix_ext;
77     }
78 }
79
80 #[cfg(doc)]
81 cfg_if::cfg_if! {
82     if #[cfg(windows)] {
83         // On windows we'll just be documenting what's already available
84         #[allow(missing_docs)]
85         #[stable(feature = "rust1", since = "1.0.0")]
86         pub use self::ext as windows_ext;
87     } else if #[cfg(any(target_os = "hermit",
88                         all(target_arch = "wasm32", not(target_os = "wasi")),
89                         all(target_vendor = "fortanix", target_env = "sgx")))] {
90         // On non-WASI wasm right now the shim below doesn't compile, so
91         // just omit it
92         #[unstable(issue = "none", feature = "std_internals")]
93         #[allow(missing_docs)]
94         pub mod windows_ext {}
95     } else {
96         // On all other platforms (aka linux/osx/etc) then pull in a "minimal"
97         // amount of windows goop which ends up compiling
98         #[macro_use]
99         #[path = "windows/compat.rs"]
100         mod compat;
101
102         #[path = "windows/c.rs"]
103         mod c;
104
105         #[path = "windows/ext/mod.rs"]
106         pub mod windows_ext;
107     }
108 }
109
110 #[cfg(doc)]
111 cfg_if::cfg_if! {
112     if #[cfg(target_os = "wasi")] {
113         // On WASI we'll document what's already available
114         #[stable(feature = "wasi_ext_doc", since = "1.35.0")]
115         pub use self::ext as wasi_ext;
116     } else if #[cfg(any(target_os = "hermit",
117                         target_arch = "wasm32",
118                         all(target_vendor = "fortanix", target_env = "sgx")))] {
119         // On non-WASI wasm right now the module below doesn't compile
120         // (missing things in `libc` which is empty) so just omit everything
121         // with an empty module
122         #[unstable(issue = "none", feature = "std_internals")]
123         #[allow(missing_docs)]
124         pub mod wasi_ext {}
125     } else {
126         // On other platforms like Windows document the bare bones of WASI
127         #[path = "wasi/ext/mod.rs"]
128         #[stable(feature = "wasi_ext_doc", since = "1.35.0")]
129         pub mod wasi_ext;
130     }
131 }