about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChris Denton <chris@chrisdenton.dev>2025-04-19 15:09:35 +0000
committerGitHub <noreply@github.com>2025-04-19 15:09:35 +0000
commit709f4fee507f373247d206f33f7aefc3ce8705f1 (patch)
tree33a04ea1eedcb9cf56a256543a288a2f54381829
parent2d4f1130a28b9e18365485f7235dac58fdad20df (diff)
parent93fa96cfba126d542ebd33624e5f774d397dbf3f (diff)
downloadrust-709f4fee507f373247d206f33f7aefc3ce8705f1.tar.gz
rust-709f4fee507f373247d206f33f7aefc3ce8705f1.zip
Rollup merge of #139868 - thaliaarchi:move-env-consts-pal, r=joboet
Move `pal::env` to `std::sys::env_consts`

Combine the `std::env::consts` platform implementations as a single file. Use the Unix file as the base, since it has 28 entries, and fold the 8 singleton platforms into it. The Unix file was 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.

I'd prefer to have no fallback implementation, as I consider it a bug; however TEEOS, Trusty, and Xous have no definitions here. Since they otherwise have `pal` abstractions, that indicates that there are several platforms without `pal` abstractions which are also missing here. To support unsupported, create a little macro to handle the fallback case and not introduce ordering between the `cfg`s like `cfg_if!`.

I've named the module `std::sys::env_consts`, because they are used in `std::env::consts` and I intend to use the name `std::sys::env` for the combination of `Args` and `Vars`.

cc `@joboet` `@ChrisDenton`

Tracked in #117276.
-rw-r--r--compiler/rustc_target/src/spec/base/linux_musl.rs15
-rw-r--r--compiler/rustc_target/src/spec/base/linux_ohos.rs15
-rw-r--r--library/std/src/env.rs2
-rw-r--r--library/std/src/sys/env_consts.rs (renamed from library/std/src/sys/pal/unix/env.rs)283
-rw-r--r--library/std/src/sys/mod.rs1
-rw-r--r--library/std/src/sys/pal/hermit/env.rs9
-rw-r--r--library/std/src/sys/pal/hermit/mod.rs1
-rw-r--r--library/std/src/sys/pal/sgx/env.rs9
-rw-r--r--library/std/src/sys/pal/sgx/mod.rs1
-rw-r--r--library/std/src/sys/pal/solid/env.rs9
-rw-r--r--library/std/src/sys/pal/solid/mod.rs1
-rw-r--r--library/std/src/sys/pal/teeos/mod.rs3
-rw-r--r--library/std/src/sys/pal/trusty/mod.rs2
-rw-r--r--library/std/src/sys/pal/uefi/env.rs9
-rw-r--r--library/std/src/sys/pal/uefi/mod.rs1
-rw-r--r--library/std/src/sys/pal/unix/mod.rs1
-rw-r--r--library/std/src/sys/pal/unsupported/env.rs9
-rw-r--r--library/std/src/sys/pal/unsupported/mod.rs1
-rw-r--r--library/std/src/sys/pal/wasi/env.rs11
-rw-r--r--library/std/src/sys/pal/wasi/mod.rs1
-rw-r--r--library/std/src/sys/pal/wasip2/mod.rs2
-rw-r--r--library/std/src/sys/pal/wasm/env.rs9
-rw-r--r--library/std/src/sys/pal/wasm/mod.rs1
-rw-r--r--library/std/src/sys/pal/windows/env.rs9
-rw-r--r--library/std/src/sys/pal/windows/mod.rs1
-rw-r--r--library/std/src/sys/pal/xous/mod.rs2
-rw-r--r--library/std/src/sys/pal/zkvm/mod.rs1
27 files changed, 206 insertions, 203 deletions
diff --git a/compiler/rustc_target/src/spec/base/linux_musl.rs b/compiler/rustc_target/src/spec/base/linux_musl.rs
index 1a854fe362d..1bef602404e 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 6f4d69a996c..1b7f1e19666 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()
+    }
 }
