-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2294 from fermyon/spin-componentize-in-tree
- Loading branch information
Showing
67 changed files
with
4,772 additions
and
104 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,30 @@ | ||
[package] | ||
name = "spin-componentize" | ||
version.workspace = true | ||
authors.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
rust-version.workspace = true | ||
|
||
[dependencies] | ||
anyhow = { workspace = true } | ||
wasmparser = "0.200.0" | ||
wasm-encoder = "0.200.0" | ||
wit-component = "0.200.0" | ||
wit-parser = "0.200.0" | ||
|
||
[dev-dependencies] | ||
wasmtime = { workspace = true } | ||
wasmtime-wasi = { workspace = true } | ||
tokio = { version = "1.36.0", features = ["macros", "rt", "fs"] } | ||
async-trait = "0.1.77" | ||
cap-std = "2.0.1" | ||
rand = "0.8.5" | ||
rand_chacha = "0.3.1" | ||
rand_core = "0.6.4" | ||
serde = { version = "1.0.197", features = ["derive"] } | ||
tempfile = "3.10.0" | ||
toml = "0.8.10" | ||
serde_json = "1.0" |
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,30 @@ | ||
# spin-componentize | ||
|
||
This library converts a Spin module to a | ||
[component](https://github.com/WebAssembly/component-model/). | ||
|
||
Note that although the world specifies both `inbound-redis` and `inbound-http` | ||
exports, `spin-componentize` will only export either or both according to what | ||
the original module exported. | ||
|
||
## Building | ||
|
||
This crate requires a [Rust](https://rustup.rs/) installation v1.68 or later and a couple of Wasm targets: | ||
|
||
```shell | ||
rustup target add wasm32-wasi | ||
rustup target add wasm32-unknown-unknown | ||
``` | ||
|
||
Note that this is currently only a library and does not yet have a CLI interface, although that | ||
would be easy to add if desired. | ||
|
||
## Testing | ||
|
||
To test whether the spin componentize process produces wasm components that can be used with wasmtime, we run "abi conformance" testing. These tests are run with a plain `cargo test` invocation. | ||
|
||
## Wit and Adapters | ||
|
||
spin-componentize and the abi conformance tests use component adapters built from wasmtime. | ||
|
||
See the [adapters README](./adapters/README.md) for more information. |
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,10 @@ | ||
# Adapters | ||
|
||
The componentize process uses adapters to adapt plain wasm modules to wasi preview 2 compatible wasm components. There are three adapters that are built and stored as wasm binaries in this repository: | ||
|
||
* The upstream wasi preview1 adapters for both commands and reactors for use with newer versions of wit-bindgen (v0.5 and above). | ||
* These are currently [the wasmtime 18.0.1 release](https://github.com/bytecodealliance/wasmtime/releases/tag/v18.0.1). | ||
* A modified adapter that has knowledge of Spin APIs for use with v0.2 of wit-bindgen which has a different ABI than newer wit-bindgen based modules. | ||
* This is currently built using commit [603fb3e](https://github.com/rylev/wasmtime/commit/603fb3e14fb0eb7468b832711fee5ff7e7ce7012) on the github.com/rylev/wasmtime fork of wasmtime. | ||
* You can see a diff between the upstream wasmtime 18.0.1 compatible adapter and this custom adapter [here](https://github.com/bytecodealliance/wasmtime/compare/release-18.0.0...rylev:wasmtime:v18.0.1-spin). | ||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,31 @@ | ||
use std::{ | ||
env, fs, | ||
path::{Path, PathBuf}, | ||
}; | ||
|
||
fn main() { | ||
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
let adapters_dir = Path::new("adapters"); | ||
std::fs::create_dir_all(out_dir.join("wasm32-unknown-unknown/release")).unwrap(); | ||
|
||
println!("cargo:rerun-if-changed=adapters/wasi_snapshot_preview1.spin.wasm"); | ||
fs::copy( | ||
adapters_dir.join("wasi_snapshot_preview1.spin.wasm"), | ||
out_dir.join("wasm32-unknown-unknown/release/wasi_snapshot_preview1_spin.wasm"), | ||
) | ||
.unwrap(); | ||
|
||
println!("cargo:rerun-if-changed=adapters/wasi_snapshot_preview1.reactor.wasm"); | ||
fs::copy( | ||
adapters_dir.join("wasi_snapshot_preview1.reactor.wasm"), | ||
out_dir.join("wasm32-unknown-unknown/release/wasi_snapshot_preview1_upstream.wasm"), | ||
) | ||
.unwrap(); | ||
|
||
println!("cargo:rerun-if-changed=adapters/wasi_snapshot_preview1.command.wasm"); | ||
fs::copy( | ||
adapters_dir.join("wasi_snapshot_preview1.command.wasm"), | ||
out_dir.join("wasm32-unknown-unknown/release/wasi_snapshot_preview1_command.wasm"), | ||
) | ||
.unwrap(); | ||
} |
Oops, something went wrong.