2019-02-09 22:16:58 +00:00
|
|
|
//! Platform-dependent platform abstraction.
|
2016-09-30 23:56:28 +00:00
|
|
|
//!
|
|
|
|
//! The `std::sys` module is the abstracted interface through which
|
|
|
|
//! `std` talks to the underlying operating system. It has different
|
|
|
|
//! implementations for different operating system families, today
|
2017-02-15 18:38:34 +08:00
|
|
|
//! just Unix and Windows, and initial support for Redox.
|
2016-09-30 23:56:28 +00:00
|
|
|
//!
|
|
|
|
//! The centralization of platform-specific code in this module is
|
|
|
|
//! enforced by the "platform abstraction layer" tidy script in
|
2017-02-15 18:38:34 +08:00
|
|
|
//! `tools/tidy/src/pal.rs`.
|
2016-09-30 23:56:28 +00:00
|
|
|
//!
|
|
|
|
//! This module is closely related to the platform-independent system
|
|
|
|
//! integration code in `std::sys_common`. See that module's
|
|
|
|
//! documentation for details.
|
|
|
|
//!
|
2016-11-10 05:15:56 +02:00
|
|
|
//! In the future it would be desirable for the independent
|
2016-09-30 23:56:28 +00:00
|
|
|
//! implementations of this module to be extracted to their own crates
|
|
|
|
//! that `std` can link to, thus enabling their implementation
|
|
|
|
//! out-of-tree via crate replacement. Though due to the complex
|
|
|
|
//! inter-dependencies within `std` that will be a challenging goal to
|
|
|
|
//! achieve.
|
|
|
|
|
2016-12-20 12:18:55 -08:00
|
|
|
#![allow(missing_debug_implementations)]
|
|
|
|
|
2017-11-20 06:22:17 -08:00
|
|
|
cfg_if! {
|
|
|
|
if #[cfg(unix)] {
|
|
|
|
mod unix;
|
|
|
|
pub use self::unix::*;
|
|
|
|
} else if #[cfg(windows)] {
|
|
|
|
mod windows;
|
|
|
|
pub use self::windows::*;
|
Implement libstd for CloudABI.
Though CloudABI is strongly inspired by POSIX, its absence of features
that don't work well with capability-based sandboxing makes it different
enough that adding bits to sys/unix will make things a mess. This change
therefore adds CloudABI specific platform code under sys/cloudabi and
borrows parts from sys/unix that can be used without changes.
One of the goals of this implementation is to build as much as possible
directly on top of CloudABI's system call layer, as opposed to using the
C library. This is preferred, as the system call layer is supposed to be
stable, whereas the C library ABI technically is not. An advantage of
this approach is that it allows us to implement certain interfaces, such
as mutexes and condition variables more optimally. They can be lighter
than the ones provided by pthreads.
This change disables some modules that cannot realistically be
implemented right now. For example, libstd's pathname abstraction is not
designed with POSIX *at() (e.g., openat()) in mind. The *at() functions
are the only set of file system APIs available on CloudABI. There is no
global file system namespace, nor a process working directory.
Discussions on how to port these modules over are outside the scope of
this change.
Apart from this change, there are still some other minor fixups that
need to be made to platform independent code to make things build. These
will be sent out separately, so they can be reviewed more thoroughly.
2018-01-08 10:51:25 +01:00
|
|
|
} else if #[cfg(target_os = "cloudabi")] {
|
|
|
|
mod cloudabi;
|
|
|
|
pub use self::cloudabi::*;
|
2017-11-20 06:22:17 -08:00
|
|
|
} else if #[cfg(target_os = "redox")] {
|
|
|
|
mod redox;
|
|
|
|
pub use self::redox::*;
|
|
|
|
} else if #[cfg(target_arch = "wasm32")] {
|
|
|
|
mod wasm;
|
|
|
|
pub use self::wasm::*;
|
2018-12-31 15:45:42 -08:00
|
|
|
} else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
|
2018-08-27 21:33:26 -07:00
|
|
|
mod sgx;
|
|
|
|
pub use self::sgx::*;
|
2017-11-20 06:22:17 -08:00
|
|
|
} else {
|
|
|
|
compile_error!("libstd doesn't compile for this platform yet");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Import essential modules from both platforms when documenting. These are
|
|
|
|
// then later used in the `std::os` module when documenting, for example,
|
|
|
|
// Windows when we're compiling for Linux.
|
|
|
|
|
2018-08-04 18:29:47 -05:00
|
|
|
#[cfg(rustdoc)]
|
2017-11-20 06:22:17 -08:00
|
|
|
cfg_if! {
|
|
|
|
if #[cfg(any(unix, target_os = "redox"))] {
|
|
|
|
// On unix we'll document what's already available
|
2019-01-26 20:30:52 +01:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2017-11-20 06:22:17 -08:00
|
|
|
pub use self::ext as unix_ext;
|
2018-12-31 15:45:42 -08:00
|
|
|
} else if #[cfg(any(target_os = "cloudabi",
|
|
|
|
target_arch = "wasm32",
|
|
|
|
all(target_vendor = "fortanix", target_env = "sgx")))] {
|
2018-01-11 11:21:12 +01:00
|
|
|
// On CloudABI and wasm right now the module below doesn't compile
|
|
|
|
// (missing things in `libc` which is empty) so just omit everything
|
|
|
|
// with an empty module
|
2017-11-20 06:22:17 -08:00
|
|
|
#[unstable(issue = "0", feature = "std_internals")]
|
2018-06-20 00:04:59 +02:00
|
|
|
#[allow(missing_docs)]
|
2017-11-20 06:22:17 -08:00
|
|
|
pub mod unix_ext {}
|
|
|
|
} else {
|
|
|
|
// On other platforms like Windows document the bare bones of unix
|
2019-02-11 04:23:21 +09:00
|
|
|
use crate::os::linux as platform;
|
2017-11-20 06:22:17 -08:00
|
|
|
#[path = "unix/ext/mod.rs"]
|
|
|
|
pub mod unix_ext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-04 18:29:47 -05:00
|
|
|
#[cfg(rustdoc)]
|
2017-11-20 06:22:17 -08:00
|
|
|
cfg_if! {
|
|
|
|
if #[cfg(windows)] {
|
|
|
|
// On windows we'll just be documenting what's already available
|
2018-06-20 00:04:59 +02:00
|
|
|
#[allow(missing_docs)]
|
2019-01-26 20:30:52 +01:00
|
|
|
#[stable(feature = "rust1", since = "1.0.0")]
|
2017-11-20 06:22:17 -08:00
|
|
|
pub use self::ext as windows_ext;
|
2018-12-31 15:45:42 -08:00
|
|
|
} else if #[cfg(any(target_os = "cloudabi",
|
|
|
|
target_arch = "wasm32",
|
|
|
|
all(target_vendor = "fortanix", target_env = "sgx")))] {
|
2018-01-11 11:21:12 +01:00
|
|
|
// On CloudABI and wasm right now the shim below doesn't compile, so
|
|
|
|
// just omit it
|
2017-11-20 06:22:17 -08:00
|
|
|
#[unstable(issue = "0", feature = "std_internals")]
|
2018-06-25 20:38:29 +02:00
|
|
|
#[allow(missing_docs)]
|
2017-11-20 06:22:17 -08:00
|
|
|
pub mod windows_ext {}
|
|
|
|
} else {
|
|
|
|
// On all other platforms (aka linux/osx/etc) then pull in a "minimal"
|
|
|
|
// amount of windows goop which ends up compiling
|
|
|
|
#[macro_use]
|
|
|
|
#[path = "windows/compat.rs"]
|
|
|
|
mod compat;
|
|
|
|
|
|
|
|
#[path = "windows/c.rs"]
|
|
|
|
mod c;
|
|
|
|
|
|
|
|
#[path = "windows/ext/mod.rs"]
|
|
|
|
pub mod windows_ext;
|
|
|
|
}
|
|
|
|
}
|