Skip to content

Commit 69df81a

Browse files
authored
Switch everything to wasmtime-wasi (#911)
1 parent c9a98ec commit 69df81a

File tree

8 files changed

+29
-71
lines changed

8 files changed

+29
-71
lines changed

Cargo.lock

+1-28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ license = "Apache-2.0 WITH LLVM-exception"
2222
wizer = "8.0.0"
2323
wasmtime = "29"
2424
wasmtime-wasi = "29"
25-
wasi-common = "29"
2625
wasm-opt = "0.116.1"
2726
anyhow = "1.0"
2827
javy = { path = "crates/javy", version = "4.0.1-alpha.1" }

crates/cli/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ name = "javy"
1111
path = "src/main.rs"
1212

1313
[dependencies]
14-
wasi-common = { workspace = true }
1514
wizer = { workspace = true }
1615
anyhow = { workspace = true }
1716
wasmtime = { workspace = true }
17+
wasmtime-wasi = { workspace = true }
1818
walrus = "0.23.3"
1919
wasm-opt = "0.116.1"
2020
tempfile = { workspace = true }

crates/cli/benches/benchmark.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ use anyhow::{anyhow, bail, Result};
22
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
33
use num_format::{Locale, ToFormattedString};
44
use std::{fmt::Display, fs, path::Path, process::Command};
5-
use wasi_common::{
6-
pipe::{ReadPipe, WritePipe},
7-
sync::WasiCtxBuilder,
8-
WasiCtx,
9-
};
105
use wasmtime::{AsContextMut, Engine, Linker, Module, Store};
6+
use wasmtime_wasi::{
7+
pipe::{MemoryInputPipe, MemoryOutputPipe},
8+
preview1::WasiP1Ctx,
9+
WasiCtxBuilder,
10+
};
1111

1212
struct FunctionCase {
1313
name: String,
@@ -86,8 +86,8 @@ impl FunctionCase {
8686

8787
pub fn run(
8888
&self,
89-
linker: &mut Linker<WasiCtx>,
90-
mut store: impl AsContextMut<Data = WasiCtx>,
89+
linker: &mut Linker<WasiP1Ctx>,
90+
mut store: impl AsContextMut<Data = WasiP1Ctx>,
9191
) -> Result<()> {
9292
let js_module = match &self.precompiled_elf_bytes {
9393
Some(bytes) => unsafe { Module::deserialize(&self.engine, bytes) }?,
@@ -107,14 +107,14 @@ impl FunctionCase {
107107
Ok(())
108108
}
109109

110-
pub fn setup(&self) -> Result<(Linker<WasiCtx>, Store<WasiCtx>)> {
110+
pub fn setup(&self) -> Result<(Linker<WasiP1Ctx>, Store<WasiP1Ctx>)> {
111111
let mut linker = Linker::new(&self.engine);
112112
let wasi = WasiCtxBuilder::new()
113-
.stdin(Box::new(ReadPipe::from(&self.payload[..])))
114-
.stdout(Box::new(WritePipe::new_in_memory()))
115-
.stderr(Box::new(WritePipe::new_in_memory()))
116-
.build();
117-
wasi_common::sync::add_to_linker(&mut linker, |s| s).unwrap();
113+
.stdin(MemoryInputPipe::new(self.payload.clone()))
114+
.stdout(MemoryOutputPipe::new(usize::MAX))
115+
.stderr(MemoryOutputPipe::new(usize::MAX))
116+
.build_p1();
117+
wasmtime_wasi::preview1::add_to_linker_sync(&mut linker, |s| s)?;
118118
let mut store = Store::new(&self.engine, wasi);
119119

120120
if let Linking::Dynamic = self.linking {

crates/cli/src/js_config.rs

+7-17
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
use anyhow::Result;
22
use serde::Deserialize;
3-
use std::{
4-
collections::HashMap,
5-
io::{Read, Seek},
6-
str,
7-
};
8-
use wasi_common::{pipe::WritePipe, sync::WasiCtxBuilder};
3+
use std::{collections::HashMap, str};
94
use wasmtime::{AsContextMut, Engine, Linker};
5+
use wasmtime_wasi::{pipe::MemoryOutputPipe, WasiCtxBuilder};
106

117
use crate::{CliPlugin, PluginKind};
128

@@ -24,25 +20,19 @@ impl ConfigSchema {
2420
let engine = Engine::default();
2521
let module = wasmtime::Module::new(&engine, cli_plugin.as_plugin().as_bytes())?;
2622
let mut linker = Linker::new(&engine);
27-
wasi_common::sync::snapshots::preview_1::add_wasi_snapshot_preview1_to_linker(
28-
&mut linker,
29-
|s| s,
30-
)?;
31-
let stdout = WritePipe::new_in_memory();
23+
wasmtime_wasi::preview1::add_to_linker_sync(&mut linker, |s| s)?;
24+
let stdout = MemoryOutputPipe::new(usize::MAX);
3225
let wasi = WasiCtxBuilder::new()
3326
.inherit_stderr()
34-
.stdout(Box::new(stdout.clone()))
35-
.build();
27+
.stdout(stdout.clone())
28+
.build_p1();
3629
let mut store = wasmtime::Store::new(&engine, wasi);
3730
let instance = linker.instantiate(store.as_context_mut(), &module)?;
3831
instance
3932
.get_typed_func::<(), ()>(store.as_context_mut(), "config_schema")?
4033
.call(store.as_context_mut(), ())?;
4134
drop(store);
42-
let mut config_json = vec![];
43-
let mut cursor = stdout.try_into_inner().unwrap();
44-
cursor.rewind()?;
45-
cursor.read_to_end(&mut config_json)?;
35+
let config_json = stdout.try_into_inner().unwrap().to_vec();
4636
let config_schema = serde_json::from_slice::<ConfigSchema>(&config_json)?;
4737
let mut configs = Vec::with_capacity(config_schema.supported_properties.len());
4838
for config in config_schema.supported_properties {

crates/cli/tests/integration_test.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use anyhow::{bail, Result};
22
use javy_runner::{Builder, Plugin, Runner, RunnerError};
33
use std::{path::PathBuf, process::Command, str};
4-
use wasi_common::sync::WasiCtxBuilder;
54
use wasmtime::{AsContextMut, Engine, Linker, Module, Store};
5+
use wasmtime_wasi::WasiCtxBuilder;
66

77
use javy_test_macros::javy_cli_test;
88

@@ -271,8 +271,8 @@ fn test_init_plugin() -> Result<()> {
271271
// `compile-src` on this module should succeed.
272272
let engine = Engine::default();
273273
let mut linker = Linker::new(&engine);
274-
wasi_common::sync::add_to_linker(&mut linker, |s| s)?;
275-
let wasi = WasiCtxBuilder::new().build();
274+
wasmtime_wasi::preview1::add_to_linker_sync(&mut linker, |s| s)?;
275+
let wasi = WasiCtxBuilder::new().build_p1();
276276
let mut store = Store::new(&engine, wasi);
277277

278278
let uninitialized_plugin = PathBuf::from(env!("CARGO_MANIFEST_DIR"))

crates/codegen/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ anyhow = { workspace = true }
1818
brotli = "7.0.0"
1919
wasmtime = { workspace = true }
2020
wasmtime-wasi = { workspace = true }
21-
wasi-common = { workspace = true }
2221
walrus = "0.23.3"
2322
swc_core = { version = "10.7.0", features = [
2423
"common_sourcemap",

crates/codegen/src/bytecode.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anyhow::{anyhow, Result};
2-
use wasi_common::{sync::WasiCtxBuilder, WasiCtx};
32
use wasmtime::{AsContextMut, Engine, Instance, Linker, Memory, Module, Store};
3+
use wasmtime_wasi::{preview1::WasiP1Ctx, WasiCtxBuilder};
44

55
pub(crate) fn compile_source(plugin_bytes: &[u8], js_source_code: &[u8]) -> Result<Vec<u8>> {
66
let (mut store, instance, memory) = create_wasm_env(plugin_bytes)?;
@@ -11,16 +11,13 @@ pub(crate) fn compile_source(plugin_bytes: &[u8], js_source_code: &[u8]) -> Resu
1111
Ok(bytecode)
1212
}
1313

14-
fn create_wasm_env(plugin_bytes: &[u8]) -> Result<(Store<WasiCtx>, Instance, Memory)> {
14+
fn create_wasm_env(plugin_bytes: &[u8]) -> Result<(Store<WasiP1Ctx>, Instance, Memory)> {
1515
let engine = Engine::default();
1616
let module = Module::new(&engine, plugin_bytes)?;
1717
let mut linker = Linker::new(&engine);
18-
wasi_common::sync::snapshots::preview_1::add_wasi_snapshot_preview1_to_linker(
19-
&mut linker,
20-
|s| s,
21-
)?;
18+
wasmtime_wasi::preview1::add_to_linker_sync(&mut linker, |s| s)?;
2219
linker.define_unknown_imports_as_traps(&module)?;
23-
let wasi = WasiCtxBuilder::new().inherit_stderr().build();
20+
let wasi = WasiCtxBuilder::new().inherit_stderr().build_p1();
2421
let mut store = Store::new(&engine, wasi);
2522
let instance = linker.instantiate(store.as_context_mut(), &module)?;
2623
let memory = instance

0 commit comments

Comments
 (0)