Skip to content

Commit 7133257

Browse files
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> -->
2 parents 1d43fbb + d313e7e commit 7133257

File tree

6 files changed

+34
-1
lines changed

6 files changed

+34
-1
lines changed

compiler/rustc_target/src/spec/targets/wasm32_wasip1.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub fn target() -> Target {
1818
let mut options = base::wasm::options();
1919

2020
options.os = "wasi".into();
21+
options.env = "p1".into();
2122
options.add_pre_link_args(LinkerFlavor::WasmLld(Cc::Yes), &["--target=wasm32-wasi"]);
2223

2324
options.pre_link_objects_self_contained = crt_objects::pre_wasi_self_contained();

compiler/rustc_target/src/spec/targets/wasm32_wasip1_threads.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub fn target() -> Target {
1313
let mut options = base::wasm::options();
1414

1515
options.os = "wasi".into();
16+
options.env = "p1".into();
1617

1718
options.add_pre_link_args(
1819
LinkerFlavor::WasmLld(Cc::No),

src/doc/rustc/src/platform-support/wasm32-wasip1-threads.md

+12
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,15 @@ or another engine that supports `wasi-threads` is installed and can be found in
150150
5. Apply such [a change](https://github.com/g0djan/rust/compare/godjan/wasi-threads...g0djan:rust:godjan/wasi-run-ui-tests?expand=1) with an engine from the step 1.
151151
6. Run `./x.py test --target wasm32-wasip1-threads tests/ui` and save the list of failed tests.
152152
7. For both lists of failed tests run `cat list | sort > sorted_list` and compare it with `diff sorted_list1 sorted_list2`.
153+
154+
## Conditionally compiling code
155+
156+
It's recommended to conditionally compile code for this target with:
157+
158+
```text
159+
#[cfg(all(target_os = "wasi", target_env = "p1", target_feature = "atomics"))]
160+
```
161+
162+
Prior to Rust 1.80 the `target_env = "p1"` key was not set. Currently the
163+
`target_feature = "atomics"` is Nightly-only. Note that the precise `#[cfg]`
164+
necessary to detect this target may change as the target becomes more stable.

src/doc/rustc/src/platform-support/wasm32-wasip1.md

+11
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,14 @@ can be tested locally, for example, with:
121121
```text
122122
./x.py test --target wasm32-wasip1 tests/ui
123123
```
124+
125+
## Conditionally compiling code
126+
127+
It's recommended to conditionally compile code for this target with:
128+
129+
```text
130+
#[cfg(all(target_os = "wasi", target_env = "p1"))]
131+
```
132+
133+
Note that the `target_env = "p1"` condition first appeared in Rust 1.80. Prior
134+
to Rust 1.80 the `target_env` condition was not set.

src/doc/rustc/src/platform-support/wasm32-wasip2.md

+8
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,11 @@ This target is not tested in CI at this time. Locally it can be tested with a
5353
```text
5454
./x.py test --target wasm32-wasip2 tests/ui
5555
```
56+
57+
## Conditionally compiling code
58+
59+
It's recommended to conditionally compile code for this target with:
60+
61+
```text
62+
#[cfg(all(target_os = "wasi", target_env = "p2"))]
63+
```

tests/ui/check-cfg/well-known-values.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
147147
LL | target_env = "_UNEXPECTED_VALUE",
148148
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
149149
|
150-
= note: expected values for `target_env` are: ``, `gnu`, `msvc`, `musl`, `newlib`, `nto70`, `nto71`, `ohos`, `p2`, `psx`, `relibc`, `sgx`, and `uclibc`
150+
= note: expected values for `target_env` are: ``, `gnu`, `msvc`, `musl`, `newlib`, `nto70`, `nto71`, `ohos`, `p1`, `p2`, `psx`, `relibc`, `sgx`, and `uclibc`
151151
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
152152

153153
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`

0 commit comments

Comments
 (0)