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