This repository has been archived by the owner on Oct 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update a few aspects of the adapter build
* Use the `wasm32-unknown-unknown` target for the adapter and specify flags in `.cargo/config.toml` to avoid having to pass the same flags everywhere. This allows using `wasm32-wasi` for tests to ensure the flags only apply to the adapter. * Use `opt-level=s` since speed is not of the utmost concern for this wasm but since it's likely to be included in many places size is likely more important. * Use `strip = 'debuginfo'` for the release build to remove the standard library's debugging information which isn't necessary. * Remove `debug = 0` from the `dev` profile to have debugging information for development. * Add a small `README.md` describing what's here for now.
- Loading branch information
1 parent
2c96f4d
commit 01ea870
Showing
5 changed files
with
90 additions
and
25 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,18 @@ | ||
[target.wasm32-wasi] | ||
#rustflags = ['-Clink-arg=--import-memory'] | ||
# The adapter module created in this repository can technically be either | ||
# compiled for wasm32-wasi or the unknown-unknown target but the unknown version | ||
# is used to be able to specify custom flags here. That way the wasi tests don't | ||
# use these custom flags but the adapter does. | ||
[target.wasm32-unknown-unknown] | ||
rustflags = [ | ||
# The adapter must import its memory from the main module so pass this for LLD | ||
# to generate the right memory import. | ||
'-Clink-arg=--import-memory', | ||
# The adapter will allocate its own stack and doesn't use the --stack-first | ||
# layout that LLD has by default. Set the stack size from LLD to zero here to | ||
# ensure that the memory imported into the module has a minimum size of 0 as | ||
# opposed to 1MB which might not be compatible with some WASI-using modules. | ||
'-Clink-arg=-zstack-size=0', | ||
# Currently all locations that will run this adapter have this feature enabled | ||
# and this avoid generating a `memcpy` function in the adapter itself. | ||
'-Ctarget-feature=+bulk-memory', | ||
] |
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,56 @@ | ||
# `wasi_snapshot_preview1.wasm` | ||
|
||
> **Note**: This repository is a work in progress. This is intended to be an | ||
> internal tool which not everyone has to look at but many might rely on. You | ||
> may need to reach out via issues or | ||
> [Zulip](https://bytecodealliance.zulipchat.com/) to learn more about this | ||
> repository. | ||
This repository currently contains an implementation of a WebAssembly module: | ||
`wasi_snapshot_preview1.wasm`. This module bridges the `wasi_snapshot_preview1` | ||
ABI to the preview2 ABI of the component model. At this time the preview2 APIs | ||
themselves are not done being specified so a local copy of `wit/*.wit` is used | ||
instead. | ||
|
||
## Building | ||
|
||
This adapter can be built with: | ||
|
||
```sh | ||
$ cargo build --target wasm32-unknown-unknown --release | ||
``` | ||
|
||
And the artifact will be located at | ||
`target/wasm32-unknown-unknown/release/wasi_snapshot_preview1.wasm`. | ||
Alternatively the latest copy of this can be [downloaded from the releases | ||
page][latest-release] | ||
|
||
[latest-release]: https://github.com/bytecodealliance/preview2-prototyping/releases/tag/latest | ||
|
||
## Using | ||
|
||
With a `wasi_snapshot_preview1.wasm` file on-hand you can create a component | ||
from a module that imports WASI functions using the [`wasm-tools` | ||
CLI](https://github.com/bytecodealliance/wasm-tools) | ||
|
||
```sh | ||
$ cat foo.rs | ||
fn main() { | ||
println!("Hello, world!"); | ||
} | ||
$ rustc foo.rs --target wasm32-wasi | ||
$ wasm-tools print foo.wasm | grep '(import' | ||
(import "wasi_snapshot_preview1" "fd_write" (func ... | ||
(import "wasi_snapshot_preview1" "environ_get" (func ... | ||
(import "wasi_snapshot_preview1" "environ_sizes_get" ... | ||
(import "wasi_snapshot_preview1" "proc_exit" (func ... | ||
$ wasm-tools component new foo.wasm --adapt wasi_snapshot_preview1.wasm -o component.wasm | ||
|
||
# Inspect the generated `component.wasm` | ||
$ wasm-tools validate component.wasm --features component-model | ||
$ wasm-tools component wit component.wasm | ||
``` | ||
Here the `component.wasm` that's generated is a ready-to-run component which | ||
imports wasi preview2 functions and is compatible with the wasi-preview1-using | ||
module internally. |
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