]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/mod.rs
Rollup merge of #54311 - frewsxcv:frewsxcv-readme, r=GuillaumeGomez
[rust.git] / src / libstd / sys / mod.rs
1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! Platform-dependent platform abstraction
12 //!
13 //! The `std::sys` module is the abstracted interface through which
14 //! `std` talks to the underlying operating system. It has different
15 //! implementations for different operating system families, today
16 //! just Unix and Windows, and initial support for Redox.
17 //!
18 //! The centralization of platform-specific code in this module is
19 //! enforced by the "platform abstraction layer" tidy script in
20 //! `tools/tidy/src/pal.rs`.
21 //!
22 //! This module is closely related to the platform-independent system
23 //! integration code in `std::sys_common`. See that module's
24 //! documentation for details.
25 //!
26 //! In the future it would be desirable for the independent
27 //! implementations of this module to be extracted to their own crates
28 //! that `std` can link to, thus enabling their implementation
29 //! out-of-tree via crate replacement. Though due to the complex
30 //! inter-dependencies within `std` that will be a challenging goal to
31 //! achieve.
32
33 #![allow(missing_debug_implementations)]
34
35 cfg_if! {
36     if #[cfg(unix)] {
37         mod unix;
38         pub use self::unix::*;
39     } else if #[cfg(windows)] {
40         mod windows;
41         pub use self::windows::*;
42     } else if #[cfg(target_os = "cloudabi")] {
43         mod cloudabi;
44         pub use self::cloudabi::*;
45     } else if #[cfg(target_os = "redox")] {
46         mod redox;
47         pub use self::redox::*;
48     } else if #[cfg(target_arch = "wasm32")] {
49         mod wasm;
50         pub use self::wasm::*;
51     } else {
52         compile_error!("libstd doesn't compile for this platform yet");
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(rustdoc)]
61 cfg_if! {
62     if #[cfg(any(unix, target_os = "redox"))] {
63         // On unix we'll document what's already available
64         pub use self::ext as unix_ext;
65     } else if #[cfg(any(target_os = "cloudabi", target_arch = "wasm32"))] {
66         // On CloudABI and 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 = "0", feature = "std_internals")]
70         #[allow(missing_docs)]
71         pub mod unix_ext {}
72     } else {
73         // On other platforms like Windows document the bare bones of unix
74         use os::linux as platform;
75         #[path = "unix/ext/mod.rs"]
76         pub mod unix_ext;
77     }
78 }
79
80 #[cfg(rustdoc)]
81 cfg_if! {
82     if #[cfg(windows)] {
83         // On windows we'll just be documenting what's already available
84         #[allow(missing_docs)]
85         pub use self::ext as windows_ext;
86     } else if #[cfg(any(target_os = "cloudabi", target_arch = "wasm32"))] {
87         // On CloudABI and wasm right now the shim below doesn't compile, so
88         // just omit it
89         #[unstable(issue = "0", 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 }