From e0d9244472b50631f07af8a425c1dbed65161d25 Mon Sep 17 00:00:00 2001 From: Thalia Archibald Date: Tue, 15 Apr 2025 05:29:38 -0700 Subject: [PATCH 1/4] Sort Unix env constants alphabetically by target_os They were roughly grouped into Linux, Apple, BSD, and everything else, roughly in alphabetical order. Alphabetically order them to make it easier to maintain and discard the Unix-specific groups to generalize it to all platforms. --- library/std/src/sys/pal/unix/env.rs | 198 ++++++++++++++-------------- 1 file changed, 100 insertions(+), 98 deletions(-) diff --git a/library/std/src/sys/pal/unix/env.rs b/library/std/src/sys/pal/unix/env.rs index c6609298f4b23..1a5e23f06b804 100644 --- a/library/std/src/sys/pal/unix/env.rs +++ b/library/std/src/sys/pal/unix/env.rs @@ -1,73 +1,64 @@ -#[cfg(target_os = "linux")] -pub mod os { - pub const FAMILY: &str = "unix"; - pub const OS: &str = "linux"; - pub const DLL_PREFIX: &str = "lib"; - pub const DLL_SUFFIX: &str = ".so"; - pub const DLL_EXTENSION: &str = "so"; - pub const EXE_SUFFIX: &str = ""; - pub const EXE_EXTENSION: &str = ""; -} +// Keep entries sorted alphabetically. -#[cfg(target_os = "macos")] +#[cfg(target_os = "aix")] pub mod os { pub const FAMILY: &str = "unix"; - pub const OS: &str = "macos"; + pub const OS: &str = "aix"; pub const DLL_PREFIX: &str = "lib"; - pub const DLL_SUFFIX: &str = ".dylib"; - pub const DLL_EXTENSION: &str = "dylib"; + pub const DLL_SUFFIX: &str = ".a"; + pub const DLL_EXTENSION: &str = "a"; pub const EXE_SUFFIX: &str = ""; pub const EXE_EXTENSION: &str = ""; } -#[cfg(target_os = "ios")] +#[cfg(target_os = "android")] pub mod os { pub const FAMILY: &str = "unix"; - pub const OS: &str = "ios"; + pub const OS: &str = "android"; pub const DLL_PREFIX: &str = "lib"; - pub const DLL_SUFFIX: &str = ".dylib"; - pub const DLL_EXTENSION: &str = "dylib"; + pub const DLL_SUFFIX: &str = ".so"; + pub const DLL_EXTENSION: &str = "so"; pub const EXE_SUFFIX: &str = ""; pub const EXE_EXTENSION: &str = ""; } -#[cfg(target_os = "tvos")] +#[cfg(target_os = "cygwin")] pub mod os { pub const FAMILY: &str = "unix"; - pub const OS: &str = "tvos"; - pub const DLL_PREFIX: &str = "lib"; - pub const DLL_SUFFIX: &str = ".dylib"; - pub const DLL_EXTENSION: &str = "dylib"; - pub const EXE_SUFFIX: &str = ""; - pub const EXE_EXTENSION: &str = ""; + pub const OS: &str = "cygwin"; + pub const DLL_PREFIX: &str = ""; + pub const DLL_SUFFIX: &str = ".dll"; + pub const DLL_EXTENSION: &str = "dll"; + pub const EXE_SUFFIX: &str = ".exe"; + pub const EXE_EXTENSION: &str = "exe"; } -#[cfg(target_os = "watchos")] +#[cfg(target_os = "dragonfly")] pub mod os { pub const FAMILY: &str = "unix"; - pub const OS: &str = "watchos"; + pub const OS: &str = "dragonfly"; pub const DLL_PREFIX: &str = "lib"; - pub const DLL_SUFFIX: &str = ".dylib"; - pub const DLL_EXTENSION: &str = "dylib"; + pub const DLL_SUFFIX: &str = ".so"; + pub const DLL_EXTENSION: &str = "so"; pub const EXE_SUFFIX: &str = ""; pub const EXE_EXTENSION: &str = ""; } -#[cfg(target_os = "visionos")] +#[cfg(all(target_os = "emscripten", target_arch = "wasm32"))] pub mod os { pub const FAMILY: &str = "unix"; - pub const OS: &str = "visionos"; + pub const OS: &str = "emscripten"; pub const DLL_PREFIX: &str = "lib"; - pub const DLL_SUFFIX: &str = ".dylib"; - pub const DLL_EXTENSION: &str = "dylib"; - pub const EXE_SUFFIX: &str = ""; - pub const EXE_EXTENSION: &str = ""; + pub const DLL_SUFFIX: &str = ".so"; + pub const DLL_EXTENSION: &str = "so"; + pub const EXE_SUFFIX: &str = ".js"; + pub const EXE_EXTENSION: &str = "js"; } -#[cfg(target_os = "freebsd")] +#[cfg(target_os = "espidf")] pub mod os { pub const FAMILY: &str = "unix"; - pub const OS: &str = "freebsd"; + pub const OS: &str = "espidf"; pub const DLL_PREFIX: &str = "lib"; pub const DLL_SUFFIX: &str = ".so"; pub const DLL_EXTENSION: &str = "so"; @@ -75,10 +66,10 @@ pub mod os { pub const EXE_EXTENSION: &str = ""; } -#[cfg(target_os = "dragonfly")] +#[cfg(target_os = "freebsd")] pub mod os { pub const FAMILY: &str = "unix"; - pub const OS: &str = "dragonfly"; + pub const OS: &str = "freebsd"; pub const DLL_PREFIX: &str = "lib"; pub const DLL_SUFFIX: &str = ".so"; pub const DLL_EXTENSION: &str = "so"; @@ -86,10 +77,10 @@ pub mod os { pub const EXE_EXTENSION: &str = ""; } -#[cfg(target_os = "netbsd")] +#[cfg(target_os = "fuchsia")] pub mod os { pub const FAMILY: &str = "unix"; - pub const OS: &str = "netbsd"; + pub const OS: &str = "fuchsia"; pub const DLL_PREFIX: &str = "lib"; pub const DLL_SUFFIX: &str = ".so"; pub const DLL_EXTENSION: &str = "so"; @@ -97,10 +88,10 @@ pub mod os { pub const EXE_EXTENSION: &str = ""; } -#[cfg(target_os = "openbsd")] +#[cfg(target_os = "haiku")] pub mod os { pub const FAMILY: &str = "unix"; - pub const OS: &str = "openbsd"; + pub const OS: &str = "haiku"; pub const DLL_PREFIX: &str = "lib"; pub const DLL_SUFFIX: &str = ".so"; pub const DLL_EXTENSION: &str = "so"; @@ -108,32 +99,21 @@ pub mod os { pub const EXE_EXTENSION: &str = ""; } -#[cfg(target_os = "cygwin")] -pub mod os { - pub const FAMILY: &str = "unix"; - pub const OS: &str = "cygwin"; - pub const DLL_PREFIX: &str = ""; - pub const DLL_SUFFIX: &str = ".dll"; - pub const DLL_EXTENSION: &str = "dll"; - pub const EXE_SUFFIX: &str = ".exe"; - pub const EXE_EXTENSION: &str = "exe"; -} - -#[cfg(target_os = "android")] +#[cfg(target_os = "horizon")] pub mod os { pub const FAMILY: &str = "unix"; - pub const OS: &str = "android"; + pub const OS: &str = "horizon"; pub const DLL_PREFIX: &str = "lib"; pub const DLL_SUFFIX: &str = ".so"; pub const DLL_EXTENSION: &str = "so"; - pub const EXE_SUFFIX: &str = ""; - pub const EXE_EXTENSION: &str = ""; + pub const EXE_SUFFIX: &str = ".elf"; + pub const EXE_EXTENSION: &str = "elf"; } -#[cfg(target_os = "solaris")] +#[cfg(target_os = "hurd")] pub mod os { pub const FAMILY: &str = "unix"; - pub const OS: &str = "solaris"; + pub const OS: &str = "hurd"; pub const DLL_PREFIX: &str = "lib"; pub const DLL_SUFFIX: &str = ".so"; pub const DLL_EXTENSION: &str = "so"; @@ -152,32 +132,32 @@ pub mod os { pub const EXE_EXTENSION: &str = ""; } -#[cfg(target_os = "haiku")] +#[cfg(target_os = "ios")] pub mod os { pub const FAMILY: &str = "unix"; - pub const OS: &str = "haiku"; + pub const OS: &str = "ios"; pub const DLL_PREFIX: &str = "lib"; - pub const DLL_SUFFIX: &str = ".so"; - pub const DLL_EXTENSION: &str = "so"; + pub const DLL_SUFFIX: &str = ".dylib"; + pub const DLL_EXTENSION: &str = "dylib"; pub const EXE_SUFFIX: &str = ""; pub const EXE_EXTENSION: &str = ""; } -#[cfg(target_os = "horizon")] +#[cfg(target_os = "l4re")] pub mod os { pub const FAMILY: &str = "unix"; - pub const OS: &str = "horizon"; + pub const OS: &str = "l4re"; pub const DLL_PREFIX: &str = "lib"; pub const DLL_SUFFIX: &str = ".so"; pub const DLL_EXTENSION: &str = "so"; - pub const EXE_SUFFIX: &str = ".elf"; - pub const EXE_EXTENSION: &str = "elf"; + pub const EXE_SUFFIX: &str = ""; + pub const EXE_EXTENSION: &str = ""; } -#[cfg(target_os = "hurd")] +#[cfg(target_os = "linux")] pub mod os { pub const FAMILY: &str = "unix"; - pub const OS: &str = "hurd"; + pub const OS: &str = "linux"; pub const DLL_PREFIX: &str = "lib"; pub const DLL_SUFFIX: &str = ".so"; pub const DLL_EXTENSION: &str = "so"; @@ -185,32 +165,32 @@ pub mod os { pub const EXE_EXTENSION: &str = ""; } -#[cfg(target_os = "vita")] +#[cfg(target_os = "macos")] pub mod os { pub const FAMILY: &str = "unix"; - pub const OS: &str = "vita"; + pub const OS: &str = "macos"; pub const DLL_PREFIX: &str = "lib"; - pub const DLL_SUFFIX: &str = ".so"; - pub const DLL_EXTENSION: &str = "so"; - pub const EXE_SUFFIX: &str = ".elf"; - pub const EXE_EXTENSION: &str = "elf"; + pub const DLL_SUFFIX: &str = ".dylib"; + pub const DLL_EXTENSION: &str = "dylib"; + pub const EXE_SUFFIX: &str = ""; + pub const EXE_EXTENSION: &str = ""; } -#[cfg(all(target_os = "emscripten", target_arch = "wasm32"))] +#[cfg(target_os = "netbsd")] pub mod os { pub const FAMILY: &str = "unix"; - pub const OS: &str = "emscripten"; + pub const OS: &str = "netbsd"; pub const DLL_PREFIX: &str = "lib"; pub const DLL_SUFFIX: &str = ".so"; pub const DLL_EXTENSION: &str = "so"; - pub const EXE_SUFFIX: &str = ".js"; - pub const EXE_EXTENSION: &str = "js"; + pub const EXE_SUFFIX: &str = ""; + pub const EXE_EXTENSION: &str = ""; } -#[cfg(target_os = "fuchsia")] +#[cfg(target_os = "nto")] pub mod os { pub const FAMILY: &str = "unix"; - pub const OS: &str = "fuchsia"; + pub const OS: &str = "nto"; pub const DLL_PREFIX: &str = "lib"; pub const DLL_SUFFIX: &str = ".so"; pub const DLL_EXTENSION: &str = "so"; @@ -218,10 +198,10 @@ pub mod os { pub const EXE_EXTENSION: &str = ""; } -#[cfg(target_os = "l4re")] +#[cfg(target_os = "nuttx")] pub mod os { pub const FAMILY: &str = "unix"; - pub const OS: &str = "l4re"; + pub const OS: &str = "nuttx"; pub const DLL_PREFIX: &str = "lib"; pub const DLL_SUFFIX: &str = ".so"; pub const DLL_EXTENSION: &str = "so"; @@ -229,10 +209,10 @@ pub mod os { pub const EXE_EXTENSION: &str = ""; } -#[cfg(target_os = "nto")] +#[cfg(target_os = "openbsd")] pub mod os { pub const FAMILY: &str = "unix"; - pub const OS: &str = "nto"; + pub const OS: &str = "openbsd"; pub const DLL_PREFIX: &str = "lib"; pub const DLL_SUFFIX: &str = ".so"; pub const DLL_EXTENSION: &str = "so"; @@ -262,10 +242,10 @@ pub mod os { pub const EXE_EXTENSION: &str = ""; } -#[cfg(target_os = "vxworks")] +#[cfg(target_os = "solaris")] pub mod os { pub const FAMILY: &str = "unix"; - pub const OS: &str = "vxworks"; + pub const OS: &str = "solaris"; pub const DLL_PREFIX: &str = "lib"; pub const DLL_SUFFIX: &str = ".so"; pub const DLL_EXTENSION: &str = "so"; @@ -273,35 +253,57 @@ pub mod os { pub const EXE_EXTENSION: &str = ""; } -#[cfg(target_os = "espidf")] +#[cfg(target_os = "tvos")] pub mod os { pub const FAMILY: &str = "unix"; - pub const OS: &str = "espidf"; + pub const OS: &str = "tvos"; pub const DLL_PREFIX: &str = "lib"; - pub const DLL_SUFFIX: &str = ".so"; - pub const DLL_EXTENSION: &str = "so"; + pub const DLL_SUFFIX: &str = ".dylib"; + pub const DLL_EXTENSION: &str = "dylib"; pub const EXE_SUFFIX: &str = ""; pub const EXE_EXTENSION: &str = ""; } -#[cfg(target_os = "aix")] +#[cfg(target_os = "visionos")] pub mod os { pub const FAMILY: &str = "unix"; - pub const OS: &str = "aix"; + pub const OS: &str = "visionos"; pub const DLL_PREFIX: &str = "lib"; - pub const DLL_SUFFIX: &str = ".a"; - pub const DLL_EXTENSION: &str = "a"; + pub const DLL_SUFFIX: &str = ".dylib"; + pub const DLL_EXTENSION: &str = "dylib"; pub const EXE_SUFFIX: &str = ""; pub const EXE_EXTENSION: &str = ""; } -#[cfg(target_os = "nuttx")] +#[cfg(target_os = "vita")] pub mod os { pub const FAMILY: &str = "unix"; - pub const OS: &str = "nuttx"; + pub const OS: &str = "vita"; + pub const DLL_PREFIX: &str = "lib"; + pub const DLL_SUFFIX: &str = ".so"; + pub const DLL_EXTENSION: &str = "so"; + pub const EXE_SUFFIX: &str = ".elf"; + pub const EXE_EXTENSION: &str = "elf"; +} + +#[cfg(target_os = "vxworks")] +pub mod os { + pub const FAMILY: &str = "unix"; + pub const OS: &str = "vxworks"; pub const DLL_PREFIX: &str = "lib"; pub const DLL_SUFFIX: &str = ".so"; pub const DLL_EXTENSION: &str = "so"; pub const EXE_SUFFIX: &str = ""; pub const EXE_EXTENSION: &str = ""; } + +#[cfg(target_os = "watchos")] +pub mod os { + pub const FAMILY: &str = "unix"; + pub const OS: &str = "watchos"; + pub const DLL_PREFIX: &str = "lib"; + pub const DLL_SUFFIX: &str = ".dylib"; + pub const DLL_EXTENSION: &str = "dylib"; + pub const EXE_SUFFIX: &str = ""; + pub const EXE_EXTENSION: &str = ""; +} From 37712cc01604633fec6aac9bc720210207fa4b54 Mon Sep 17 00:00:00 2001 From: Thalia Archibald Date: Tue, 15 Apr 2025 05:48:27 -0700 Subject: [PATCH 2/4] Combine env consts into std::sys::env_consts --- library/std/src/env.rs | 2 +- .../sys/{pal/unix/env.rs => env_consts.rs} | 70 ++++++++++++++++++- library/std/src/sys/mod.rs | 1 + library/std/src/sys/pal/hermit/env.rs | 9 --- library/std/src/sys/pal/hermit/mod.rs | 1 - library/std/src/sys/pal/sgx/env.rs | 9 --- library/std/src/sys/pal/sgx/mod.rs | 1 - library/std/src/sys/pal/solid/env.rs | 9 --- library/std/src/sys/pal/solid/mod.rs | 1 - library/std/src/sys/pal/teeos/mod.rs | 3 - library/std/src/sys/pal/trusty/mod.rs | 2 - library/std/src/sys/pal/uefi/env.rs | 9 --- library/std/src/sys/pal/uefi/mod.rs | 1 - library/std/src/sys/pal/unix/mod.rs | 1 - library/std/src/sys/pal/unsupported/env.rs | 9 --- library/std/src/sys/pal/unsupported/mod.rs | 1 - library/std/src/sys/pal/wasi/env.rs | 11 --- library/std/src/sys/pal/wasi/mod.rs | 1 - library/std/src/sys/pal/wasip2/mod.rs | 2 - library/std/src/sys/pal/wasm/env.rs | 9 --- library/std/src/sys/pal/wasm/mod.rs | 1 - library/std/src/sys/pal/windows/env.rs | 9 --- library/std/src/sys/pal/windows/mod.rs | 1 - library/std/src/sys/pal/xous/mod.rs | 2 - library/std/src/sys/pal/zkvm/mod.rs | 1 - 25 files changed, 71 insertions(+), 95 deletions(-) rename library/std/src/sys/{pal/unix/env.rs => env_consts.rs} (81%) delete mode 100644 library/std/src/sys/pal/hermit/env.rs delete mode 100644 library/std/src/sys/pal/sgx/env.rs delete mode 100644 library/std/src/sys/pal/solid/env.rs delete mode 100644 library/std/src/sys/pal/uefi/env.rs delete mode 100644 library/std/src/sys/pal/unsupported/env.rs delete mode 100644 library/std/src/sys/pal/wasi/env.rs delete mode 100644 library/std/src/sys/pal/wasm/env.rs delete mode 100644 library/std/src/sys/pal/windows/env.rs diff --git a/library/std/src/env.rs b/library/std/src/env.rs index 05bd4345ea8dd..c84a72c4fad02 100644 --- a/library/std/src/env.rs +++ b/library/std/src/env.rs @@ -950,7 +950,7 @@ impl fmt::Debug for ArgsOs { /// Constants associated with the current target #[stable(feature = "env", since = "1.0.0")] pub mod consts { - use crate::sys::env::os; + use crate::sys::env_consts::os; /// A string describing the architecture of the CPU that is currently in use. /// An example value may be: `"x86"`, `"arm"` or `"riscv64"`. diff --git a/library/std/src/sys/pal/unix/env.rs b/library/std/src/sys/env_consts.rs similarity index 81% rename from library/std/src/sys/pal/unix/env.rs rename to library/std/src/sys/env_consts.rs index 1a5e23f06b804..f439aa5a905c5 100644 --- a/library/std/src/sys/pal/unix/env.rs +++ b/library/std/src/sys/env_consts.rs @@ -1,3 +1,5 @@ +//! Constants associated with each target. + // Keep entries sorted alphabetically. #[cfg(target_os = "aix")] @@ -44,7 +46,7 @@ pub mod os { pub const EXE_EXTENSION: &str = ""; } -#[cfg(all(target_os = "emscripten", target_arch = "wasm32"))] +#[cfg(target_os = "emscripten")] pub mod os { pub const FAMILY: &str = "unix"; pub const OS: &str = "emscripten"; @@ -99,6 +101,17 @@ pub mod os { pub const EXE_EXTENSION: &str = ""; } +#[cfg(target_os = "hermit")] +pub mod os { + pub const FAMILY: &str = ""; + pub const OS: &str = "hermit"; + pub const DLL_PREFIX: &str = ""; + pub const DLL_SUFFIX: &str = ""; + pub const DLL_EXTENSION: &str = ""; + pub const EXE_SUFFIX: &str = ""; + pub const EXE_EXTENSION: &str = ""; +} + #[cfg(target_os = "horizon")] pub mod os { pub const FAMILY: &str = "unix"; @@ -242,6 +255,17 @@ pub mod os { pub const EXE_EXTENSION: &str = ""; } +#[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] +pub mod os { + pub const FAMILY: &str = ""; + pub const OS: &str = ""; + pub const DLL_PREFIX: &str = ""; + pub const DLL_SUFFIX: &str = ".sgxs"; + pub const DLL_EXTENSION: &str = "sgxs"; + pub const EXE_SUFFIX: &str = ".sgxs"; + pub const EXE_EXTENSION: &str = "sgxs"; +} + #[cfg(target_os = "solaris")] pub mod os { pub const FAMILY: &str = "unix"; @@ -253,6 +277,17 @@ pub mod os { pub const EXE_EXTENSION: &str = ""; } +#[cfg(target_os = "solid_asp3")] +pub mod os { + pub const FAMILY: &str = "itron"; + pub const OS: &str = "solid"; + pub const DLL_PREFIX: &str = ""; + pub const DLL_SUFFIX: &str = ".so"; + pub const DLL_EXTENSION: &str = "so"; + pub const EXE_SUFFIX: &str = ""; + pub const EXE_EXTENSION: &str = ""; +} + #[cfg(target_os = "tvos")] pub mod os { pub const FAMILY: &str = "unix"; @@ -264,6 +299,17 @@ pub mod os { pub const EXE_EXTENSION: &str = ""; } +#[cfg(target_os = "uefi")] +pub mod os { + pub const FAMILY: &str = ""; + pub const OS: &str = "uefi"; + pub const DLL_PREFIX: &str = ""; + pub const DLL_SUFFIX: &str = ""; + pub const DLL_EXTENSION: &str = ""; + pub const EXE_SUFFIX: &str = ".efi"; + pub const EXE_EXTENSION: &str = "efi"; +} + #[cfg(target_os = "visionos")] pub mod os { pub const FAMILY: &str = "unix"; @@ -297,6 +343,17 @@ pub mod os { pub const EXE_EXTENSION: &str = ""; } +#[cfg(all(target_family = "wasm", not(any(target_os = "emscripten", target_os = "linux"))))] +pub mod os { + pub const FAMILY: &str = ""; + pub const OS: &str = ""; + pub const DLL_PREFIX: &str = ""; + pub const DLL_SUFFIX: &str = ".wasm"; + pub const DLL_EXTENSION: &str = "wasm"; + pub const EXE_SUFFIX: &str = ".wasm"; + pub const EXE_EXTENSION: &str = "wasm"; +} + #[cfg(target_os = "watchos")] pub mod os { pub const FAMILY: &str = "unix"; @@ -307,3 +364,14 @@ pub mod os { pub const EXE_SUFFIX: &str = ""; pub const EXE_EXTENSION: &str = ""; } + +#[cfg(target_os = "windows")] +pub mod os { + pub const FAMILY: &str = "windows"; + pub const OS: &str = "windows"; + pub const DLL_PREFIX: &str = ""; + pub const DLL_SUFFIX: &str = ".dll"; + pub const DLL_EXTENSION: &str = "dll"; + pub const EXE_SUFFIX: &str = ".exe"; + pub const EXE_EXTENSION: &str = "exe"; +} diff --git a/library/std/src/sys/mod.rs b/library/std/src/sys/mod.rs index bc4bf11cb7405..e7b631999e0da 100644 --- a/library/std/src/sys/mod.rs +++ b/library/std/src/sys/mod.rs @@ -12,6 +12,7 @@ pub mod anonymous_pipe; pub mod args; pub mod backtrace; pub mod cmath; +pub mod env_consts; pub mod exit_guard; pub mod fd; pub mod fs; diff --git a/library/std/src/sys/pal/hermit/env.rs b/library/std/src/sys/pal/hermit/env.rs deleted file mode 100644 index 7a0fcb31ef2e8..0000000000000 --- a/library/std/src/sys/pal/hermit/env.rs +++ /dev/null @@ -1,9 +0,0 @@ -pub mod os { - pub const FAMILY: &str = ""; - pub const OS: &str = "hermit"; - pub const DLL_PREFIX: &str = ""; - pub const DLL_SUFFIX: &str = ""; - pub const DLL_EXTENSION: &str = ""; - pub const EXE_SUFFIX: &str = ""; - pub const EXE_EXTENSION: &str = ""; -} diff --git a/library/std/src/sys/pal/hermit/mod.rs b/library/std/src/sys/pal/hermit/mod.rs index 821836824e2bc..70636760a83b6 100644 --- a/library/std/src/sys/pal/hermit/mod.rs +++ b/library/std/src/sys/pal/hermit/mod.rs @@ -18,7 +18,6 @@ use crate::os::raw::c_char; -pub mod env; pub mod futex; pub mod os; #[path = "../unsupported/pipe.rs"] diff --git a/library/std/src/sys/pal/sgx/env.rs b/library/std/src/sys/pal/sgx/env.rs deleted file mode 100644 index 8043b7c5213a1..0000000000000 --- a/library/std/src/sys/pal/sgx/env.rs +++ /dev/null @@ -1,9 +0,0 @@ -pub mod os { - pub const FAMILY: &str = ""; - pub const OS: &str = ""; - pub const DLL_PREFIX: &str = ""; - pub const DLL_SUFFIX: &str = ".sgxs"; - pub const DLL_EXTENSION: &str = "sgxs"; - pub const EXE_SUFFIX: &str = ".sgxs"; - pub const EXE_EXTENSION: &str = "sgxs"; -} diff --git a/library/std/src/sys/pal/sgx/mod.rs b/library/std/src/sys/pal/sgx/mod.rs index 8a87e7a7ae13d..99735947e2cd4 100644 --- a/library/std/src/sys/pal/sgx/mod.rs +++ b/library/std/src/sys/pal/sgx/mod.rs @@ -9,7 +9,6 @@ use crate::io::ErrorKind; use crate::sync::atomic::{AtomicBool, Ordering}; pub mod abi; -pub mod env; mod libunwind_integration; pub mod os; #[path = "../unsupported/pipe.rs"] diff --git a/library/std/src/sys/pal/solid/env.rs b/library/std/src/sys/pal/solid/env.rs deleted file mode 100644 index 6855c113b2893..0000000000000 --- a/library/std/src/sys/pal/solid/env.rs +++ /dev/null @@ -1,9 +0,0 @@ -pub mod os { - pub const FAMILY: &str = "itron"; - pub const OS: &str = "solid"; - pub const DLL_PREFIX: &str = ""; - pub const DLL_SUFFIX: &str = ".so"; - pub const DLL_EXTENSION: &str = "so"; - pub const EXE_SUFFIX: &str = ""; - pub const EXE_EXTENSION: &str = ""; -} diff --git a/library/std/src/sys/pal/solid/mod.rs b/library/std/src/sys/pal/solid/mod.rs index c41dc848a1b4a..0011cf256df74 100644 --- a/library/std/src/sys/pal/solid/mod.rs +++ b/library/std/src/sys/pal/solid/mod.rs @@ -16,7 +16,6 @@ pub mod itron { use super::unsupported; } -pub mod env; // `error` is `pub(crate)` so that it can be accessed by `itron/error.rs` as // `crate::sys::error` pub(crate) mod error; diff --git a/library/std/src/sys/pal/teeos/mod.rs b/library/std/src/sys/pal/teeos/mod.rs index b8095cec3e978..c7b1777725858 100644 --- a/library/std/src/sys/pal/teeos/mod.rs +++ b/library/std/src/sys/pal/teeos/mod.rs @@ -6,9 +6,6 @@ #![allow(unused_variables)] #![allow(dead_code)] -#[path = "../unsupported/env.rs"] -pub mod env; -//pub mod fd; pub mod os; #[path = "../unsupported/pipe.rs"] pub mod pipe; diff --git a/library/std/src/sys/pal/trusty/mod.rs b/library/std/src/sys/pal/trusty/mod.rs index 04e6b4c818687..275f606246336 100644 --- a/library/std/src/sys/pal/trusty/mod.rs +++ b/library/std/src/sys/pal/trusty/mod.rs @@ -3,8 +3,6 @@ #[path = "../unsupported/common.rs"] #[deny(unsafe_op_in_unsafe_fn)] mod common; -#[path = "../unsupported/env.rs"] -pub mod env; #[path = "../unsupported/os.rs"] pub mod os; #[path = "../unsupported/pipe.rs"] diff --git a/library/std/src/sys/pal/uefi/env.rs b/library/std/src/sys/pal/uefi/env.rs deleted file mode 100644 index c106d5fed3e1d..0000000000000 --- a/library/std/src/sys/pal/uefi/env.rs +++ /dev/null @@ -1,9 +0,0 @@ -pub mod os { - pub const FAMILY: &str = ""; - pub const OS: &str = "uefi"; - pub const DLL_PREFIX: &str = ""; - pub const DLL_SUFFIX: &str = ""; - pub const DLL_EXTENSION: &str = ""; - pub const EXE_SUFFIX: &str = ".efi"; - pub const EXE_EXTENSION: &str = "efi"; -} diff --git a/library/std/src/sys/pal/uefi/mod.rs b/library/std/src/sys/pal/uefi/mod.rs index cd901f48b76f8..bd6a36021f4cb 100644 --- a/library/std/src/sys/pal/uefi/mod.rs +++ b/library/std/src/sys/pal/uefi/mod.rs @@ -13,7 +13,6 @@ //! [`OsString`]: crate::ffi::OsString #![forbid(unsafe_op_in_unsafe_fn)] -pub mod env; pub mod helpers; pub mod os; #[path = "../unsupported/pipe.rs"] diff --git a/library/std/src/sys/pal/unix/mod.rs b/library/std/src/sys/pal/unix/mod.rs index 3a790d9c868c9..a4702ae1b18d0 100644 --- a/library/std/src/sys/pal/unix/mod.rs +++ b/library/std/src/sys/pal/unix/mod.rs @@ -6,7 +6,6 @@ use crate::io::ErrorKind; #[macro_use] pub mod weak; -pub mod env; #[cfg(target_os = "fuchsia")] pub mod fuchsia; pub mod futex; diff --git a/library/std/src/sys/pal/unsupported/env.rs b/library/std/src/sys/pal/unsupported/env.rs deleted file mode 100644 index d2efec506c56b..0000000000000 --- a/library/std/src/sys/pal/unsupported/env.rs +++ /dev/null @@ -1,9 +0,0 @@ -pub mod os { - pub const FAMILY: &str = ""; - pub const OS: &str = ""; - pub const DLL_PREFIX: &str = ""; - pub const DLL_SUFFIX: &str = ""; - pub const DLL_EXTENSION: &str = ""; - pub const EXE_SUFFIX: &str = ""; - pub const EXE_EXTENSION: &str = ""; -} diff --git a/library/std/src/sys/pal/unsupported/mod.rs b/library/std/src/sys/pal/unsupported/mod.rs index dea42a95dcc6f..5e3295b1331a3 100644 --- a/library/std/src/sys/pal/unsupported/mod.rs +++ b/library/std/src/sys/pal/unsupported/mod.rs @@ -1,6 +1,5 @@ #![deny(unsafe_op_in_unsafe_fn)] -pub mod env; pub mod os; pub mod pipe; pub mod thread; diff --git a/library/std/src/sys/pal/wasi/env.rs b/library/std/src/sys/pal/wasi/env.rs deleted file mode 100644 index 8d44498267360..0000000000000 --- a/library/std/src/sys/pal/wasi/env.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![forbid(unsafe_op_in_unsafe_fn)] - -pub mod os { - pub const FAMILY: &str = ""; - pub const OS: &str = ""; - pub const DLL_PREFIX: &str = ""; - pub const DLL_SUFFIX: &str = ".wasm"; - pub const DLL_EXTENSION: &str = "wasm"; - pub const EXE_SUFFIX: &str = ".wasm"; - pub const EXE_EXTENSION: &str = "wasm"; -} diff --git a/library/std/src/sys/pal/wasi/mod.rs b/library/std/src/sys/pal/wasi/mod.rs index 4ea42b1082b1d..61dd1c3f98b10 100644 --- a/library/std/src/sys/pal/wasi/mod.rs +++ b/library/std/src/sys/pal/wasi/mod.rs @@ -13,7 +13,6 @@ //! compiling for wasm. That way it's a compile time error for something that's //! guaranteed to be a runtime error! -pub mod env; #[allow(unused)] #[path = "../wasm/atomics/futex.rs"] pub mod futex; diff --git a/library/std/src/sys/pal/wasip2/mod.rs b/library/std/src/sys/pal/wasip2/mod.rs index 6445bf2cc0d2c..47fe3221c9093 100644 --- a/library/std/src/sys/pal/wasip2/mod.rs +++ b/library/std/src/sys/pal/wasip2/mod.rs @@ -6,8 +6,6 @@ //! To begin with, this target mirrors the wasi target 1 to 1, but over //! time this will change significantly. -#[path = "../wasi/env.rs"] -pub mod env; #[allow(unused)] #[path = "../wasm/atomics/futex.rs"] pub mod futex; diff --git a/library/std/src/sys/pal/wasm/env.rs b/library/std/src/sys/pal/wasm/env.rs deleted file mode 100644 index 730e356d7fe95..0000000000000 --- a/library/std/src/sys/pal/wasm/env.rs +++ /dev/null @@ -1,9 +0,0 @@ -pub mod os { - pub const FAMILY: &str = ""; - pub const OS: &str = ""; - pub const DLL_PREFIX: &str = ""; - pub const DLL_SUFFIX: &str = ".wasm"; - pub const DLL_EXTENSION: &str = "wasm"; - pub const EXE_SUFFIX: &str = ".wasm"; - pub const EXE_EXTENSION: &str = "wasm"; -} diff --git a/library/std/src/sys/pal/wasm/mod.rs b/library/std/src/sys/pal/wasm/mod.rs index af370020d96ab..37cb46a8f6b3f 100644 --- a/library/std/src/sys/pal/wasm/mod.rs +++ b/library/std/src/sys/pal/wasm/mod.rs @@ -16,7 +16,6 @@ #![deny(unsafe_op_in_unsafe_fn)] -pub mod env; #[path = "../unsupported/os.rs"] pub mod os; #[path = "../unsupported/pipe.rs"] diff --git a/library/std/src/sys/pal/windows/env.rs b/library/std/src/sys/pal/windows/env.rs deleted file mode 100644 index f0a99d6200cac..0000000000000 --- a/library/std/src/sys/pal/windows/env.rs +++ /dev/null @@ -1,9 +0,0 @@ -pub mod os { - pub const FAMILY: &str = "windows"; - pub const OS: &str = "windows"; - pub const DLL_PREFIX: &str = ""; - pub const DLL_SUFFIX: &str = ".dll"; - pub const DLL_EXTENSION: &str = "dll"; - pub const EXE_SUFFIX: &str = ".exe"; - pub const EXE_EXTENSION: &str = "exe"; -} diff --git a/library/std/src/sys/pal/windows/mod.rs b/library/std/src/sys/pal/windows/mod.rs index 3c0a5c2de2636..4f18c4009ab6c 100644 --- a/library/std/src/sys/pal/windows/mod.rs +++ b/library/std/src/sys/pal/windows/mod.rs @@ -15,7 +15,6 @@ pub mod compat; pub mod api; pub mod c; -pub mod env; #[cfg(not(target_vendor = "win7"))] pub mod futex; pub mod handle; diff --git a/library/std/src/sys/pal/xous/mod.rs b/library/std/src/sys/pal/xous/mod.rs index 4f652d3f130de..383d031ed4353 100644 --- a/library/std/src/sys/pal/xous/mod.rs +++ b/library/std/src/sys/pal/xous/mod.rs @@ -1,7 +1,5 @@ #![forbid(unsafe_op_in_unsafe_fn)] -#[path = "../unsupported/env.rs"] -pub mod env; pub mod os; #[path = "../unsupported/pipe.rs"] pub mod pipe; diff --git a/library/std/src/sys/pal/zkvm/mod.rs b/library/std/src/sys/pal/zkvm/mod.rs index ebd7b03677988..e1efa2406858f 100644 --- a/library/std/src/sys/pal/zkvm/mod.rs +++ b/library/std/src/sys/pal/zkvm/mod.rs @@ -11,7 +11,6 @@ pub const WORD_SIZE: usize = size_of::(); pub mod abi; -pub mod env; pub mod os; #[path = "../unsupported/pipe.rs"] pub mod pipe; From 670ff84d1c70146a2556b41650d3e417143c6c60 Mon Sep 17 00:00:00 2001 From: Thalia Archibald Date: Tue, 15 Apr 2025 06:42:39 -0700 Subject: [PATCH 3/4] Handle unsupported fallback --- library/std/src/sys/env_consts.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/library/std/src/sys/env_consts.rs b/library/std/src/sys/env_consts.rs index f439aa5a905c5..018d7954db26a 100644 --- a/library/std/src/sys/env_consts.rs +++ b/library/std/src/sys/env_consts.rs @@ -1,6 +1,19 @@ //! Constants associated with each target. -// Keep entries sorted alphabetically. +// Replaces the #[else] gate with #[cfg(not(any(…)))] of all the other gates. +// This ensures that they must be mutually exclusive and do not have precedence +// like cfg_if!. +macro cfg_unordered( + $(#[cfg($cfg:meta)] $os:item)* + #[else] $fallback:item +) { + $(#[cfg($cfg)] $os)* + #[cfg(not(any($($cfg),*)))] $fallback +} + +// Keep entries sorted alphabetically and mutually exclusive. + +cfg_unordered! { #[cfg(target_os = "aix")] pub mod os { @@ -375,3 +388,17 @@ pub mod os { pub const EXE_SUFFIX: &str = ".exe"; pub const EXE_EXTENSION: &str = "exe"; } + +// The fallback when none of the other gates match. +#[else] +pub mod os { + pub const FAMILY: &str = ""; + pub const OS: &str = ""; + pub const DLL_PREFIX: &str = ""; + pub const DLL_SUFFIX: &str = ""; + pub const DLL_EXTENSION: &str = ""; + pub const EXE_SUFFIX: &str = ""; + pub const EXE_EXTENSION: &str = ""; +} + +} From 93fa96cfba126d542ebd33624e5f774d397dbf3f Mon Sep 17 00:00:00 2001 From: Thalia Archibald Date: Fri, 18 Apr 2025 16:45:26 -0700 Subject: [PATCH 4/4] Use struct update syntax for some TargetOptions --- compiler/rustc_target/src/spec/base/linux_musl.rs | 15 +++++++-------- compiler/rustc_target/src/spec/base/linux_ohos.rs | 15 +++++++-------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_target/src/spec/base/linux_musl.rs b/compiler/rustc_target/src/spec/base/linux_musl.rs index 1a854fe362d50..1bef602404e56 100644 --- a/compiler/rustc_target/src/spec/base/linux_musl.rs +++ b/compiler/rustc_target/src/spec/base/linux_musl.rs @@ -1,12 +1,11 @@ use crate::spec::{LinkSelfContainedDefault, TargetOptions, base, crt_objects}; pub(crate) fn opts() -> TargetOptions { - let mut base = base::linux::opts(); - - base.env = "musl".into(); - base.pre_link_objects_self_contained = crt_objects::pre_musl_self_contained(); - base.post_link_objects_self_contained = crt_objects::post_musl_self_contained(); - base.link_self_contained = LinkSelfContainedDefault::InferredForMusl; - - base + TargetOptions { + env: "musl".into(), + pre_link_objects_self_contained: crt_objects::pre_musl_self_contained(), + post_link_objects_self_contained: crt_objects::post_musl_self_contained(), + link_self_contained: LinkSelfContainedDefault::InferredForMusl, + ..base::linux::opts() + } } diff --git a/compiler/rustc_target/src/spec/base/linux_ohos.rs b/compiler/rustc_target/src/spec/base/linux_ohos.rs index 6f4d69a996c34..1b7f1e196664f 100644 --- a/compiler/rustc_target/src/spec/base/linux_ohos.rs +++ b/compiler/rustc_target/src/spec/base/linux_ohos.rs @@ -1,12 +1,11 @@ use crate::spec::{TargetOptions, TlsModel, base}; pub(crate) fn opts() -> TargetOptions { - let mut base = base::linux::opts(); - - base.env = "ohos".into(); - base.crt_static_default = false; - base.tls_model = TlsModel::Emulated; - base.has_thread_local = false; - - base + TargetOptions { + env: "ohos".into(), + crt_static_default: false, + tls_model: TlsModel::Emulated, + has_thread_local: false, + ..base::linux::opts() + } }