Skip to content

Commit 49c7411

Browse files
committed
Fix compilation errors
Using slightly worse error reporting.
1 parent 1a1870d commit 49c7411

2 files changed

Lines changed: 14 additions & 21 deletions

File tree

src/engine.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{Context as _, Result, anyhow, bail};
1+
use anyhow::{Result, anyhow, bail};
22
use futures::{StreamExt as _, stream};
33
use log::{debug, info};
44
use std::{
@@ -10,11 +10,9 @@ use wasmtime::{
1010
Engine, Store,
1111
component::{Component, Linker},
1212
};
13-
use wasmtime_wasi::{DirPerms, FilePerms, I32Exit, ResourceTable};
13+
use wasmtime_wasi::{DirPerms, FilePerms, I32Exit, ResourceTable, WasiCtx, WasiCtxView, WasiView};
1414

15-
use wasmtime_wasi::p2::{
16-
IoView, WasiCtx, WasiCtxBuilder, WasiView, bindings::Command, pipe::MemoryOutputPipe,
17-
};
15+
use wasmtime_wasi::p2::{bindings::Command, pipe::MemoryOutputPipe};
1816

1917
use crate::{
2018
config::{ConfigLinter, LinterLocation},
@@ -58,14 +56,11 @@ struct ComponentRunStates {
5856
}
5957

6058
impl WasiView for ComponentRunStates {
61-
fn ctx(&mut self) -> &mut WasiCtx {
62-
&mut self.wasi_ctx
63-
}
64-
}
65-
66-
impl IoView for ComponentRunStates {
67-
fn table(&mut self) -> &mut ResourceTable {
68-
&mut self.resource_table
59+
fn ctx(&mut self) -> WasiCtxView<'_> {
60+
WasiCtxView {
61+
ctx: &mut self.wasi_ctx,
62+
table: &mut self.resource_table,
63+
}
6964
}
7065
}
7166

@@ -122,8 +117,7 @@ pub async fn run_single_linter(
122117

123118
info!("Loading component");
124119

125-
let engine =
126-
Engine::new(wasmtime::Config::new().async_support(true)).context("creating WASM engine")?;
120+
let engine = Engine::new(&wasmtime::Config::new())?;
127121

128122
let component = wasi_cache::load_component_cached(&engine, &linter_path).await?;
129123

@@ -195,7 +189,7 @@ async fn run_linter_command(
195189
let stdout = MemoryOutputPipe::new(10 * 1024 * 1024);
196190
let stderr = MemoryOutputPipe::new(10 * 1024 * 1024);
197191

198-
let wasi = WasiCtxBuilder::new()
192+
let wasi = WasiCtx::builder()
199193
.allow_tcp(false)
200194
.allow_udp(false)
201195
.allow_ip_name_lookup(false)
@@ -238,7 +232,7 @@ async fn run_linter_command(
238232
return Ok(false);
239233
}
240234
} else {
241-
return Err(error);
235+
return Err(error.into());
242236
}
243237
}
244238
};

src/wasi_cache.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ pub async fn load_component_cached(engine: &Engine, wasi_path: &Path) -> Result<
2424
let cache_path = wasi_path.with_file_name(filename);
2525

2626
if !cache_path.exists() {
27-
let compiled = engine
28-
.precompile_component(&wasi)
29-
.context("precompiling WASI module")?;
27+
let compiled = engine.precompile_component(&wasi)?;
3028

3129
let tmpfile = wasi_path.with_file_name(unique_filename("tmp-", ".cache"));
3230
fs::write(&tmpfile, compiled).await?;
@@ -42,5 +40,6 @@ pub async fn load_component_cached(engine: &Engine, wasi_path: &Path) -> Result<
4240
// where we might end up overwriting it, but it should be with an atomic
4341
// rename and the contents should remain the same (assuming WASM compilation
4442
// is deterministic).
45-
unsafe { Component::deserialize_file(&engine, cache_path) }
43+
let result = unsafe { Component::deserialize_file(&engine, cache_path) };
44+
Ok(result?)
4645
}

0 commit comments

Comments
 (0)