Skip to content

Move pal::env to std::sys::env_consts #139868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 20, 2025

Conversation

thaliaarchi
Copy link
Contributor

@thaliaarchi thaliaarchi commented Apr 15, 2025

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 cfgs 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.

@rustbot
Copy link
Collaborator

rustbot commented Apr 15, 2025

r? @joboet

rustbot has assigned @joboet.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added O-hermit Operating System: Hermit O-SGX Target: SGX O-solid Operating System: SOLID O-unix Operating system: Unix-like O-wasi Operating system: Wasi, Webassembly System Interface O-wasm Target: WASM (WebAssembly), http://webassembly.org/ O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 15, 2025
@thaliaarchi thaliaarchi force-pushed the move-env-consts-pal branch from 87339da to ea13aca Compare April 15, 2025 13:48
@thaliaarchi
Copy link
Contributor Author

Commit 87339da is an earlier version which used cfg_if!. I don't like the ordering between the cfgs that it introduces.

@thaliaarchi
Copy link
Contributor Author

WALI presents a complication, because it's both Linux and Wasm, but it's probably just as simple as #[cfg(all(target_family = "wasm", not(target_os = "linux")))]. The only others which don't gate on target_os are #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] and #[windows]. SGX is easy to verify, since there's only one target. For Windows, I've expanded #[windows] to #[cfg(target_family = "windows")], since that's what it's a shorthand for, though #[cfg(target_os = "windows")] would be more clear. According to @ChrisDenton, there's probably not any cases where they differ.

@thaliaarchi thaliaarchi force-pushed the move-env-consts-pal branch from ea13aca to cac458c Compare April 15, 2025 23:47
@joboet
Copy link
Member

joboet commented Apr 18, 2025

Sound and looks good to me!
@bors r+

@bors
Copy link
Collaborator

bors commented Apr 18, 2025

📌 Commit cac458c has been approved by joboet

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 18, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 18, 2025
…=joboet

Move `pal::env` into `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 rust-lang#117276.
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 18, 2025
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#137454 (not lint break with label and unsafe block)
 - rust-lang#138934 (support config extensions)
 - rust-lang#139297 (Deduplicate & clean up Nix shell)
 - rust-lang#139834 (Don't canonicalize crate paths)
 - rust-lang#139868 (Move `pal::env` into `std::sys::env_consts`)
 - rust-lang#139978 (Add citool command for generating a test dashboard)
 - rust-lang#140000 (skip llvm-config in autodiff check builds, when its unavailable)
 - rust-lang#140007 (Disable has_thread_local on i686-win7-windows-msvc)

r? `@ghost`
`@rustbot` modify labels: rollup
@matthiaskrgr
Copy link
Member

@bors r-
#140012 (comment)

2025-04-18T20:16:55.6950825Z
2025-04-18T20:16:55.8638464Z error[E0428]: the name `os` is defined multiple times
2025-04-18T20:16:55.8639221Z    --> library/std/src/sys/env_consts.rs:362:1
2025-04-18T20:16:55.8639750Z     |
2025-04-18T20:16:55.8640277Z 65  | pub mod os {
2025-04-18T20:16:55.8641094Z     | ---------- previous definition of the module `os` here
2025-04-18T20:16:55.8641700Z ...
2025-04-18T20:16:55.8642184Z 362 | pub mod os {
2025-04-18T20:16:55.8642884Z     | ^^^^^^^^^^ `os` redefined here
2025-04-18T20:16:55.8643648Z     |
2025-04-18T20:16:55.8644365Z     = note: `os` must be defined only once in the type namespace of this module
2025-04-18T20:16:55.8644825Z
2025-04-18T20:16:58.4808620Z For more information about this error, try `rustc --explain E0428`.
2025-04-18T20:16:58.5006460Z [RUSTC-TIMING] std test:false 2.826
2025-04-18T20:16:58.5009351Z warning: `std` (lib) generated 1 warning
2025-04-18T20:16:58.5010054Z error: could not compile `std` (lib) due to 1 previous error; 1 warning emitted
2025-04-18T20:16:58.5068975Z Build completed unsuccessfully in 0:00:34
2025-04-18T20:16:58.5157722Z   local time: Fri Apr 18 20:16:58 UTC 2025
2025-04-18T20:16:58.5715563Z   network time: Fri, 18 Apr 2025 20:16:58 GMT
``

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 18, 2025
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.
@thaliaarchi thaliaarchi force-pushed the move-env-consts-pal branch from cac458c to 4849207 Compare April 19, 2025 02:17
@rustbot
Copy link
Collaborator

rustbot commented Apr 19, 2025

These commits modify compiler targets.
(See the Target Tier Policy.)

@thaliaarchi
Copy link
Contributor Author

thaliaarchi commented Apr 19, 2025

I've fixed Emscripten (which failed CI).

Also, I confirmed that target_os = "emscripten" always implies target_arch = "wasm32" and that target_family = "windows" iff target_os = "windows, so I switched those two to just target_os to make them more clear. Now, only Wasm and SGX aren't gated using target_os and I've similarly verified that they're mutually exclusive with the others.

$ rustc +nightly -Z unstable-options --print all-target-specs-json > targets.json
$ jq 'to_entries[] | select(.value | .os == "emscripten" and .arch != "wasm32")' targets.json
$ jq 'to_entries[] | select(.value | (."target-family" // [] | contains(["windows"])) != (.os == "windows"))' targets.json
$ jq 'map(select(."target-family" // [] | contains(["wasm"])).os) | unique[]' targets.json
null
"emscripten"
"linux"
"unknown"
"wasi"
$ jq '.[] | select(.vendor == "fortanix" or .env == "sgx").os' targets.json
"unknown"

In the process of this exploration, I found two tiny code simplifications in rustc_targets to match the style of other targets.

@thaliaarchi thaliaarchi changed the title Move pal::env into std::sys::env_consts Move pal::env to std::sys::env_consts Apr 19, 2025
@thaliaarchi thaliaarchi force-pushed the move-env-consts-pal branch from 4849207 to 93fa96c Compare April 19, 2025 02:50
@thaliaarchi
Copy link
Contributor Author

thaliaarchi commented Apr 19, 2025

The macro is now much simpler, while doing the same thing.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 19, 2025
@joboet
Copy link
Member

joboet commented Apr 19, 2025

Neat!
@bors r+

@bors
Copy link
Collaborator

bors commented Apr 19, 2025

📌 Commit 93fa96c has been approved by joboet

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 19, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 19, 2025
…enton

Rollup of 8 pull requests

Successful merges:

 - rust-lang#138934 (support config extensions)
 - rust-lang#139091 (Rewrite on_unimplemented format string parser.)
 - rust-lang#139753 (Make `#[naked]` an unsafe attribute)
 - rust-lang#139762 (Don't assemble non-env/bound candidates if projection is rigid)
 - rust-lang#139834 (Don't canonicalize crate paths)
 - rust-lang#139868 (Move `pal::env` to `std::sys::env_consts`)
 - rust-lang#139978 (Add citool command for generating a test dashboard)
 - rust-lang#139995 (Clean UI tests 4 of n)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 20, 2025
…enton

Rollup of 8 pull requests

Successful merges:

 - rust-lang#138934 (support config extensions)
 - rust-lang#139091 (Rewrite on_unimplemented format string parser.)
 - rust-lang#139753 (Make `#[naked]` an unsafe attribute)
 - rust-lang#139762 (Don't assemble non-env/bound candidates if projection is rigid)
 - rust-lang#139834 (Don't canonicalize crate paths)
 - rust-lang#139868 (Move `pal::env` to `std::sys::env_consts`)
 - rust-lang#139978 (Add citool command for generating a test dashboard)
 - rust-lang#139995 (Clean UI tests 4 of n)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 20, 2025
…enton

Rollup of 8 pull requests

Successful merges:

 - rust-lang#138934 (support config extensions)
 - rust-lang#139091 (Rewrite on_unimplemented format string parser.)
 - rust-lang#139753 (Make `#[naked]` an unsafe attribute)
 - rust-lang#139762 (Don't assemble non-env/bound candidates if projection is rigid)
 - rust-lang#139834 (Don't canonicalize crate paths)
 - rust-lang#139868 (Move `pal::env` to `std::sys::env_consts`)
 - rust-lang#139978 (Add citool command for generating a test dashboard)
 - rust-lang#139995 (Clean UI tests 4 of n)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 709f4fe into rust-lang:master Apr 20, 2025
6 checks passed
@rustbot rustbot added this to the 1.88.0 milestone Apr 20, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 20, 2025
Rollup merge of rust-lang#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 rust-lang#117276.
@thaliaarchi thaliaarchi deleted the move-env-consts-pal branch April 20, 2025 06:45
thaliaarchi added a commit to thaliaarchi/rust that referenced this pull request Apr 22, 2025
thaliaarchi added a commit to thaliaarchi/rust that referenced this pull request Apr 22, 2025
I missed this in rust-lang#139868. Its `mod` declaration was removed, but the
contents were not moved.
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Apr 22, 2025
…=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 rust-lang#117276.
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Apr 22, 2025
…enton

Rollup of 8 pull requests

Successful merges:

 - rust-lang#138934 (support config extensions)
 - rust-lang#139091 (Rewrite on_unimplemented format string parser.)
 - rust-lang#139753 (Make `#[naked]` an unsafe attribute)
 - rust-lang#139762 (Don't assemble non-env/bound candidates if projection is rigid)
 - rust-lang#139834 (Don't canonicalize crate paths)
 - rust-lang#139868 (Move `pal::env` to `std::sys::env_consts`)
 - rust-lang#139978 (Add citool command for generating a test dashboard)
 - rust-lang#139995 (Clean UI tests 4 of n)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 24, 2025
Move zkVM constants into `sys::env_consts`

I missed this in rust-lang#139868. Its `mod` declaration was removed, but the contents were not moved.

r? joboet
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 24, 2025
Rollup merge of rust-lang#140141 - thaliaarchi:env-consts/zkvm, r=joboet

Move zkVM constants into `sys::env_consts`

I missed this in rust-lang#139868. Its `mod` declaration was removed, but the contents were not moved.

r? joboet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-hermit Operating System: Hermit O-SGX Target: SGX O-solid Operating System: SOLID O-unix Operating system: Unix-like O-wasi Operating system: Wasi, Webassembly System Interface O-wasm Target: WASM (WebAssembly), http://webassembly.org/ O-windows Operating system: Windows S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants