Skip to content

Add cfg Support for Distinguishing WASI Targets #125803

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

Closed
namse opened this issue May 31, 2024 · 5 comments
Closed

Add cfg Support for Distinguishing WASI Targets #125803

namse opened this issue May 31, 2024 · 5 comments
Labels
A-target-specs Area: Compile-target specifications A-targets Area: Concerning the implications of different compiler targets O-wasi Operating system: Wasi, Webassembly System Interface T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@namse
Copy link

namse commented May 31, 2024

WASI supports different features depending on whether it is p1 or p2. Additionally, p1-threads support threads. The problem is that we cannot determine these distinctions using cfg or similar mechanisms. In crates like tokio, it's impossible to create conditional compilation branches with cfg, such as 'this feature is not available in p1 but is supported in p2, so let's create a conditional branch.'

Therefore, I would like to request support for a method to distinguish WASI targets more precisely using cfg or a similar mechanism.

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 31, 2024
@Urgau Urgau added A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-target-specs Area: Compile-target specifications A-targets Area: Concerning the implications of different compiler targets O-wasi Operating system: Wasi, Webassembly System Interface and removed A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 31, 2024
@workingjubilee
Copy link
Member

uhhh cc @alexcrichton @sunfishcode @yoshuawuyts

@CryZe
Copy link
Contributor

CryZe commented Jun 1, 2024

#[cfg(target_env = "p2")] should work. Though it doesn't seem like p1 was added, unless I'm just not seeing it right now. While negating the condition would work for now, it does seem dangerous whenever there's a p3.

@workingjubilee
Copy link
Member

oh. can someone add that to the platform support page? I don't see it on https://doc.rust-lang.org/nightly/rustc/platform-support/wasm32-wasip2.html

@alexcrichton
Copy link
Member

I've added target_env = "p1" in #125869. Today you'll have to do not(target_env = "p2") and while that's not great for hypothetical future iterations it's all that's possible today beyond detecting the target in build.rs and setting a cfg key yourself.

For wasm32-wasip1-threads the only way to detect that is with the Nightly-only target_feature = "atomics". That's not the best detection mechanism since it's reasonable that the feature may be enabled by default for all wasm targets in the future (e.g. it's a similar situation where not(target_env = "p2") is not a great detection mechanism. Failing that your only detection mechanism will be build.rs and looking at TARGET (after probably looking at CARGO_CFG_TARGET_FAMILY to check it's wasm.

compiler-errors pushed a commit to compiler-errors/rust that referenced this issue Jun 12, 2024
This commit sets the `target_env` key for the
`wasm32-wasi{,p1,p1-threads}` targets to the string `"p1"`. This mirrors
how the `wasm32-wasip2` target has `target_env = "p2"`. The intention of
this is to more easily detect each target in downstream crates to enable
adding custom code per-target.

cc rust-lang#125803
compiler-errors added a commit to compiler-errors/rust that referenced this issue Jun 12, 2024
…s, r=wesleywiser

Add `target_env = "p1"` to the `wasm32-wasip1` target

This commit sets the `target_env` key for the
`wasm32-wasi{,p1,p1-threads}` targets to the string `"p1"`. This mirrors how the `wasm32-wasip2` target has `target_env = "p2"`. The intention of this is to more easily detect each target in downstream crates to enable adding custom code per-target.

cc rust-lang#125803

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jun 12, 2024
Rollup merge of rust-lang#125869 - alexcrichton:add-p1-to-wasi-targets, r=wesleywiser

Add `target_env = "p1"` to the `wasm32-wasip1` target

This commit sets the `target_env` key for the
`wasm32-wasi{,p1,p1-threads}` targets to the string `"p1"`. This mirrors how the `wasm32-wasip2` target has `target_env = "p2"`. The intention of this is to more easily detect each target in downstream crates to enable adding custom code per-target.

cc rust-lang#125803

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->
@workingjubilee
Copy link
Member

This seems to have been addressed to our current abilities. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-target-specs Area: Compile-target specifications A-targets Area: Concerning the implications of different compiler targets O-wasi Operating system: Wasi, Webassembly System Interface T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants