Skip to content

Introduce a tier-3 wasm32-component target #948

@yoshuawuyts

Description

@yoshuawuyts

Proposal

We’d like to propose adding a new target to Rust: wasm32-component. This target is very similar to the wasm32-wasip2 and wasm32-wasip3 targets, except that it doesn’t rely on and exposes any of the WASI APIs, instead only ever being able to build Wasm Component model built-ins.

There are many instances where host platforms do not want to provide access to the entire breadth of WASI APIs like sockets and files. This includes examples like HTTP proxies, build system plugins, and embedded scenarios. Currently the best way to build for these platforms is to target one of the wasm32-wasi{2,3} targets, and ask users don’t try and use any of std::net and std::fs so these symbols don’t end up in the import section of the final binary. But this approach feels rather icky and confuses users, so it would be good to be able to statically guarantee the right things will happen by providing a dedicated Rust build target.

This target will most likely only support core + alloc. In theory it may at some point also want to support std::thread, since threads are being added as a core built-in to Wasm Components. But they haven’t landed yet, and for this target we may very well be able to point people at using them via a third-party library instead. We may want to revisit this in the future; but for now core + alloc is sufficient.

In terms of implementation: this target provides a subset of the wasm32-wasip{2,3} targets. In terms of compiler infrastructure it should add little extra maintenance burden on top of the existing targets.

Target Tier Policy

A tier 3 target must have a designated developer or developers (the "target maintainers") on record to be CCed when issues arise regarding the target. (The mechanism to track and CC such developers may evolve over time.)

@alexcrichton will be the designated maintainer for the target

Targets must use naming consistent with any existing targets; for instance, a target for the same CPU or OS as an existing Rust target should use the same name for that CPU or OS. Targets should normally use the same names and naming conventions as used elsewhere in the broader ecosystem beyond Rust (such as in other toolchains), unless they have a very good reason to diverge. Changing the name of a target can be highly disruptive, especially once the target reaches a higher tier, so getting the name right is important even for a tier 3 target.

The name for this target is wasm32-component. In the Wasm family of targets this is a new target name. wasm32 is the instruction family, component is the packaging format (similar to elf for Linux platforms). In theory this could have been named wasm32-unknown-component which would be closer to wasm32-unknown-unknown, but would put us further away from wasm32-wasip{1,2}.

There is no perfectly consistent naming scheme available for this target. But we believe that wasm32-component provides the most memorable/ergonomic target name. In theory for an eventual WASI 1.0 target the most consistent scheme would then become wasm32-component-wasi, indicating that it is wasm32-component plus support for WASI APIs. But that’s not something we need to decide on now. And at the very least we feel confident that wasm32-component is the best option for this target.

Tier 3 targets may have unusual requirements to build or use, but must not create legal issues or impose onerous legal terms for the Rust project or for Rust developers or users.

Understood. Building/using wasm32-component is effectively a subset of wasm32-wasip{2,3} and should not present any additional challenges or hurdles.

Neither this policy nor any decisions made regarding targets shall create any binding agreement or estoppel by any party. If any member of an approving Rust team serves as one of the maintainers of a target, or has any legal or employment requirement (explicit or implicit) that might affect their decisions regarding a target, they must recuse themselves from any approval decisions regarding the target's tier status, though they may otherwise participate in discussions.

Sounds good.

Tier 3 targets should attempt to implement as much of the standard libraries as possible and appropriate (core for most targets, alloc for targets that can support dynamic memory allocation, std for targets with an operating system or equivalent layer of system-provided functionality), but may leave some code unimplemented (either unavailable or stubbed out as appropriate), whether because the target makes it impossible to implement or challenging to implement. The authors of pull requests are not obligated to avoid calling any portions of the standard library on the basis of a tier 3 target not implementing those portions.

wasm32-component is intended to support core + alloc but not std. wasm32-wasip{2,3} are the targets intended to support std. Though eventually wasm32-component may get platform support for threads, in which case we will have to decide whether to add support for that via std::thread, via a platform-specific API, a third-party library, or some other solution. But that is not something we have to decide on now.

The target must provide documentation for the Rust community explaining how to build for the target, using cross-compilation if possible. If the target supports running binaries, or running tests (even if they do not pass), the documentation must explain how to run such binaries or tests for the target, using emulation if possible or dedicated hardware if necessary.

The PR introducing the target will include a wasm32_component.md file outlining the build instructions in more detail. This document is expected to closely match the existing wasm32_wasip{2,3}.md documents.

Tier 3 targets must not impose burden on the authors of pull requests, or other developers in the community, to maintain 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 a tier 3 target. Do not send automated messages or notifications (via any medium, including via @) to a PR author or others involved with a PR regarding a tier 3 target, unless they have opted into such messages.

This new target won't be any more of a burden than wasm32-wasip{2,3}, which I'm under the impression is already not much of a burden. If something changes about that though please let us know!

Patches adding or updating tier 3 targets must not break any existing tier 2 or tier 1 target, and must not knowingly break another tier 3 target without approval of either the compiler team or the maintainers of the other tier 3 target.

Any breakage here would definitely be unintentional and @alexcrichton would be happy to follow-up with a fix if that happens.

Tier 3 targets must be able to produce assembly using at least one of rustc's supported backends from any host target. (Having support in a fork of the backend is not sufficient, it must be upstream.)

The Wasm backend in LLVM is sufficient for this.

Mentors or Reviewers

If you have a reviewer or mentor in mind for this work, mention them here. You can put your own name here if you are planning to mentor the work.

@alexcrichton will be implementing this. I believe he is a known compiler contributor who doesn’t need any mentorship, but will require code review. In the past I’ve asked @wesleywiser to review the addition of new Wasm targets, but we’re happy to work with whoever is available for review from the compiler team.

Process

The main points of the Major Change Process are as follows:

  • File an issue describing the proposal.
  • A compiler team member who is knowledgeable in the area can second by writing @rustbot second or kickoff a team FCP with @rfcbot fcp $RESOLUTION.
  • Once an MCP is seconded, the Final Comment Period begins.
    • Final Comment Period lasts for 10 days after all outstanding concerns are solved.
    • Outstanding concerns will block the Final Comment Period from finishing. Once all concerns are resolved, the 10 day countdown is restarted.
    • If no concerns are raised after 10 days since the resolution of the last outstanding concern, the MCP is considered approved.

You can read more about Major Change Proposals on forge.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-compilerAdd this label so rfcbot knows to poll the compiler teammajor-changeA proposal to make a major change to rustcto-announceAnnounce this issue on triage meeting

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions