-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Promote the wasm32-wasip2
target to Tier 2
#126967
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2a3e22b
Promote the `wasm32-wasip2` target to Tier 2
alexcrichton 1afdd45
Update how wasm-component-ld is built
alexcrichton 4cd6eee
Unconditionally use stage0 build compiler
alexcrichton c370bf4
Don't use stage0 compiler for wasm-component-ld
alexcrichton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# See the `README.md` in this directory for what this tool is. | ||
|
||
[package] | ||
name = "wasm-component-ld-wrapper" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[[bin]] | ||
name = "wasm-component-ld" | ||
path = "src/main.rs" | ||
|
||
[dependencies] | ||
wasm-component-ld = "0.5.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# `wasm-component-ld` | ||
|
||
This wrapper is a wrapper around the [`wasm-component-ld`] crates.io crate. That | ||
crate. That crate is itself a thin wrapper around two pieces: | ||
|
||
* `wasm-ld` - the LLVM-based linker distributed as part of LLD and packaged in | ||
Rust as `rust-lld`. | ||
* [`wit-component`] - a Rust crate for creating a [WebAssembly Component] from a | ||
core wasm module. | ||
|
||
This linker is used for Rust's `wasm32-wasip2` target to natively output a | ||
component instead of a core WebAssembly module, unlike other WebAssembly | ||
targets. If you're confused about any of this here's an FAQ-style explanation of | ||
what's going on here: | ||
|
||
* **What's a component?** - It's a proposal to the WebAssembly standard | ||
primarily developed at this time by out-of-browser use cases of WebAssembly. | ||
You can find high-level documentation [here][component docs]. | ||
|
||
* **What's WASIp2?** - Not to be confused with WASIp1, WASIp0, | ||
`wasi_snapshot_preview1`, or `wasi_unstable`, it's a version of WASI. Released | ||
in January 2024 it's the first version of WASI defined in terms of the | ||
component model. | ||
|
||
* **Why does this need its own linker?** - like any target that Rust has the | ||
`wasm32-wasip2` target needs a linker. What makes this different from other | ||
WebAssembly targets is that WASIp2 is defined at the component level, not core | ||
WebAssembly level. This means that filesystem functions take a `string` | ||
instead of `i32 i32`, for example. This means that the raw output of LLVM and | ||
`wasm-ld`, a core WebAssembly module, is not suitable. | ||
|
||
* **Isn't writing a linker really hard?** - Generally, yes, but this linker | ||
works by first asking `wasm-ld` to do all the hard work. It invokes `wasm-ld` | ||
and then uses the output core WebAssembly module to create a component. | ||
|
||
* **How do you create a component from a core module?** - this is the purpose of | ||
the [`wit-component`] crate, notably the `ComponentEncoder` type. This uses | ||
component type information embedded in the core module and a general set of | ||
conventions/guidelines with what the core module imports/exports. A component | ||
is then hooked up to codify all of these conventions in a component itself. | ||
|
||
* **Why not require users to run `wit-component` themselves?** - while possible | ||
it adds friction to the usage `wasm32-wasip2` target. More importantly though | ||
the "module only" output of the `wasm32-wasip2` target is not ready right now. | ||
The standard library still imports from `wasi_snapshot_preview1` and it will | ||
take time to migrate all usage to WASIp2. | ||
|
||
* **What exactly does this linker do?** - the `wasm-component-ld` has the same | ||
CLI interface and flags as `wasm-ld`, plus some more that are | ||
component-specific. These flags are used to forward most flags to `wasm-ld` to | ||
produce a core wasm module. After the core wasm module is produced the | ||
`wit-component` crate will read custom sections in the final binary which | ||
contain component type information. After merging all this type information | ||
together a component is produced which wraps the core module. | ||
|
||
If you've got any other questions about this linker or its operation don't | ||
hesitate to reach out to the maintainers of the `wasm32-wasip2` target. | ||
|
||
[`wasm-component-ld`]: https://crates.io/crates/wasm-component-ld | ||
[`wit-component`]: https://crates.io/crates/wit-component | ||
[WebAssembly Component]: https://github.com/webassembly/component-model | ||
[component docs]: https://component-model.bytecodealliance.org/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// See the `README.md` in this directory for what this tool is. | ||
|
||
// The source for this crate lives at | ||
// https://github.com/bytecodealliance/wasm-component-ld and the binary is | ||
// independently used in other projects such as `wasi-sdk` so the `main` | ||
// function is just reexported here to delegate. A Cargo dependency is used to | ||
// facilitate version management in the Rust repository and work well with | ||
// vendored/offline builds. | ||
use wasm_component_ld::main; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an incomplete sentence here (and still seems to be there on master).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh oops, I'll work on fixing this.
EDIT: #130034