Skip to content

Commit

Permalink
deps: upgrade to latest toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Jul 26, 2023
1 parent 7bb256d commit e20916d
Show file tree
Hide file tree
Showing 15 changed files with 631 additions and 475 deletions.
819 changes: 408 additions & 411 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ clap = { version = "4", features = ["derive"] }
serde = { version = "1", features = ["derive"] }
toml = "0.7"
walrus = "0.20.1"
wasm-compose = { git = "https://github.com/bytecodealliance/wasm-tools", branch = "main" }
wasm-metadata = { git = "https://github.com/bytecodealliance/wasm-tools" }
wasm-compose = "0.4.0"
wasm-metadata = "0.10.1"
wasm-opt = "0.113.0"
wit-component = { git = "https://github.com/bytecodealliance/wasm-tools" }
wit-component = "0.13.1"

[build-dependencies]
anyhow = "1"
Expand All @@ -45,8 +45,8 @@ anyhow = "1"
async-std = { version = "1", features = ["attributes"] }
cap-std = "1.0.12"
heck = { version = "0.4" }
wasmtime = { version = "10.0.1", features = ["component-model"] }
wasmtime-wasi = "10.0.1"
wasmtime = { git = "https://github.com/alexcrichton/wasmtime", branch = "update-wasm-tools", features = ["component-model"] }
wasmtime-wasi = { git = "https://github.com/alexcrichton/wasmtime", branch = "update-wasm-tools" }