diff --git a/library/std/src/env.rs b/library/std/src/env.rs
index 05bd4345ea8..c84a72c4fad 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
index c6609298f4b..018d7954db2 100644
--- a/library/std/src/sys/pal/unix/env.rs
+++ b/library/std/src/sys/env_consts.rs
@@ -1,73 +1,79 @@
-#[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 = "";
+//! Constants associated with each target.
+
+// 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
 }
 
-#[cfg(target_os = "macos")]
+// Keep entries sorted alphabetically and mutually exclusive.
+
+cfg_unordered! {
+
+#[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(target_os = "emscripten")]
 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 +81,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 +92,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 +103,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 +114,32 @@ pub mod os {
     pub const EXE_EXTENSION: &str = "";
 }
 
-#[cfg(target_os = "cygwin")]
+#[cfg(target_os = "hermit")]
 pub mod os {
-    pub const FAMILY: &str = "unix";
-    pub const OS: &str = "cygwin";
+    pub const FAMILY: &str = "";
+    pub const OS: &str = "hermit";
     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";
+    pub const DLL_SUFFIX: &str = "";
+    pub const DLL_EXTENSION: &str = "";
+    pub const EXE_SUFFIX: &str = "";
+    pub const EXE_EXTENSION: &str = "";
 }
 
-#[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 +158,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 +191,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 +224,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 +235,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 +268,21 @@ pub mod os {
     pub const EXE_EXTENSION: &str = "";
 }
 
-#[cfg(target_os = "vxworks")]
+#[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";
-    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 +290,115 @@ pub mod os {
     pub const EXE_EXTENSION: &str = "";
 }
 
-#[cfg(target_os = "espidf")]
+#[cfg(target_os = "solid_asp3")]
 pub mod os {
-    pub const FAMILY: &str = "unix";
-    pub const OS: &str = "espidf";
-    pub const DLL_PREFIX: &str = "lib";
+    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 = "aix")]
+#[cfg(target_os = "tvos")]
 pub mod os {
     pub const FAMILY: &str = "unix";
-    pub const OS: &str = "aix";
+    pub const OS: &str = "tvos";
     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 = "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";
-    pub const OS: &str = "nuttx";
+    pub const OS: &str = "visionos";
+    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 = "";
+}
+
+#[cfg(target_os = "vita")]
+pub mod os {
+    pub const FAMILY: &str = "unix";
+    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(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";
+    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 = "";
+}
+
+#[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";
+}
+
+// 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 = "";
+}
+
+}
diff --git a/library/std/src/sys/mod.rs b/library/std/src/sys/mod.rs
index bc4bf11cb74..e7b631999e0 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 7a0fcb31ef2..00000000000
--- 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 821836824e2..70636760a83 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 8043b7c5213..00000000000
--- 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 8a87e7a7ae1..99735947e2c 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 6855c113b28..00000000000
--- 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 c41dc848a1b..0011cf256df 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 b8095cec3e9..c7b17777258 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 04e6b4c8186..275f6062463 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 c106d5fed3e..00000000000
--- 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 cd901f48b76..bd6a36021f4 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 3a790d9c868..a4702ae1b18 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 d2efec506c5..00000000000
--- 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 dea42a95dcc..5e3295b1331 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 8d444982673..00000000000
--- 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 4ea42b1082b..61dd1c3f98b 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 6445bf2cc0d..47fe3221c90 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 730e356d7fe..00000000000
--- 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 af370020d96..37cb46a8f6b 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 f0a99d6200c..00000000000
--- 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 3c0a5c2de26..4f18c4009ab 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 4f652d3f130..383d031ed43 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 ebd7b036779..e1efa240685 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::<u32>();
 
 pub mod abi;
-pub mod env;
 pub mod os;
 #[path = "../unsupported/pipe.rs"]
 pub mod pipe;