-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into cardano-chain-follower-api-design
- Loading branch information
Showing
59 changed files
with
7,187 additions
and
7 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
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 |
---|---|---|
|
@@ -224,6 +224,7 @@ | |
".git/**", | ||
"**/.gitignore", | ||
".vscode/**", | ||
"**/.idea/**" | ||
"**/.idea/**", | ||
"hermes/wasm/*/**" | ||
] | ||
} |
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,5 @@ | ||
[build] | ||
|
||
target = "wasm32-unknown-unknown" | ||
|
||
rustflags = ["--cap-lints", "warn"] |
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,35 @@ | ||
#cspell: words Apisit Ritreungroj wasmparser wasi bindgen | ||
|
||
[workspace] | ||
resolver = "2" | ||
members = [ | ||
"crates/wasi-component-adapter", | ||
"crates/wasi-component-adapter/verify", | ||
] | ||
|
||
[workspace.package] | ||
edition = "2021" | ||
version = "0.0.1" | ||
authors = [ | ||
"Apisit Ritreungroj <apisit.ritreungroj@iohk.io>", | ||
"Steven Johnson <steven.johnson@iohk.io>" | ||
] | ||
rust-version = "1.73" | ||
homepage = "https://input-output-hk.github.io/hermes" | ||
repository = "https://github.com/input-output-hk/hermes" | ||
license = "MIT OR Apache-2.0" | ||
|
||
[workspace.dependencies] | ||
|
||
# for `wasi-preview1-component-adapter` | ||
wit-bindgen = "0.16.0" | ||
byte-array-literals = { path = "./crates/wasi-component-adapter/byte-array-literals", version = "0.0.1" } | ||
wasm-encoder = "0.38.1" | ||
object = "0.32.1" | ||
|
||
# for `wasi-preview1-component-adapter/verify` | ||
wasmparser = "0.118.1" | ||
wat = "1.0.82" | ||
anyhow = "1.0.76" | ||
|
||
[workspace.lints] |
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,49 @@ | ||
VERSION 0.7 | ||
|
||
#cspell: words fmtchk rustfmt toolsets wasi wasmtime Earthfile | ||
|
||
# Fork the repo `wasmtime` and extract only the `wasi-preview1-component-adapter` crate from it. | ||
fork-wasi-component-adapter: | ||
LOCALLY | ||
|
||
# The local directory to store `wasi/wit`. | ||
# This needs to include along with `wasi-preview1-component-adapter`. | ||
ARG wit_local_dir=crates/wasi | ||
# The local directory to place the extracted `wasi` crate. | ||
ARG wasi_local_dir=crates/wasi-component-adapter | ||
# The location after the `wasmtime` repo was cloned. | ||
ARG wasi_git_dir=wasmtime/crates/wasi-preview1-component-adapter | ||
|
||
# Remove the existing local one. Clone and extract it from the repo. | ||
RUN rm -rf $wasi_local_dir/ || true && \ | ||
rm -rf $wit_local_dir/ || true && \ | ||
git clone --depth 1 https://github.com/bytecodealliance/wasmtime.git && \ | ||
mv $wasi_git_dir $wasi_local_dir && \ | ||
mkdir $wit_local_dir && \ | ||
mv wasmtime/crates/wasi/wit $wit_local_dir/wit && \ | ||
rm -rf wasmtime/ | ||
|
||
# Set up our target toolchains, and copy our files. | ||
builder: | ||
FROM github.com/input-output-hk/catalyst-ci/earthly/rust:v2.0.3+rust-base | ||
|
||
DO github.com/input-output-hk/catalyst-ci/earthly/rust:v2.0.3+SETUP --toolchain=rust-toolchain.toml | ||
|
||
COPY --dir .cargo Cargo.* clippy.toml deny.toml rustfmt.toml crates . | ||
|
||
# Run quality checks. | ||
check: | ||
FROM +builder | ||
|
||
RUN cargo machete && \ | ||
# cargo +nightly fmtchk && \ | ||
cargo deny check | ||
|
||
# DO github.com/input-output-hk/catalyst-ci/earthly/rust:v2.0.3+CHECK | ||
|
||
build: | ||
FROM +builder | ||
|
||
RUN cargo build --release | ||
|
||
SAVE ARTIFACT target/wasm32-unknown-unknown/release/wasi_snapshot_preview1.wasm wasi-component-adapter.wasm |
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,22 @@ | ||
# Hermes - WASM | ||
|
||
<!-- cspell: words wasmtime wasi --> | ||
|
||
This directory contains standalone Rust code that is not used as a project dependency. | ||
The primary purpose of these Rust files and packages is to compile into WebAssembly (Wasm). | ||
This code contains the forked code from | ||
[wasmtime](https://github.com/bytecodealliance/wasmtime/tree/main/crates/wasi-preview1-component-adapter), | ||
located in `crates/wasi-component-adapter` and `crates/wasi`. | ||
|
||
## Configuration | ||
|
||
The Rust configuration file locates in `.cargo/config.toml`. | ||
It already specified the build target to `wasm32-unknown-unknown`. | ||
|
||
To compile all the packages, simply run the command: | ||
|
||
```bash | ||
cargo build --release | ||
``` | ||
|
||
To build the WebAssembly binary output `.wasm`. |
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 @@ | ||
allow-unwrap-in-tests = true |
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,29 @@ | ||
[package] | ||
name = "wasi-preview1-component-adapter" | ||
version.workspace = true | ||
authors.workspace = true | ||
edition.workspace = true | ||
publish = false | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[dependencies] | ||
wasi = { version = "0.11.0", default-features = false } | ||
wit-bindgen = { workspace = true, default-features = false, features = ["macros"] } | ||
byte-array-literals = { workspace = true } | ||
|
||
[build-dependencies] | ||
wasm-encoder = { workspace = true } | ||
object = { workspace = true, default-features = false, features = ["archive"] } | ||
|
||
[lib] | ||
test = false | ||
crate-type = ["cdylib"] | ||
name = "wasi_snapshot_preview1" | ||
|
||
[features] | ||
default = ["reactor"] | ||
reactor = [] | ||
command = [] | ||
proxy = [] |
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,63 @@ | ||
# `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 -p wasi-preview1-component-adapter --target wasm32-unknown-unknown --release | ||
``` | ||
|
||
And the artifact will be located at | ||
`target/wasm32-unknown-unknown/release/wasi_snapshot_preview1.wasm`. | ||
|
||
This by default builds a "reactor" adapter which means that it only provides | ||
adaptation from preview1 to preview2. Alternatively you can also build a | ||
"command" adapter by passing `--features command --no-default-features` which | ||
will additionally export a `run` function entrypoint. This is suitable for use | ||
with preview1 binaries that export a `_start` function. | ||
|
||
Alternatively the latest copy of the command and reactor adapters can be | ||
[downloaded from the `dev` tag assets][dev-tag] | ||
|
||
[dev-tag]: https://github.com/bytecodealliance/wasmtime/releases/tag/dev | ||
|
||
## 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. |
Oops, something went wrong.