Skip to content

Commit

Permalink
Rollup merge of rust-lang#115345 - g0djan:godjan/tier2-wasi-threads, …
Browse files Browse the repository at this point in the history
…r=WaffleLapkin

MCP661: Move wasm32-wasi-preview1-threads target to Tier 2

rust-lang/compiler-team#661

>A tier 2 target must have value to people other than its maintainers. (It may still be a niche target, but it must not be exclusively useful for an inherently closed group.)

The feature is already implemented in [wasi-sdk(](https://github.com/WebAssembly/wasi-sdk) (C toolchain for WASM), and four different WASM runtimes([Wasmtime](https://github.com/bytecodealliance/wasmtime), [WAMR](https://github.com/bytecodealliance/wasm-micro-runtime), [Wasmer](https://github.com/wasmerio/wasmer), [toywasm](https://github.com/yamt/toywasm)) are compatible with it.

>A tier 2 target must have a designated team of developers (the "target maintainers") available to consult on target-specific build-breaking issues, or if necessary to develop target-specific language or library implementation details. This team must have at least 2 developers.
>The target maintainers should not only fix target-specific issues, but should use any such issue as an opportunity to educate the Rust community about portability to their target, and enhance documentation of the target.

We already have a team of 4 developers. See [src/doc/rustc/src/platform-support/wasm32-wasi-preview1-threads.md](https://github.com/rust-lang/rust/blob/master/src/doc/rustc/src/platform-support/wasm32-wasi-preview1-threads.md). The documentation is being updated in this PR as the first occurrence.

>The target must not place undue burden on Rust developers not specifically concerned with that target. Rust developers are expected to not gratuitously break a tier 2 target, but are not expected to become experts in every tier 2 target, and are not expected to provide target-specific implementations for every tier 2 target.

It doesn't as it’s built on top of existing wasm32-wasi tier-2 target and it only extends stdlib by implementing
std:: thread::spawn/join.

> The target must provide documentation for the Rust community explaining how to build for the target using cross-compilation, and explaining how to run tests for the target. If at all possible, this documentation should show how to run Rust programs and tests for the target using emulation, to allow anyone to do so. If the target cannot be feasibly emulated, the documentation should explain how to obtain and work with physical hardware, cloud systems, or equivalent.

For build and running tests see *Building Rust programs* and *Testing* in [src/doc/rustc/src/platform-support/wasm32-wasi-preview1-threads.md](https://github.com/rust-lang/rust/blob/master/src/doc/rustc/src/platform-support/wasm32-wasi-preview1-threads.md). Only manual test running is supported at the moment with some tweaks in the test runner codebase.

> The target must document its baseline expectations for the features or versions of CPUs, operating systems, libraries, runtime environments, and similar.

See *Platform requirements* in [src/doc/rustc/src/platform-support/wasm32-wasi-preview1-threads.md](https://github.com/rust-lang/rust/blob/master/src/doc/rustc/src/platform-support/wasm32-wasi-preview1-threads.md)

> If introducing a new tier 2 or higher target that is identical to an existing Rust target except for the baseline expectations for the features or versions of CPUs, operating systems, libraries, runtime environments, and similar, then the proposed target must document to the satisfaction of the approving teams why the specific difference in baseline expectations provides sufficient value to justify a separate target.
>Note that in some cases, based on the usage of existing targets within the Rust community, Rust developers or a target's maintainers may wish to modify the baseline expectations of a target, or split an existing target into multiple targets with different baseline expectations. A proposal to do so will be treated similarly to the analogous promotion, demotion, or removal of a target, according to this policy, with the same team approvals required.
>For instance, if an OS version has become obsolete and unsupported, a target for that OS may raise its baseline expectations for OS version (treated as though removing a target corresponding to the older versions), or a target for that OS may split out support for older OS versions into a lower-tier target (treated as though demoting a target corresponding to the older versions, and requiring justification for a new target at a lower tier for the older OS versions).

Justified in rust-lang/compiler-team#574 and I acknowledge these requirements and intend to ensure they are met.

> Tier 2 targets must not leave any significant portions of core or the standard library unimplemented or stubbed out, unless they cannot possibly be supported on the target.
>The right approach to handling a missing feature from a target may depend on whether the target seems likely to develop the feature in the future. In some cases, a target may be co-developed along with Rust support, and Rust may gain new features on the target as that target gains the capabilities to support those features.
>As an exception, a target identical to an existing tier 1 target except for lower baseline expectations for the OS, CPU, or similar, may propose to qualify as tier 2 (but not higher) without support for std if the target will primarily be used in no_std applications, to reduce the support burden for the standard library. In this case, evaluation of the proposed target's value will take this limitation into account.

It does not, as it’s built as an extension of the existing tier 2 target (wasm32-wasi).

> The code generation backend for the target should not have deficiencies that invalidate Rust safety properties, as evaluated by the Rust compiler team. (This requirement does not apply to arbitrary security enhancements or mitigations provided by code generation backends, only to those properties needed to ensure safe Rust code cannot cause undefined behavior or other unsoundness.) If this requirement does not hold, the target must clearly and prominently document any such limitations as part of the target's entry in the target tier list, and ideally also via a failing test in the testsuite. The Rust compiler team must be satisfied with the balance between these limitations and the difficulty of implementing the necessary features.
>For example, if Rust relies on a specific code generation feature to ensure that safe code cannot overflow the stack, the code generation for the target should support that feature.
>If the Rust compiler introduces new safety properties (such as via new capabilities of a compiler backend), the Rust compiler team will determine if they consider those new safety properties a best-effort improvement for specific targets, or a required property for all Rust targets. In the latter case, the compiler team may require the maintainers of existing targets to either implement and confirm support for the property or update the target tier list with documentation of the missing property.

Doesn't apply, the target re-uses existing backend and doesn't extend it

> If the target supports C code, and the target has an interoperable calling convention for C code, the Rust target must support that C calling convention for the platform via extern "C". The C calling convention does not need to be the default Rust calling convention for the target, however.

Target does not support C code
>The target must build reliably in CI, for all components that Rust's CI considers mandatory.

The target reliably builds in CI already https://github.com/rust-lang/rust/blob/master/src/ci/docker/host-x86_64/dist-various-2/Dockerfile#L143.

>The approving teams may additionally require that a subset of tests pass in CI, such as enough to build a functional "hello world" program, ./x.py test --no-run, or equivalent "smoke tests". In particular, this requirement may apply if the target builds host tools, or if the tests in question provide substantial value via early detection of critical problems.

The existing tier-2 target and this target as its extension [pass](rust-lang#112922 (comment)) for 14.5k+ tests/ui when tests are run manually(described in *Testing* in in [src/doc/rustc/src/platform-support/wasm32-wasi-preview1-threads.md](https://github.com/rust-lang/rust/blob/master/src/doc/rustc/src/platform-support/wasm32-wasi-preview1-threads.md). Can be tested in the CI as soon as the original target does.

> Building the target in CI must not take substantially longer than the current slowest target in CI, and should not substantially raise the maintenance burden of the CI infrastructure. This requirement is subjective, to be evaluated by the infrastructure team, and will take the community importance of the target into account.

It doesn’t as it only slightly extends standard library of the existing target

> Tier 2 targets should, if at all possible, support cross-compiling. Tier 2 targets should not require using the target as the host for builds, even if the target supports host tools.

N/a given as it only extends stdlib of the existing target.

> In addition to the legal requirements for all targets (specified in the tier 3 requirements), because a tier 2 target typically involves the Rust project building and supplying various compiled binaries, incorporating the target and redistributing any resulting compiled binaries (e.g. built libraries, host tools if any) must not impose any onerous license requirements on any members of the Rust project, including infrastructure team members and those operating CI systems. This is a subjective requirement, to be evaluated by the approving teams.
>As an exception to this, if the target's primary purpose is to build components for a Free and Open Source Software (FOSS) project licensed under "copyleft" terms (terms which require licensing other code under compatible FOSS terms), such as kernel modules or plugins, then the standard libraries for the target may potentially be subject to copyleft terms, as long as such terms are satisfied by Rust's existing practices of providing full corresponding source code. Note that anything added to the Rust repository itself must still use Rust's standard license terms.

Requirement are met, no legal issues.

> Tier 2 targets must not impose burden on the authors of pull requests, or other developers in the community, to ensure that tests pass for the target. In particular, do not post comments (automated or manual) on a PR that derail or suggest a block on the PR based on tests failing for the target. Do not send automated messages or notifications (via any medium, including via ```@)``` to a PR author or others involved with a PR regarding the PR breaking tests on a tier 2 target, unless they have opted into such messages.
>Backlinks such as those generated by the issue/PR tracker when linking to an issue or PR are not considered a violation of this policy, within reason. However, such messages (even on a separate repository) must not generate notifications to anyone involved with a PR who has not requested such notifications.

I acknowledge these requirements and intend to ensure they are met.
> The target maintainers should regularly run the testsuite for the target, and should fix any test failures in a reasonably timely fashion.

The tests are run manually every week by ```@g0djan``` now.
While target has been in Tier 3, 2 issues(rust-lang#114608 and rust-lang#114610) have been raised. Both issues were addressed the same day and fixes has been merged by now.

> All requirements for tier 3 apply.

Target was initially accepted as a Tier 3 target in rust-lang#112922 .
  • Loading branch information
GuillaumeGomez committed Sep 7, 2023
2 parents c5775a7 + ac76882 commit e4fd23a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
Expand Up @@ -10,7 +10,7 @@ bin="$PWD/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04/bin"
git clone https://github.com/WebAssembly/wasi-libc

cd wasi-libc
git reset --hard 7018e24d8fe248596819d2e884761676f3542a04
git reset --hard ec4566beae84e54952637f0bf61bee4b4cacc087
make -j$(nproc) \
CC="$bin/clang" \
NM="$bin/llvm-nm" \
Expand Down
Expand Up @@ -10,7 +10,7 @@ bin="$PWD/clang+llvm-16.0.4-x86_64-linux-gnu-ubuntu-22.04/bin"
git clone https://github.com/WebAssembly/wasi-libc

cd wasi-libc
git reset --hard 7018e24d8fe248596819d2e884761676f3542a04
git reset --hard ec4566beae84e54952637f0bf61bee4b4cacc087
make -j$(nproc) \
CC="$bin/clang" \
NM="$bin/llvm-nm" \
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustc/src/platform-support.md
Expand Up @@ -181,6 +181,7 @@ target | std | notes
`wasm32-unknown-emscripten` | ✓ | WebAssembly via Emscripten
`wasm32-unknown-unknown` | ✓ | WebAssembly
`wasm32-wasi` | ✓ | WebAssembly with WASI
[`wasm32-wasi-preview1-threads`](platform-support/wasm32-wasi-preview1-threads.md) | ✓ | | WebAssembly with WASI Preview 1 and threads
`x86_64-apple-ios` | ✓ | 64-bit x86 iOS
[`x86_64-fortanix-unknown-sgx`](platform-support/x86_64-fortanix-unknown-sgx.md) | ✓ | [Fortanix ABI] for 64-bit Intel SGX
`x86_64-fuchsia` | ✓ | Alias for `x86_64-unknown-fuchsia`
Expand Down Expand Up @@ -323,7 +324,6 @@ target | std | host | notes
`thumbv7a-pc-windows-msvc` | ? | |
`thumbv7a-uwp-windows-msvc` | ✓ | |
`thumbv7neon-unknown-linux-musleabihf` | ? | | Thumb2-mode ARMv7-A Linux with NEON, MUSL
[`wasm32-wasi-preview1-threads`](platform-support/wasm32-wasi-preview1-threads.md) | ✓ | | WebAssembly with WASI Preview 1 and threads
[`wasm64-unknown-unknown`](platform-support/wasm64-unknown-unknown.md) | ? | | WebAssembly
`x86_64-apple-ios-macabi` | ✓ | | Apple Catalyst on x86_64
[`x86_64-apple-tvos`](platform-support/apple-tvos.md) | ? | | x86 64-bit tvOS
Expand Down
33 changes: 21 additions & 12 deletions src/doc/rustc/src/platform-support/wasm32-wasi-preview1-threads.md
@@ -1,6 +1,6 @@
# `wasm32-wasi-preview1-threads`

**Tier: 3**
**Tier: 2**

The `wasm32-wasi-preview1-threads` target is a new and still (as of July 2023) an
experimental target. This target is an extension to `wasm32-wasi-preview1` target,
Expand Down Expand Up @@ -70,12 +70,6 @@ compile `wasm32-wasi-preview1-threads` binaries straight out of the box. You can
reliably interoperate with C code in this mode (yet).


This target is not a stable target. This means that there are not many engines
which implement the `wasi-threads` feature and if they do they're likely behind a
flag, for example:

* Wasmtime - `--wasm-features=threads --wasi-modules=experimental-wasi-threads`

Also note that at this time the `wasm32-wasi-preview1-threads` target assumes the
presence of other merged wasm proposals such as (with their LLVM feature flags):

Expand All @@ -94,6 +88,17 @@ The target intends to match the corresponding Clang target for its `"C"` ABI.
> found it's recommended to open an issue either with rust-lang/rust or ideally
> with LLVM itself.
## Platform requirements

The runtime should support the same set of APIs as any other supported wasi target for interacting with the host environment through the WASI standard. The runtime also should have implemetation of [wasi-threads proposal](https://github.com/WebAssembly/wasi-threads).

This target is not a stable target. This means that there are a few engines
which implement the `wasi-threads` feature and if they do they're likely behind a
flag, for example:

* Wasmtime - `--wasm-features=threads --wasi-modules=experimental-wasi-threads`
* [WAMR](https://github.com/bytecodealliance/wasm-micro-runtime) - needs to be built with WAMR_BUILD_LIB_WASI_THREADS=1

## Building the target

Users need to install or built wasi-sdk since release 20.0
Expand All @@ -110,12 +115,16 @@ After that users can build this by adding it to the `target` list in

## Building Rust programs

Since it is Tier 3, rust doesn't ship pre-compiled artifacts for this target.
From Rust Nightly 1.71.1 (2023-08-03) on the artifacts are shipped pre-compiled:

```text
rustup target add wasm32-wasi-preview1-threads --toolchain nightly
```

Rust programs can be built for that target:

Specify `wasi-root` as explained in the previous section and then use the `build-std`
nightly cargo feature to build the standard library:
```shell
cargo +nightly build --target=wasm32-wasi-preview1-threads -Zbuild-std
```text
rustc --target wasm32-wasi-preview1-threads your-code.rs
```

## Cross-compilation
Expand Down

0 comments on commit e4fd23a

Please sign in to comment.