Skip to content

Commit

Permalink
Auto merge of rust-lang#84200 - CDirkx:os, r=m-ou-se
Browse files Browse the repository at this point in the history
Move all `sys::ext` modules to `os`

This PR moves all `sys::ext` modules to `os`, centralizing the location of all `os` code and simplifying the dependencies between `os` and `sys`.

Because this also removes all uses `cfg_if!` on publicly exported items, where after rust-lang#81969 there were still a few left, this should properly work around rust-lang/rust-analyzer#6038.

`@rustbot` label: +T-libs-impl
  • Loading branch information
bors committed May 5, 2021
2 parents 24acc38 + 2173d8d commit 342db70
Show file tree
Hide file tree
Showing 47 changed files with 162 additions and 191 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 4 additions & 2 deletions library/std/src/os/fortanix_sgx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! This includes functions to deal with memory isolation, usercalls, and the
//! SGX instruction set.

#![deny(missing_docs, missing_debug_implementations)]
#![deny(missing_docs)]
#![unstable(feature = "sgx_platform", issue = "56975")]

/// Low-level interfaces to usercalls. See the [ABI documentation] for more
Expand Down Expand Up @@ -43,7 +43,9 @@ pub mod mem {
pub use crate::sys::abi::mem::*;
}

pub use crate::sys::ext::{arch, ffi, io};
pub mod arch;
pub mod ffi;
pub mod io;

/// Functions for querying thread-related information.
pub mod thread {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![stable(feature = "rust1", since = "1.0.0")]
#![allow(missing_docs)]

pub mod ffi;

Expand Down
1 change: 1 addition & 0 deletions library/std/src/os/linux/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Linux-specific definitions.

#![stable(feature = "raw_ext", since = "1.1.0")]
#![doc(cfg(target_os = "linux"))]

pub mod fs;
pub mod raw;
1 change: 0 additions & 1 deletion library/std/src/os/linux/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
definitions"
)]
#![allow(deprecated)]
#![allow(missing_debug_implementations)]

use crate::os::raw::c_ulong;

Expand Down
169 changes: 105 additions & 64 deletions library/std/src/os/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,78 +3,119 @@
#![stable(feature = "os", since = "1.0.0")]
#![allow(missing_docs, nonstandard_style, missing_debug_implementations)]

// When documenting libstd we want to show unix/windows/linux/wasi modules as these are the "main
// modules" that are used across platforms, so all modules are enabled when `cfg(doc)` is set.
// This should help show platform-specific functionality in a hopefully cross-platform way in the
// documentation.
// Note that we deliberately avoid `cfg_if!` here to work around a rust-analyzer bug that would make
// `std::os` submodules unusable: https://github.com/rust-analyzer/rust-analyzer/issues/6038
pub mod raw;

#[cfg(doc)]
#[stable(feature = "rust1", since = "1.0.0")]
pub use crate::sys::unix_ext as unix;
// The code below could be written clearer using `cfg_if!`. However, the items below are
// publicly exported by `std` and external tools can have trouble analysing them because of the use
// of a macro that is not vendored by Rust and included in the toolchain.
// See https://github.com/rust-analyzer/rust-analyzer/issues/6038.

