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