From e2d01eddc3034aa3a418ce41247c129a342601f8 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 3 Sep 2021 17:21:52 +0200 Subject: [PATCH 1/3] Simplify std::os module reexports to fix rustdoc linking issues --- library/std/src/os/mod.rs | 183 +++++++++++++++----------------------- 1 file changed, 74 insertions(+), 109 deletions(-) diff --git a/library/std/src/os/mod.rs b/library/std/src/os/mod.rs index 79e6967300767..1a4d77e00bf07 100644 --- a/library/std/src/os/mod.rs +++ b/library/std/src/os/mod.rs @@ -10,117 +10,82 @@ pub mod raw; // 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(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. - - pub mod unix; - - pub mod linux; - - pub mod wasi; - - 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. - - #[unstable(issue = "none", feature = "std_internals")] - pub mod unix {} - - #[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 {} +// 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 and add the "unstable" attribute. + +#[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] +pub mod fortanix_sgx; + +// Unix, linux, wasi and windows are handled a bit differently. +cfg_if::cfg_if! { + if #[cfg(all( + doc, + any( + all(target_arch = "wasm32", not(target_os = "wasi")), + all(target_vendor = "fortanix", target_env = "sgx") + ) + ))] + { + #[unstable(issue = "none", feature = "std_internals")] + pub mod unix {} + #[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 {} + } else { + #[cfg(target_os = "hermit")] + #[path = "hermit/mod.rs"] + pub mod unix; + + #[cfg(any(unix, doc))] + pub mod unix; + + #[cfg(any(target_os = "linux", target_os = "l4re", doc))] + pub mod linux; + + #[cfg(any(target_os = "wasi", doc))] + pub mod wasi; + + #[cfg(any(windows, doc))] + pub mod windows; + } } -#[cfg(doc)] -#[stable(feature = "os", since = "1.0.0")] -pub use doc::*; - -#[cfg(not(doc))] -#[path = "."] -mod imp { - // If we're not documenting std then we only expose modules appropriate for the - // current platform. - - #[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 = "espidf")] - pub mod espidf; - #[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::*; +// Others. +#[cfg(target_os = "android")] +pub mod android; +#[cfg(target_os = "dragonfly")] +pub mod dragonfly; +#[cfg(target_os = "emscripten")] +pub mod emscripten; +#[cfg(target_os = "espidf")] +pub mod espidf; +#[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; #[cfg(any(unix, target_os = "wasi", doc))] mod fd; From 64354a9ea27b62edb8db9e6eddfc413ec58ca183 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 3 Sep 2021 21:13:52 +0200 Subject: [PATCH 2/3] Remove usage of cfg_if in std/src/os/mod.rs --- library/std/src/os/mod.rs | 102 ++++++++++++++++++++++++++------------ 1 file changed, 71 insertions(+), 31 deletions(-) diff --git a/library/std/src/os/mod.rs b/library/std/src/os/mod.rs index 1a4d77e00bf07..3f02a650e3541 100644 --- a/library/std/src/os/mod.rs +++ b/library/std/src/os/mod.rs @@ -18,41 +18,81 @@ pub mod raw; pub mod fortanix_sgx; // Unix, linux, wasi and windows are handled a bit differently. -cfg_if::cfg_if! { - if #[cfg(all( - doc, - any( - all(target_arch = "wasm32", not(target_os = "wasi")), - all(target_vendor = "fortanix", target_env = "sgx") - ) - ))] - { - #[unstable(issue = "none", feature = "std_internals")] - pub mod unix {} - #[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 {} - } else { - #[cfg(target_os = "hermit")] - #[path = "hermit/mod.rs"] - pub mod unix; +#[cfg(all( + doc, + any( + all(target_arch = "wasm32", not(target_os = "wasi")), + all(target_vendor = "fortanix", target_env = "sgx") + ) +))] +#[unstable(issue = "none", feature = "std_internals")] +pub mod unix {} +#[cfg(all( + doc, + any( + all(target_arch = "wasm32", not(target_os = "wasi")), + all(target_vendor = "fortanix", target_env = "sgx") + ) +))] +#[unstable(issue = "none", feature = "std_internals")] +pub mod linux {} +#[cfg(all( + doc, + any( + all(target_arch = "wasm32", not(target_os = "wasi")), + all(target_vendor = "fortanix", target_env = "sgx") + ) +))] +#[unstable(issue = "none", feature = "std_internals")] +pub mod wasi {} +#[cfg(all( + doc, + any( + all(target_arch = "wasm32", not(target_os = "wasi")), + all(target_vendor = "fortanix", target_env = "sgx") + ) +))] +#[unstable(issue = "none", feature = "std_internals")] +pub mod windows {} - #[cfg(any(unix, doc))] - pub mod unix; +// unix +#[cfg(not(any( + all(target_arch = "wasm32", not(target_os = "wasi")), + all(target_vendor = "fortanix", target_env = "sgx") +)))] +#[cfg(all(not(doc), target_os = "hermit"))] +#[path = "hermit/mod.rs"] +pub mod unix; +#[cfg(not(any( + all(target_arch = "wasm32", not(target_os = "wasi")), + all(target_vendor = "fortanix", target_env = "sgx") +)))] +#[cfg(any(unix, doc))] +pub mod unix; - #[cfg(any(target_os = "linux", target_os = "l4re", doc))] - pub mod linux; +// linux +#[cfg(not(any( + all(target_arch = "wasm32", not(target_os = "wasi")), + all(target_vendor = "fortanix", target_env = "sgx") +)))] +#[cfg(any(target_os = "linux", target_os = "l4re", doc))] +pub mod linux; - #[cfg(any(target_os = "wasi", doc))] - pub mod wasi; +// wasi +#[cfg(not(any( + all(target_arch = "wasm32", not(target_os = "wasi")), + all(target_vendor = "fortanix", target_env = "sgx") +)))] +#[cfg(any(target_os = "wasi", doc))] +pub mod wasi; - #[cfg(any(windows, doc))] - pub mod windows; - } -} +// windows +#[cfg(not(any( + all(target_arch = "wasm32", not(target_os = "wasi")), + all(target_vendor = "fortanix", target_env = "sgx") +)))] +#[cfg(any(windows, doc))] +pub mod windows; // Others. #[cfg(target_os = "android")] From 88d5aa62dc6e30e6b48e2c280e914752ea26937e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 7 Sep 2021 15:44:08 +0200 Subject: [PATCH 3/3] Move fortanix module position in std::os reexports for alpha sort --- library/std/src/os/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/library/std/src/os/mod.rs b/library/std/src/os/mod.rs index 3f02a650e3541..eb9967a8a7ab3 100644 --- a/library/std/src/os/mod.rs +++ b/library/std/src/os/mod.rs @@ -14,9 +14,6 @@ pub mod raw; // documented don't compile (missing things in `libc` which is empty), // so just omit them with an empty module and add the "unstable" attribute. -#[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] -pub mod fortanix_sgx; - // Unix, linux, wasi and windows are handled a bit differently. #[cfg(all( doc, @@ -103,6 +100,8 @@ pub mod dragonfly; pub mod emscripten; #[cfg(target_os = "espidf")] pub mod espidf; +#[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] +pub mod fortanix_sgx; #[cfg(target_os = "freebsd")] pub mod freebsd; #[cfg(target_os = "fuchsia")]