#[cfg(doc)]
#[stable(feature = "rust1", since = "1.0.0")]
pub use crate::sys::windows_ext as windows;
#[cfg(all(
doc,
not(any(
all(target_arch = "wasm32", not(target_os = "wasi")),
all(target_vendor = "fortanix", target_env = "sgx")
))
))]
#[path = "."]
mod doc {
// When documenting std we want to show the `unix`, `windows`, `linux` and `wasi`
// modules as these are the "main modules" that are used across platforms,
// so these modules are enabled when `cfg(doc)` is set.
// This should help show platform-specific functionality in a hopefully cross-platform
// way in the documentation.

#[cfg(doc)]
#[doc(cfg(target_os = "linux"))]
pub mod linux;
pub mod unix;

#[cfg(doc)]
#[stable(feature = "wasi_ext_doc", since = "1.35.0")]
pub use crate::sys::wasi_ext as wasi;
pub mod linux;

// If we're not documenting libstd then we just expose the main modules as we otherwise would.
pub mod wasi;

#[cfg(not(doc))]
#[cfg(any(unix, target_os = "hermit"))]
#[stable(feature = "rust1", since = "1.0.0")]
pub use crate::sys::ext as unix;
pub mod windows;
}
#[cfg(all(
doc,
any(
all(target_arch = "wasm32", not(target_os = "wasi")),
all(target_vendor = "fortanix", target_env = "sgx")
)
))]
mod doc {
// On certain platforms right now the "main modules" modules that are
// documented don't compile (missing things in `libc` which is empty),
// so just omit them with an empty module.

#[cfg(not(doc))]
#[cfg(windows)]
#[stable(feature = "rust1", since = "1.0.0")]
pub use crate::sys::ext as windows;
#[unstable(issue = "none", feature = "std_internals")]
pub mod unix {}

#[cfg(not(doc))]
#[cfg(any(target_os = "linux", target_os = "l4re"))]
pub mod linux;
#[unstable(issue = "none", feature = "std_internals")]
pub mod linux {}

#[unstable(issue = "none", feature = "std_internals")]
pub mod wasi {}

#[unstable(issue = "none", feature = "std_internals")]
pub mod windows {}
}
#[cfg(doc)]
#[stable(feature = "os", since = "1.0.0")]
pub use doc::*;

#[cfg(not(doc))]
#[cfg(target_os = "wasi")]
pub mod wasi;

#[cfg(target_os = "android")]
pub mod android;
#[cfg(target_os = "dragonfly")]
pub mod dragonfly;
#[cfg(target_os = "emscripten")]
pub mod emscripten;
#[cfg(all(target_vendor = "fortanix", target_env = "sgx"))]
pub mod fortanix_sgx;
#[cfg(target_os = "freebsd")]
pub mod freebsd;
#[cfg(target_os = "fuchsia")]
pub mod fuchsia;
#[cfg(target_os = "haiku")]
pub mod haiku;
#[cfg(target_os = "illumos")]
pub mod illumos;
#[cfg(target_os = "ios")]
pub mod ios;
#[cfg(target_os = "macos")]
pub mod macos;
#[cfg(target_os = "netbsd")]
pub mod netbsd;
#[cfg(target_os = "openbsd")]
pub mod openbsd;
#[cfg(target_os = "redox")]
pub mod redox;
#[cfg(target_os = "solaris")]
pub mod solaris;
#[cfg(target_os = "vxworks")]
pub mod vxworks;
#[path = "."]
mod imp {
// If we're not documenting std then we only expose modules appropriate for the
// current platform.

pub mod raw;
#[cfg(all(target_vendor = "fortanix", target_env = "sgx"))]
pub mod fortanix_sgx;

#[cfg(target_os = "hermit")]
#[path = "hermit/mod.rs"]
pub mod unix;

#[cfg(target_os = "android")]
pub mod android;
#[cfg(target_os = "dragonfly")]
pub mod dragonfly;
#[cfg(target_os = "emscripten")]
pub mod emscripten;
#[cfg(target_os = "freebsd")]
pub mod freebsd;
#[cfg(target_os = "fuchsia")]
pub mod fuchsia;
#[cfg(target_os = "haiku")]
pub mod haiku;
#[cfg(target_os = "illumos")]
pub mod illumos;
#[cfg(target_os = "ios")]
pub mod ios;
#[cfg(target_os = "l4re")]
pub mod linux;
#[cfg(target_os = "linux")]
pub mod linux;
#[cfg(target_os = "macos")]
pub mod macos;
#[cfg(target_os = "netbsd")]
pub mod netbsd;
#[cfg(target_os = "openbsd")]
pub mod openbsd;
#[cfg(target_os = "redox")]
pub mod redox;
#[cfg(target_os = "solaris")]
pub mod solaris;
#[cfg(unix)]
pub mod unix;

#[cfg(target_os = "vxworks")]
pub mod vxworks;

#[cfg(target_os = "wasi")]
pub mod wasi;

#[cfg(windows)]
pub mod windows;
}
#[cfg(not(doc))]
#[stable(feature = "os", since = "1.0.0")]
pub use imp::*;
1 change: 0 additions & 1 deletion library/std/src/os/redox/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
definitions"
)]
#![allow(deprecated)]
#![allow(missing_debug_implementations)]

