]> git.lizzy.rs Git - rust.git/blob - library/std/src/sys/mod.rs
Rollup merge of #84320 - jsha:details-implementors, r=Manishearth,Nemo157,GuillaumeGomez
[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(unix)] {
29         mod unix;
30         pub use self::unix::*;
31     } else if #[cfg(windows)] {
32         mod windows;
33         pub use self::windows::*;
34     } else if #[cfg(target_os = "hermit")] {
35         mod hermit;
36         pub use self::hermit::*;
37     } else if #[cfg(target_os = "wasi")] {
38         mod wasi;
39         pub use self::wasi::*;
40     } else if #[cfg(target_arch = "wasm32")] {
41         mod wasm;
42         pub use self::wasm::*;
43     } else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
44         mod sgx;
45         pub use self::sgx::*;
46     } else {
47         mod unsupported;
48         pub use self::unsupported::*;
49     }
50 }
51
52 // Import essential modules from both platforms when documenting. These are
53 // then later used in the `std::os` module when documenting, for example,
54 // Windows when we're compiling for Linux.
55
56 #[cfg(doc)]
57 cfg_if::cfg_if! {
58     if #[cfg(unix)] {
59         // On unix we'll document what's already available
60         #[stable(feature = "rust1", since = "1.0.0")]
61         pub use self::ext as unix_ext;
62     } else if #[cfg(any(target_os = "hermit",
63                         all(target_arch = "wasm32", not(target_os = "wasi")),
64                         all(target_vendor = "fortanix", target_env = "sgx")))] {
65         // On non-WASI wasm right now the module below doesn't compile
66         // (missing things in `libc` which is empty) so just omit everything
67         // with an empty module
68         #[unstable(issue = "none", feature = "std_internals")]
69         #[allow(missing_docs)]
70         pub mod unix_ext {}
71     } else {
72         #[path = "unix/ext/mod.rs"]
73         pub mod unix_ext;
74     }
75 }
76
77 #[cfg(doc)]
78 cfg_if::cfg_if! {
79     if #[cfg(windows)] {
80         // On windows we'll just be documenting what's already available
81         #[allow(missing_docs)]
82         #[stable(feature = "rust1", since = "1.0.0")]
83         pub use self::ext as windows_ext;
84     } else if #[cfg(any(target_os = "hermit",
85                         all(target_arch = "wasm32", not(target_os = "wasi")),
86                         all(target_vendor = "fortanix", target_env = "sgx")))] {
87         // On non-WASI wasm right now the shim below doesn't compile, so
88         // just omit it
89         #[unstable(issue = "none", feature = "std_internals")]
90         #[allow(missing_docs)]
91         pub mod windows_ext {}
92     } else {
93         // On all other platforms (aka linux/osx/etc) then pull in a "minimal"
94         // amount of windows goop which ends up compiling
95         #[macro_use]
96         #[path = "windows/compat.rs"]
97         mod compat;
98
99         #[path = "windows/c.rs"]
100         mod c;
101
102         #[path = "windows/ext/mod.rs"]
103         pub mod windows_ext;
104     }
105 }
106
107 #[cfg(doc)]
108 cfg_if::cfg_if! {
109     if #[cfg(target_os = "wasi")] {
110         // On WASI we'll document what's already available
111         #[stable(feature = "wasi_ext_doc", since = "1.35.0")]
112         pub use self::ext as wasi_ext;
113     } else if #[cfg(any(target_os = "hermit",
114                         target_arch = "wasm32",
115                         all(target_vendor = "fortanix", target_env = "sgx")))] {
116         // On non-WASI wasm right now the module below doesn't compile
117         // (missing things in `libc` which is empty) so just omit everything
118         // with an empty module
119         #[unstable(issue = "none", feature = "std_internals")]
120         #[allow(missing_docs)]
121         pub mod wasi_ext {}
122     } else {
123         // On other platforms like Windows document the bare bones of WASI
124         #[path = "wasi/ext/mod.rs"]
125         #[stable(feature = "wasi_ext_doc", since = "1.35.0")]
126         pub mod wasi_ext;
127     }
128 }