Skip to content

Commit f2bb7e9

Browse files
committed
WIP: extism example
1 parent 26253d9 commit f2bb7e9

File tree

9 files changed

+12521
-0
lines changed

9 files changed

+12521
-0
lines changed

extism/host/Cargo.lock

Lines changed: 6052 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extism/host/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "extism-host"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
anyhow = "1.0.79"
8+
extism = "1.0.0"
9+
tokio = { version = "1", features = ["full"] }
10+
iroh-extism-host-functions = { path = "../iroh-extism-host-functions" }

extism/host/src/main.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use extism::*;
2+
3+
#[tokio::main]
4+
async fn main() -> anyhow::Result<()> {
5+
let tokio_rt = tokio::runtime::Builder::new_multi_thread()
6+
.thread_name("main-runtime")
7+
.worker_threads(2)
8+
.enable_all()
9+
.build()?;
10+
let rt = tokio_rt.handle().clone();
11+
12+
let iroh = rt.block_on(async {
13+
let iroh_path = iroh_extism_host_functions::default_iroh_extism_data_root().await?;
14+
iroh_extism_host_functions::create_iroh(iroh_path).await
15+
})?;
16+
println!("iroh node id: {:?}", iroh.node_id());
17+
18+
let file = Wasm::file("../plugin/target/wasm32-unknown-unknown/debug/plugin.wasm");
19+
let manifest = Manifest::new([file]);
20+
21+
let plugin = PluginBuilder::new(manifest)
22+
.with_wasi(true);
23+
24+
let mut plugin = iroh_extism_host_functions::add_all_host_functions(rt, plugin, iroh)
25+
.build()?;
26+
27+
let res = plugin
28+
.call::<&str, &str>("print_hai_and_get_ticket", "blobaaa54kekl2oa7yd5ro3u65kynwolq3h2msu65c3jfj44ja23fstmcajcnb2hi4dthixs65ltmuys2mjomrsxe4bonfzg62bonzsxi53pojvs4lydabefsibbyrlqbqfiirdmivybeyaeaqktotuaaaaaaaaaaaaqb7cvoah75ql4x2hvxaxxlgje2d7qy2avizyjb25pd4anc6c5ulvgpth5xq")
29+
.unwrap();
30+
31+
println!("{}", res);
32+
33+
Ok(())
34+
}

0 commit comments

Comments
 (0)