Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump: upgrade wasmtime and related dependencies to 13.0.0 #221

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
506 changes: 258 additions & 248 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ wws-project = { path = "./crates/project" }
wws-panel = { path = "./crates/panel" }
wws-api-manage = { path = "./crates/api-manage" }
wws-api-manage-openapi = { path = "./crates/api-manage-openapi" }
wasmtime = "10.0.2"
wasmtime-wasi = "10.0.2"
wasmtime-wasi-nn = "10.0.2"
wasi-common = "10.0.2"
wasmtime = "13.0.0"
wasmtime-wasi = "13.0.0"
wasmtime-wasi-nn = "13.0.0"
wasi-common = "13.0.0"
path-slash = "0.2.1"
openssl = { version = "=0.10.55" }
13 changes: 8 additions & 5 deletions crates/runtimes/src/modules/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,16 @@ impl Runtime for ExternalRuntime {

/// Mount the source code in the WASI context so it can be
/// processed by the engine
fn prepare_wasi_ctx(&self, builder: WasiCtxBuilder) -> Result<WasiCtxBuilder> {
let dir = Dir::open_ambient_dir(&self.store.folder, ambient_authority())?;

fn prepare_wasi_ctx(&self, builder: &mut WasiCtxBuilder) -> Result<()> {
builder
.preopened_dir(dir, "/src")?
.preopened_dir(
Dir::open_ambient_dir(&self.store.folder, ambient_authority())?,
"/src",
)?
.args(&self.metadata.args)
.map_err(|_| errors::RuntimeError::WasiContextError)
.map_err(|_| errors::RuntimeError::WasiContextError)?;

Ok(())
}

/// Returns a reference to the Wasm module that should
Expand Down
10 changes: 7 additions & 3 deletions crates/runtimes/src/modules/javascript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ impl Runtime for JavaScriptRuntime {

/// Mount the source code in the WASI context so it can be
/// processed by the engine
fn prepare_wasi_ctx(&self, builder: WasiCtxBuilder) -> Result<WasiCtxBuilder> {
let dir = Dir::open_ambient_dir(&self.store.folder, ambient_authority())?;
Ok(builder.preopened_dir(dir, "/src")?)
fn prepare_wasi_ctx(&self, builder: &mut WasiCtxBuilder) -> Result<()> {
builder.preopened_dir(
Dir::open_ambient_dir(&self.store.folder, ambient_authority())?,
"/src",
)?;

Ok(())
}

/// Returns a reference to the Wasm module that should
Expand Down
4 changes: 2 additions & 2 deletions crates/runtimes/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ pub trait Runtime {
/// WASI context builder. This allow runtimes to mount
/// specific lib folders, source code and adding
/// environment variables.
fn prepare_wasi_ctx(&self, builder: WasiCtxBuilder) -> Result<WasiCtxBuilder> {
Ok(builder)
fn prepare_wasi_ctx(&self, _builder: &mut WasiCtxBuilder) -> Result<()> {
Ok(())
}

/// Returns a reference raw bytes of the Wasm module that should
Expand Down
2 changes: 1 addition & 1 deletion crates/worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ wws-data-kv = { workspace = true }
wws-runtimes = { workspace = true }
# We didn't integrate components yet. For an initial binding implementation,
# we will use the wit-bindgen-wasmtime crate maintained by the Fermyon team.
wit-bindgen-wasmtime = { git = "https://github.com/fermyon/wit-bindgen-backport", rev = "b89d5079ba5b07b319631a1b191d2139f126c976" }
wit-bindgen-wasmtime = { git = "https://github.com/fermyon/wit-bindgen-backport", rev = "598cd229bb43baceff9616d16930b8a5a3e79d79" }
base64 = "0.21.0"
sha256 = "1.1.1"
17 changes: 10 additions & 7 deletions crates/worker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,22 @@ impl Worker {
vars.iter().map(|(k, v)| (k.clone(), v.clone())).collect();

// Create the initial WASI context
let mut wasi_builder = WasiCtxBuilder::new()
let mut wasi_builder = WasiCtxBuilder::new();
wasi_builder
.envs(&tuple_vars)
.map_err(|_| errors::WorkerError::ConfigureRuntimeError)?;

// Configure the stdio
let stdio = Stdio::new(&input);
wasi_builder = stdio.configure_wasi_ctx(wasi_builder);
stdio.configure_wasi_ctx(&mut wasi_builder);

// Mount folders from the configuration
if let Some(folders) = self.config.folders.as_ref() {
for folder in folders {
if let Some(base) = &self.path.parent() {
let dir = Dir::open_ambient_dir(base.join(&folder.from), ambient_authority())
.map_err(|_| errors::WorkerError::ConfigureRuntimeError)?;
wasi_builder = wasi_builder
wasi_builder
.preopened_dir(dir, &folder.to)
.map_err(|_| errors::WorkerError::ConfigureRuntimeError)?;
} else {
Expand All @@ -145,7 +146,7 @@ impl Worker {
eprintln!("❌ The only WASI-NN supported backend name is \"{WASI_NN_BACKEND_OPENVINO}\". Please, update your config.");
None
} else {
wasmtime_wasi_nn::add_to_linker(&mut linker, |s: &mut WorkerState| {
wasmtime_wasi_nn::witx::add_to_linker(&mut linker, |s: &mut WorkerState| {
Arc::get_mut(s.wasi_nn.as_mut().unwrap())
.expect("wasi-nn is not implemented with multi-threading support")
})
Expand All @@ -155,18 +156,20 @@ impl Worker {
)
})?;

Some(Arc::new(WasiNnCtx::new().map_err(|_| {
let (backends, registry) = wasmtime_wasi_nn::preload(&[]).map_err(|_| {
errors::WorkerError::RuntimeError(
wws_runtimes::errors::RuntimeError::WasiContextError,
)
})?))
})?;

Some(Arc::new(WasiNnCtx::new(backends, registry)))
}
} else {
None
};

// Pass to the runtime to add any WASI specific requirement
wasi_builder = self.runtime.prepare_wasi_ctx(wasi_builder)?;
self.runtime.prepare_wasi_ctx(&mut wasi_builder)?;

let wasi = wasi_builder.build();
let state = WorkerState {
Expand Down
5 changes: 4 additions & 1 deletion crates/worker/src/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ impl Stdio {
}
}

pub fn configure_wasi_ctx(&self, builder: WasiCtxBuilder) -> WasiCtxBuilder {
pub fn configure_wasi_ctx<'a>(
&self,
builder: &'a mut WasiCtxBuilder,
) -> &'a mut WasiCtxBuilder {
builder
.stdin(Box::new(self.stdin.clone()))
.stdout(Box::new(self.stdout.clone()))
Expand Down