Skip to content

Commit

Permalink
deps: toolchain upgrade (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored Aug 28, 2023
1 parent 0d7f879 commit 8f14f24
Show file tree
Hide file tree
Showing 35 changed files with 932 additions and 871 deletions.
677 changes: 281 additions & 396 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,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" }
wasm-metadata = { git = "https://github.com/bytecodealliance/wasm-tools" }
wasm-opt = "0.113.0"
wit-component = { git = "https://github.com/bytecodealliance/wasm-tools" }
wasm-compose = "0.4.2"
wasm-metadata = "0.10.3"
wasm-opt = "0.114.1"
wit-component = "0.14.0"

[build-dependencies]
anyhow = "1"
Expand All @@ -47,8 +47,8 @@ cap-std = "1.0.12"
heck = { version = "0.4" }
tokio = { version = "1.30.0", features = ["macros"] }
wasmtime = { git = "https://github.com/bytecodealliance/wasmtime", features = ["component-model"] }
wasmtime-wasi = { git = "https://github.com/bytecodealliance/wasmtime" }
wasmtime-wasi = { git = "https://github.com/bytecodealliance/wasmtime" }

[workspace.dependencies]
anyhow = "1"
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen" }
Binary file modified lib/virtual_adapter.wasm
Binary file not shown.
Binary file modified lib/wasi_snapshot_preview1.reactor.wasm
Binary file not shown.
23 changes: 9 additions & 14 deletions src/virt_deny.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,7 @@ pub(crate) fn deny_http_virt(module: &mut Module) -> Result<()> {
)?;
add_stub_exported_func(
module,
"wasi:http/types#incoming-request-path",
vec![ValType::I32],
vec![ValType::I32],
)?;
add_stub_exported_func(
module,
"wasi:http/types#incoming-request-query",
"wasi:http/types#incoming-request-path-with-query",
vec![ValType::I32],
vec![ValType::I32],
)?;
Expand Down Expand Up @@ -255,7 +249,13 @@ pub(crate) fn deny_http_virt(module: &mut Module) -> Result<()> {
add_stub_exported_func(
module,
"wasi:http/types#set-response-outparam",
vec![ValType::I32, ValType::I32, ValType::I32, ValType::I32],
vec![
ValType::I32,
ValType::I32,
ValType::I32,
ValType::I32,
ValType::I32,
],
vec![ValType::I32],
)?;
add_stub_exported_func(
Expand Down Expand Up @@ -368,12 +368,7 @@ pub(crate) fn deny_random_virt(module: &mut Module) -> Result<()> {
}

pub(crate) fn deny_exit_virt(module: &mut Module) -> Result<()> {
add_stub_exported_func(
module,
"wasi:cli-base/exit#exit",
vec![ValType::I32],
vec![],
)?;
add_stub_exported_func(module, "wasi:cli/exit#exit", vec![ValType::I32], vec![])?;
Ok(())
}

Expand Down
10 changes: 6 additions & 4 deletions src/virt_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,16 @@ pub(crate) fn create_env_virt<'a>(module: &'a mut Module, env: &VirtEnv) -> Resu
}

pub(crate) fn stub_env_virt(module: &mut Module) -> Result<()> {
stub_imported_func(module, "wasi:cli-base/environment", "get-arguments", true)?;
stub_imported_func(module, "wasi:cli-base/environment", "get-environment", true)?;
stub_imported_func(module, "wasi:cli/environment", "get-arguments", true)?;
stub_imported_func(module, "wasi:cli/environment", "get-environment", true)?;
stub_imported_func(module, "wasi:cli/environment", "initial-cwd", true)?;
Ok(())
}

pub(crate) fn strip_env_virt(module: &mut Module) -> Result<()> {
stub_env_virt(module)?;
remove_exported_func(module, "wasi:cli-base/environment#get-arguments")?;
remove_exported_func(module, "wasi:cli-base/environment#get-environment")?;
remove_exported_func(module, "wasi:cli/environment#get-arguments")?;
remove_exported_func(module, "wasi:cli/environment#get-environment")?;
remove_exported_func(module, "wasi:cli/environment#initial-cwd")?;
Ok(())
}
138 changes: 98 additions & 40 deletions src/virt_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,30 +248,55 @@ impl FsEntry {
Ok(())
}

pub fn visit_pre<'a, Visitor>(&'a self, base_path: &str, visit: &mut Visitor) -> Result<()>
pub fn visit_bfs<'a, Visitor>(&'a self, base_path: &str, visit: &mut Visitor) -> Result<()>
where
Visitor: FnMut(&FsEntry, &str, &str, usize) -> Result<()>,
{
visit(self, base_path, "", 0)?;
self.visit_pre_inner(visit, base_path)
visit(self, base_path, "", 1)?;
let mut children_of = vec![(base_path.to_string(), self)];
let mut next_children_of;
while children_of.len() > 0 {
next_children_of = Vec::new();
FsEntry::visit_bfs_level(children_of, visit, &mut next_children_of)?;
children_of = next_children_of;
}
Ok(())
}