use crate::os::raw::{c_char, c_int, c_long, c_ulong, c_void};

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -27,44 +27,43 @@

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(cfg(unix))]
#![allow(missing_docs)]

cfg_if::cfg_if! {
if #[cfg(doc)] {
// Use linux as the default platform when documenting on other platforms like Windows
use crate::os::linux as platform;
} else {
#[cfg(target_os = "android")]
use crate::os::android as platform;
#[cfg(target_os = "dragonfly")]
use crate::os::dragonfly as platform;
#[cfg(target_os = "emscripten")]
use crate::os::emscripten as platform;
#[cfg(target_os = "freebsd")]
use crate::os::freebsd as platform;
#[cfg(target_os = "fuchsia")]
use crate::os::fuchsia as platform;
#[cfg(target_os = "haiku")]
use crate::os::haiku as platform;
#[cfg(target_os = "illumos")]
use crate::os::illumos as platform;
#[cfg(target_os = "ios")]
use crate::os::ios as platform;
#[cfg(any(target_os = "linux", target_os = "l4re"))]
use crate::os::linux as platform;
#[cfg(target_os = "macos")]
use crate::os::macos as platform;
#[cfg(target_os = "netbsd")]
use crate::os::netbsd as platform;
#[cfg(target_os = "openbsd")]
use crate::os::openbsd as platform;
#[cfg(target_os = "redox")]
use crate::os::redox as platform;
#[cfg(target_os = "solaris")]
use crate::os::solaris as platform;
#[cfg(target_os = "vxworks")]
use crate::os::vxworks as platform;
}
// Use linux as the default platform when documenting on other platforms like Windows
#[cfg(doc)]
use crate::os::linux as platform;

#[cfg(not(doc))]
mod platform {
#[cfg(target_os = "android")]
pub use crate::os::android::*;
#[cfg(target_os = "dragonfly")]
pub use crate::os::dragonfly::*;
#[cfg(target_os = "emscripten")]
pub use crate::os::emscripten::*;
#[cfg(target_os = "freebsd")]
pub use crate::os::freebsd::*;
#[cfg(target_os = "fuchsia")]
pub use crate::os::fuchsia::*;
#[cfg(target_os = "haiku")]
pub use crate::os::haiku::*;
#[cfg(target_os = "illumos")]
pub use crate::os::illumos::*;
#[cfg(target_os = "ios")]
pub use crate::os::ios::*;
#[cfg(any(target_os = "linux", target_os = "l4re"))]
pub use crate::os::linux::*;
#[cfg(target_os = "macos")]
pub use crate::os::macos::*;
#[cfg(target_os = "netbsd")]
pub use crate::os::netbsd::*;
#[cfg(target_os = "openbsd")]
pub use crate::os::openbsd::*;
#[cfg(target_os = "redox")]
pub use crate::os::redox::*;
#[cfg(target_os = "solaris")]
pub use crate::os::solaris::*;
#[cfg(target_os = "vxworks")]
pub use crate::os::vxworks::*;
}

pub mod ffi;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 0 additions & 6 deletions library/std/src/os/wasi.rs

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
//! }
//! ```

#![stable(feature = "rust1", since = "1.0.0")]
#![deny(unsafe_op_in_unsafe_fn)]
#![doc(cfg(target_os = "wasi"))]

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(cfg(windows))]
#![allow(missing_docs)]

pub mod ffi;
pub mod fs;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion library/std/src/sys/hermit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub mod args;
pub mod cmath;
pub mod condvar;
pub mod env;
pub mod ext;
pub mod fd;
pub mod fs;
#[path = "../unsupported/io.rs"]
Expand Down
Loading

0 comments on commit 342db70

Please sign in to comment.