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