fn visit_pre_inner<'a, Visitor>(&'a self, visit: &mut Visitor, base_path: &str) -> Result<()>
fn visit_bfs_level<'a, Visitor>(
children_of: Vec<(String, &'a FsEntry)>,
visit: &mut Visitor,
next_children_of: &mut Vec<(String, &'a FsEntry)>,
) -> Result<()>
where
Visitor: FnMut(&FsEntry, &str, &str, usize) -> Result<()>,
{
match self {
FsEntry::Dir(dir) => {
let len = dir.iter().len();
for (idx, (name, sub_entry)) in dir.iter().enumerate() {
visit(sub_entry, name, base_path, len - idx - 1)?;
// first we do a full len count at this depth to be able to predict the
// next depth offset position for children of this item from the current index
let mut child_offset = 0;
for (_, parent) in &children_of {
match parent {
FsEntry::Dir(dir) => {
child_offset += dir.iter().len();
}
for (name, sub_entry) in dir {
let path = format!("{base_path}/{name}");
sub_entry.visit_pre_inner(visit, &path)?;
_ => {}
}
}
for (base_path, parent) in children_of {
match parent {
FsEntry::Dir(dir) => {
for (name, sub_entry) in dir.iter() {
visit(sub_entry, name, &base_path, child_offset)?;
child_offset -= 1;
let path = format!("{base_path}/{name}");
next_children_of.push((path, sub_entry));
if let FsEntry::Dir(dir) = sub_entry {
child_offset += dir.iter().len();
}
}
}
_ => {}
}
_ => {}
}
Ok(())
}
Expand Down Expand Up @@ -386,7 +411,8 @@ pub(crate) fn create_io_virt<'a>(
if let Some(fs) = &fs {
for (name, entry) in &fs.preopens {
preopen_indices.push(static_fs_data.len() as u32);
entry.visit_pre(name, &mut |entry, name, _path, remaining_siblings| {
let mut cur_idx = 0;
entry.visit_bfs(name, &mut |entry, name, _path, child_offset| {
let name_str_ptr = data_section.string(name)?;
let (ty, data) = match &entry {
// removed during previous step
Expand All @@ -408,20 +434,12 @@ pub(crate) fn create_io_virt<'a>(
StaticFileData { host_path: str },
)
}
FsEntry::Dir(dir) => {
let child_cnt = dir.len() as u32;
// children will be visited next in preorder and contiguously
// therefore the child index in the static fs data is known
// to be the next index
let start_idx = static_fs_data.len() as u32 + 1;
let child_idx = start_idx + remaining_siblings as u32;
(
StaticIndexType::Dir,
StaticFileData {
dir: (child_idx, child_cnt),
},
)
}
FsEntry::Dir(dir) => (
StaticIndexType::Dir,
StaticFileData {
dir: (child_offset as u32, dir.len() as u32),
},
),
FsEntry::File(bytes) => {
let byte_len = bytes.len();
if byte_len > fs.passive_cutoff.unwrap_or(1024) as usize {
Expand All @@ -448,6 +466,7 @@ pub(crate) fn create_io_virt<'a>(
ty,
data,
});
cur_idx += 1;
Ok(())
})?;
}
Expand Down Expand Up @@ -525,9 +544,10 @@ pub(crate) fn create_io_virt<'a>(
Ok(virtual_files)
}

// stubs must be _comprehensive_ in order to act as full deny over entire subsystem
// Stubs must be _comprehensive_ in order to act as full deny over entire subsystem
// when stubbing functions that are not part of the virtual adapter exports, we therefore
// have to create this functions fresh
// have to create this functions fresh.
// Ideally, we should generate these stubs automatically from WASI definitions.
pub(crate) fn stub_fs_virt(module: &mut Module) -> Result<()> {
stub_imported_func(module, "wasi:filesystem/preopens", "get-directories", true)?;
stub_imported_func(module, "wasi:filesystem/types", "read-via-stream", true)?;
Expand Down Expand Up @@ -635,9 +655,39 @@ pub(crate) fn stub_clocks_virt(module: &mut Module) -> Result<()> {
}

pub(crate) fn stub_stdio_virt(module: &mut Module) -> Result<()> {
stub_imported_func(module, "wasi:cli-base/stdin", "get-stdin", true)?;
stub_imported_func(module, "wasi:cli-base/stdout", "get-stdout", true)?;
stub_imported_func(module, "wasi:cli-base/stderr", "get-stderr", true)?;
stub_imported_func(module, "wasi:cli/stdin", "get-stdin", true)?;
stub_imported_func(module, "wasi:cli/stdout", "get-stdout", true)?;
stub_imported_func(module, "wasi:cli/stderr", "get-stderr", true)?;
stub_imported_func(
module,
"wasi:cli/terminal-stdin",
"get-terminal-stdin",
false,
)?;
stub_imported_func(
module,
"wasi:cli/terminal-stdout",
"get-terminal-stdout",
false,
)?;
stub_imported_func(
module,
"wasi:cli/terminal-stderr",
"get-terminal-stderr",
false,
)?;
stub_imported_func(
module,
"wasi:cli/terminal-input",
"drop-terminal-input",
false,
)?;
stub_imported_func(
module,
"wasi:cli/terminal-output",
"drop-terminal-output",
false,
)?;
Ok(())
}

Expand Down Expand Up @@ -780,8 +830,7 @@ pub(crate) fn strip_http_virt(module: &mut Module) -> Result<()> {
remove_exported_func(module, "wasi:http/types#drop-incoming-request")?;
remove_exported_func(module, "wasi:http/types#drop-outgoing-request")?;
remove_exported_func(module, "wasi:http/types#incoming-request-method")?;
remove_exported_func(module, "wasi:http/types#incoming-request-path")?;
remove_exported_func(module, "wasi:http/types#incoming-request-query")?;
remove_exported_func(module, "wasi:http/types#incoming-request-path-with-query")?;
remove_exported_func(module, "wasi:http/types#incoming-request-scheme")?;
remove_exported_func(module, "wasi:http/types#incoming-request-authority")?;
remove_exported_func(module, "wasi:http/types#incoming-request-headers")?;
Expand Down Expand Up @@ -817,8 +866,12 @@ pub(crate) fn stub_http_virt(module: &mut Module) -> Result<()> {
stub_imported_func(module, "wasi:http/types", "drop-incoming-request", false)?;
stub_imported_func(module, "wasi:http/types", "drop-outgoing-request", false)?;
stub_imported_func(module, "wasi:http/types", "incoming-request-method", false)?;
stub_imported_func(module, "wasi:http/types", "incoming-request-path", false)?;
stub_imported_func(module, "wasi:http/types", "incoming-request-query", false)?;
stub_imported_func(
module,
"wasi:http/types",
"incoming-request-path-with-query",
false,
)?;
stub_imported_func(module, "wasi:http/types", "incoming-request-scheme", false)?;
stub_imported_func(
module,
Expand Down Expand Up @@ -872,9 +925,14 @@ pub(crate) fn stub_http_virt(module: &mut Module) -> Result<()> {

pub(crate) fn strip_stdio_virt(module: &mut Module) -> Result<()> {
stub_stdio_virt(module)?;
remove_exported_func(module, "wasi:cli-base/stdin#get-stdin")?;
remove_exported_func(module, "wasi:cli-base/stdout#get-stdout")?;
remove_exported_func(module, "wasi:cli-base/stderr#get-stderr")?;
remove_exported_func(module, "wasi:cli/stdin#get-stdin")?;
remove_exported_func(module, "wasi:cli/stdout#get-stdout")?;
remove_exported_func(module, "wasi:cli/stderr#get-stderr")?;
remove_exported_func(module, "wasi:cli/terminal-stdin#get-terminal-stdin")?;
remove_exported_func(module, "wasi:cli/terminal-stdout#get-terminal-stdout")?;
remove_exported_func(module, "wasi:cli/terminal-stderr#get-terminal-stderr")?;
remove_exported_func(module, "wasi:cli/terminal-input#drop-terminal-input")?;
remove_exported_func(module, "wasi:cli/terminal-output#drop-terminal-output")?;
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion tests/components/do-everything/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ wit_bindgen::generate!({

struct VirtTestComponent;

impl VirtTest for VirtTestComponent {
impl Guest for VirtTestComponent {
fn test_get_env() -> Vec<(String, String)> {
unreachable!();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/components/file-read/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ wit_bindgen::generate!({

struct VirtTestComponent;

impl VirtTest for VirtTestComponent {
impl Guest for VirtTestComponent {
fn test_get_env() -> Vec<(String, String)> {
Vec::new()
}
Expand Down
2 changes: 1 addition & 1 deletion tests/components/get-env/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ wit_bindgen::generate!({

struct VirtTestComponent;

impl VirtTest for VirtTestComponent {
impl Guest for VirtTestComponent {
fn test_get_env() -> Vec<(String, String)> {
env::vars().collect()
}
Expand Down
Loading

0 comments on commit 8f14f24

Please sign in to comment.