[workspace.dependencies]
anyhow = "1"
Expand Down
Binary file modified lib/virtual_adapter.wasm
Binary file not shown.
Binary file modified lib/wasi_snapshot_preview1.reactor.wasm
Binary file not shown.
3 changes: 3 additions & 0 deletions src/bin/wasi-virt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ struct Args {
#[arg(long, num_args(0..), use_value_delimiter(true), require_equals(true), value_name("ENV_VAR"))]
allow_env: Option<Vec<String>>,

/// Set environment variable overrides
#[arg(short, long, use_value_delimiter(true), value_name("ENV=VAR"), value_parser = parse_key_val::<String, String>)]
env: Option<Vec<(String, String)>>,

// FS
/// Configure runtime preopen mappings
#[arg(long, value_name("preopen=hostpreopen"), value_parser = parse_key_val::<String, String>)]
preopen: Option<Vec<(String, String)>>,

/// Mount a virtual directory globbed from the local filesystem
#[arg(long, value_name("preopen=virtualdir"), value_parser = parse_key_val::<String, String>)]
mount: Option<Vec<(String, String)>>,

Expand Down
5 changes: 5 additions & 0 deletions src/virt_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,31 @@ pub enum HostEnv {
}

impl VirtEnv {
/// Set the host environment variable allow list
pub fn allow(&mut self, allow_list: &[String]) -> &mut Self {
self.host = HostEnv::Allow(allow_list.iter().map(|s| s.to_string()).collect());
self
}

/// Set the host environment variable deny list
pub fn deny(&mut self, deny_list: &[&str]) -> &mut Self {
self.host = HostEnv::Deny(deny_list.iter().map(|s| s.to_string()).collect());
self
}

/// Enable all environment variables on the host
pub fn allow_all(&mut self) -> &mut Self {
self.host = HostEnv::All;
self
}

/// Deny all environment variables on the host
pub fn deny_all(&mut self) -> &mut Self {
self.host = HostEnv::None;
self
}

/// Set the environment variable overrides
pub fn overrides(&mut self, overrides: &[(&str, &str)]) -> &mut Self {
for (key, val) in overrides {
self.overrides.push((key.to_string(), val.to_string()));
Expand Down
5 changes: 4 additions & 1 deletion src/virt_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub struct VirtFs {
pub preopens: BTreeMap<String, FsEntry>,
/// A cutoff size in bytes, above which
/// files will be treated as passive segments.
/// Per-file control may also be provided.
pub passive_cutoff: Option<usize>,
}

Expand Down Expand Up @@ -53,21 +52,25 @@ pub struct VirtFile {
type VirtDir = BTreeMap<String, FsEntry>;

impl VirtFs {
/// Add a preopen entry
pub fn preopen(&mut self, name: String, preopen: FsEntry) -> &mut Self {
self.preopens.insert(name, preopen);
self
}

/// Add a preopen host mapping
pub fn host_preopen(&mut self, name: String, dir: String) -> &mut Self {
self.preopens.insert(name, FsEntry::RuntimeDir(dir));
self
}

/// Add a preopen virtualized local directory (which will be globbed)
pub fn virtual_preopen(&mut self, name: String, dir: String) -> &mut Self {
self.preopens.insert(name, FsEntry::Virtualize(dir));
self
}

/// Set the passive cutoff size in bytes for creating Wasm passive segments
pub fn passive_cutoff(&mut self, passive_cutoff: usize) -> &mut Self {
self.passive_cutoff = Some(passive_cutoff);
self
Expand Down
12 changes: 7 additions & 5 deletions tests/virt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ use wasmtime::{
component::{Component, Linker},
Config, Engine, Store, WasmBacktraceDetails,
};
use wasmtime_wasi::preview2::{
wasi as wasi_preview2, DirPerms, FilePerms, Table, WasiCtx, WasiCtxBuilder, WasiView,
};
use wasmtime_wasi::preview2::command::add_to_linker;
use wasmtime_wasi::preview2::{DirPerms, FilePerms, Table, WasiCtx, WasiCtxBuilder, WasiView};
use wasmtime_wasi::Dir;
use wit_component::ComponentEncoder;

Expand Down Expand Up @@ -101,7 +100,10 @@ async fn virt_test() -> Result<()> {
.validate(true)
.module(&component_core)?;
encoder = encoder.adapter("wasi_snapshot_preview1", wasi_adapter.as_slice())?;
fs::write(&generated_component_path, encoder.encode()?)?;
fs::write(
&generated_component_path,
encoder.encode().with_context(|| "Encoding component")?,
)?;

// create the test case specific virtualization
let mut virt_component_path = generated_path.join(test_case_name);
Expand Down Expand Up @@ -183,7 +185,7 @@ async fn virt_test() -> Result<()> {
Ok(())
})?;

wasi_preview2::command::add_to_linker(&mut linker)?;
add_to_linker(&mut linker)?;
let mut store = Store::new(&engine, CommandCtx { table, wasi });

let (instance, _instance) =
Expand Down
62 changes: 38 additions & 24 deletions virtual-adapter/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::exports::wasi::filesystem::filesystem::{
AccessType, Advice, Datetime, DescriptorFlags, DescriptorStat, DescriptorType, DirectoryEntry,
ErrorCode, Filesystem, Modes, NewTimestamp, OpenFlags, PathFlags,
};
use crate::exports::wasi::io::streams::{StreamError, Streams};
use crate::exports::wasi::io::streams::{StreamError, StreamStatus, Streams};
use crate::wasi::cli_base::preopens;
use crate::wasi::filesystem::filesystem;
// use crate::wasi::io::streams;
Expand Down Expand Up @@ -354,15 +354,22 @@ impl FileStream {
fn new(fd: u32) -> Self {
Self { fd, offset: 0 }
}
fn read(&mut self, len: u64) -> Result<(Vec<u8>, bool), StreamError> {
fn read(&mut self, len: u64) -> Result<(Vec<u8>, StreamStatus), StreamError> {
let Some(descriptor) = FsState::get_descriptor(self.fd) else {
return Err(StreamError {});
return Err(StreamError { dummy: 0 });
};
let (bytes, done) = descriptor
.get_bytes(self.offset, len)
.map_err(|_| StreamError {})?;
.map_err(|_| StreamError { dummy: 0 })?;
self.offset += bytes.len() as u64;
Ok((bytes, done))
Ok((
bytes,
if done {
StreamStatus::Ended
} else {
StreamStatus::Open
},
))
}
}

Expand Down Expand Up @@ -530,9 +537,16 @@ impl Filesystem for VirtAdapter {
let Stream::File(filestream) = stream else {
unreachable!()
};
let result = filestream.read(len).map_err(|_| ErrorCode::Io)?;
let (bytes, status) = filestream.read(len).map_err(|_| ErrorCode::Io)?;
FsState::drop_stream(sid);
Ok(result)

Ok((
bytes,
match status {
StreamStatus::Open => false,
StreamStatus::Ended => true,
},
))
}
fn write(_: u32, _: Vec<u8>, _: u64) -> Result<u64, ErrorCode> {
Err(ErrorCode::Access)
Expand Down Expand Up @@ -698,22 +712,22 @@ impl Filesystem for VirtAdapter {
}

impl Streams for VirtAdapter {
fn read(sid: u32, len: u64) -> Result<(Vec<u8>, bool), StreamError> {
fn read(sid: u32, len: u64) -> Result<(Vec<u8>, StreamStatus), StreamError> {
VirtAdapter::blocking_read(sid, len)
}
fn blocking_read(sid: u32, len: u64) -> Result<(Vec<u8>, bool), StreamError> {
fn blocking_read(sid: u32, len: u64) -> Result<(Vec<u8>, StreamStatus), StreamError> {
let Some(stream) = FsState::get_stream(sid) else {
return Err(StreamError {});
return Err(StreamError { dummy: 0 });
};
match stream {
Stream::File(filestream) => filestream.read(len),
_ => Err(StreamError {}),
_ => Err(StreamError { dummy: 0 }),
}
}
fn skip(_: u32, _: u64) -> Result<(u64, bool), StreamError> {
fn skip(_: u32, _: u64) -> Result<(u64, StreamStatus), StreamError> {
todo!()
}
fn blocking_skip(_: u32, _: u64) -> Result<(u64, bool), StreamError> {
fn blocking_skip(_: u32, _: u64) -> Result<(u64, StreamStatus), StreamError> {
todo!()
}
fn subscribe_to_input_stream(_: u32) -> u32 {
Expand All @@ -722,25 +736,25 @@ impl Streams for VirtAdapter {
fn drop_input_stream(sid: u32) {
FsState::drop_stream(sid);
}
fn write(_: u32, _: Vec<u8>) -> Result<u64, StreamError> {
Err(StreamError {})
fn write(_: u32, _: Vec<u8>) -> Result<(u64, StreamStatus), StreamError> {
Err(StreamError { dummy: 0 })
}
fn blocking_write(_: u32, _: Vec<u8>) -> Result<u64, StreamError> {
Err(StreamError {})
fn blocking_write(_: u32, _: Vec<u8>) -> Result<(u64, StreamStatus), StreamError> {
Err(StreamError { dummy: 0 })
}
fn write_zeroes(_: u32, _: u64) -> Result<u64, StreamError> {
Err(StreamError {})
fn write_zeroes(_: u32, _: u64) -> Result<(u64, StreamStatus), StreamError> {
Err(StreamError { dummy: 0 })
}
fn blocking_write_zeroes(_: u32, _: u64) -> Result<u64, StreamError> {
Err(StreamError {})
fn blocking_write_zeroes(_: u32, _: u64) -> Result<(u64, StreamStatus), StreamError> {
Err(StreamError { dummy: 0 })
}
fn splice(_: u32, _: u32, _: u64) -> Result<(u64, bool), StreamError> {
fn splice(_: u32, _: u32, _: u64) -> Result<(u64, StreamStatus), StreamError> {
todo!()
}
fn blocking_splice(_: u32, _: u32, _: u64) -> Result<(u64, bool), StreamError> {
fn blocking_splice(_: u32, _: u32, _: u64) -> Result<(u64, StreamStatus), StreamError> {
todo!()
}
fn forward(_: u32, _: u32) -> Result<u64, StreamError> {
fn forward(_: u32, _: u32) -> Result<(u64, StreamStatus), StreamError> {
todo!()
}
fn subscribe_to_output_stream(_: u32) -> u32 {
Expand Down
Loading

0 comments on commit e20916d

Please sign in to comment.