diff --git a/Cargo.lock b/Cargo.lock index 36caa1e0aa..b2a87ecbfe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1121,10 +1121,6 @@ dependencies = [ name = "example-fib-debug-wasm" version = "0.0.0" -[[package]] -name = "example-wasi-fs-wasm" -version = "0.0.0" - [[package]] name = "example-wasi-wasm" version = "0.0.0" @@ -3128,15 +3124,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "wasi-virtfs" -version = "0.22.0" -dependencies = [ - "anyhow", - "cap-std", - "wasi-common", -] - [[package]] name = "wasm-encoder" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index 6527021f39..4321fda023 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -77,10 +77,8 @@ members = [ "crates/wiggle/wasmtime", "crates/wasi-common", "crates/wasi-common/cap-std-sync", - "crates/wasi-common/virtfs", "examples/fib-debug/wasm", "examples/wasi/wasm", - "examples/wasi-fs/wasm", "fuzz", ] diff --git a/crates/wasi-common/virtfs/Cargo.toml b/crates/wasi-common/virtfs/Cargo.toml deleted file mode 100644 index 4a760434a6..0000000000 --- a/crates/wasi-common/virtfs/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "wasi-virtfs" -version = "0.22.0" -authors = ["The Wasmtime Project Developers"] -description = "WASI implementation in Rust" -license = "Apache-2.0 WITH LLVM-exception" -categories = ["wasm"] -keywords = ["webassembly", "wasm"] -repository = "https://github.com/bytecodealliance/wasmtime" -readme = "README.md" -edition = "2018" -include = ["src/**/*", "LICENSE" ] -publish = false - -[dependencies] -wasi-common = { path = "../", version = "0.22.0" } -anyhow = "1.0" -cap-std = "0.12" diff --git a/crates/wasi-common/virtfs/src/dir.rs b/crates/wasi-common/virtfs/src/dir.rs deleted file mode 100644 index 45396e7de9..0000000000 --- a/crates/wasi-common/virtfs/src/dir.rs +++ /dev/null @@ -1,82 +0,0 @@ -use crate::file::File; -use std::any::Any; -use std::path::{Path, PathBuf}; -use wasi_common::{ - dir::{ReaddirCursor, ReaddirEntity, WasiDir}, - file::{FdFlags, FileCaps, FileType, Filestat, OFlags, WasiFile}, - Error, ErrorExt, -}; - -pub struct Dir; - -impl Dir {} - -impl WasiDir for Dir { - fn as_any(&self) -> &dyn Any { - self - } - fn open_file( - &self, - symlink_follow: bool, - path: &str, - oflags: OFlags, - caps: FileCaps, - fdflags: FdFlags, - ) -> Result, Error> { - todo!() - } - - fn open_dir(&self, symlink_follow: bool, path: &str) -> Result, Error> { - todo!() - } - - fn create_dir(&self, path: &str) -> Result<(), Error> { - todo!() - } - fn readdir( - &self, - cursor: ReaddirCursor, - ) -> Result>>, Error> { - todo!() - } - - fn symlink(&self, src_path: &str, dest_path: &str) -> Result<(), Error> { - todo!() - } - fn remove_dir(&self, path: &str) -> Result<(), Error> { - todo!() - } - - fn unlink_file(&self, path: &str) -> Result<(), Error> { - todo!() - } - fn read_link(&self, path: &str) -> Result { - todo!() - } - fn get_filestat(&self) -> Result { - todo!() - } - fn get_path_filestat(&self, path: &str, follow_symlinks: bool) -> Result { - todo!() - } - fn rename(&self, src_path: &str, dest_dir: &dyn WasiDir, dest_path: &str) -> Result<(), Error> { - todo!() - } - fn hard_link( - &self, - src_path: &str, - target_dir: &dyn WasiDir, - target_path: &str, - ) -> Result<(), Error> { - todo!() - } - fn set_times( - &self, - path: &str, - atime: Option, - mtime: Option, - follow_symlinks: bool, - ) -> Result<(), Error> { - todo!() - } -} diff --git a/crates/wasi-common/virtfs/src/file.rs b/crates/wasi-common/virtfs/src/file.rs deleted file mode 100644 index 1e3e775284..0000000000 --- a/crates/wasi-common/virtfs/src/file.rs +++ /dev/null @@ -1,73 +0,0 @@ -use cap_std::Advice; -use std::any::Any; -use std::convert::TryInto; -use std::io; -use wasi_common::{ - file::{FdFlags, FileType, Filestat, WasiFile}, - Error, -}; - -pub struct File; - -impl File {} - -impl WasiFile for File { - fn as_any(&self) -> &dyn Any { - self - } - fn datasync(&self) -> Result<(), Error> { - Ok(()) - } - fn sync(&self) -> Result<(), Error> { - Ok(()) - } - fn get_filetype(&self) -> Result { - todo!() - } - fn get_fdflags(&self) -> Result { - todo!() - } - fn set_fdflags(&mut self, fdflags: FdFlags) -> Result<(), Error> { - todo!() - } - fn get_filestat(&self) -> Result { - todo!() - } - fn set_filestat_size(&self, size: u64) -> Result<(), Error> { - todo!() - } - fn advise(&self, _offset: u64, _len: u64, _advice: Advice) -> Result<(), Error> { - Ok(()) - } - fn allocate(&self, offset: u64, len: u64) -> Result<(), Error> { - todo!() - } - fn set_times( - &self, - atime: Option, - mtime: Option, - ) -> Result<(), Error> { - todo!() - } - fn read_vectored(&self, bufs: &mut [io::IoSliceMut]) -> Result { - todo!() - } - fn read_vectored_at(&self, bufs: &mut [io::IoSliceMut], offset: u64) -> Result { - todo!() - } - fn write_vectored(&self, bufs: &[io::IoSlice]) -> Result { - todo!() - } - fn write_vectored_at(&self, bufs: &[io::IoSlice], offset: u64) -> Result { - todo!() - } - fn seek(&self, pos: std::io::SeekFrom) -> Result { - todo!() - } - fn peek(&self, buf: &mut [u8]) -> Result { - todo!() - } - fn num_ready_bytes(&self) -> Result { - todo!() - } -} diff --git a/crates/wasi-common/virtfs/src/lib.rs b/crates/wasi-common/virtfs/src/lib.rs deleted file mode 100644 index f8abfac3c4..0000000000 --- a/crates/wasi-common/virtfs/src/lib.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod file; -pub mod dir; diff --git a/docs/examples-rust-wasi-fs.md b/docs/examples-rust-wasi-fs.md deleted file mode 100644 index c3b4f0857d..0000000000 --- a/docs/examples-rust-wasi-fs.md +++ /dev/null @@ -1,21 +0,0 @@ -# WASI - -You can also [browse this source code online][code] and clone the wasmtime -repository to run the example locally. - -[code]: https://github.com/bytecodealliance/wasmtime/blob/main/examples/wasi/main.rs - -This example shows off how to run a wasi binary with a memory filesystem. - -## Wasm Source code - -```rust,ignore -{{#include ../examples/wasi-fs/wasm/wasi-fs.rs}} -``` - - -## `wasi-fs.rs` - -```rust,ignore -{{#include ../examples/wasi-fs/main.rs}} -``` diff --git a/examples/wasi-fs/main.c b/examples/wasi-fs/main.c deleted file mode 100644 index 8633bfbd6c..0000000000 --- a/examples/wasi-fs/main.c +++ /dev/null @@ -1,122 +0,0 @@ -/* -Example of instantiating a WebAssembly which uses WASI imports. - -You can compile and run this example on Linux with: - - cargo build --release -p wasmtime-c-api - cc examples/wasi-fs/main.c \ - -I crates/c-api/include \ - -I crates/c-api/wasm-c-api/include \ - target/release/libwasmtime.a \ - -lpthread -ldl -lm \ - -o wasi-fs - ./wasi-fs - -Note that on Windows and macOS the command will be similar, but you'll need -to tweak the `-lpthread` and such annotations. -*/ - -#include -#include -#include -#include -#include -#include - -#define MIN(a, b) ((a) < (b) ? (a) : (b)) - -static void exit_with_error(const char *message, wasmtime_error_t *error, wasm_trap_t *trap); - -int main() { - int ret = 0; - // Set up our context - wasm_engine_t *engine = wasm_engine_new(); - assert(engine != NULL); - wasm_store_t *store = wasm_store_new(engine); - assert(store != NULL); - - wasm_byte_vec_t wasm; - // Load our input file to parse it next - FILE* file = fopen("target/wasm32-wasi/debug/wasi-fs.wasm", "rb"); - if (!file) { - printf("> Error loading file!\n"); - exit(1); - } - fseek(file, 0L, SEEK_END); - size_t file_size = ftell(file); - wasm_byte_vec_new_uninitialized(&wasm, file_size); - fseek(file, 0L, SEEK_SET); - if (fread(wasm.data, file_size, 1, file) != 1) { - printf("> Error loading module!\n"); - exit(1); - } - fclose(file); - - // Compile our modules - wasm_module_t *module = NULL; - wasmtime_error_t *error = wasmtime_module_new(engine, &wasm, &module); - if (!module) - exit_with_error("failed to compile module", error, NULL); - wasm_byte_vec_delete(&wasm); - - // Instantiate wasi - wasi_config_t *wasi_config = wasi_config_new(); - assert(wasi_config); - wasi_config_inherit_argv(wasi_config); - wasi_config_inherit_env(wasi_config); - wasi_config_inherit_stdin(wasi_config); - wasi_config_inherit_stdout(wasi_config); - wasi_config_inherit_stderr(wasi_config); - wasi_config_preopen_dir(wasi_config, "examples/wasi-fs", "."); - wasm_trap_t *trap = NULL; - wasi_instance_t *wasi = wasi_instance_new(store, "wasi_snapshot_preview1", wasi_config, &trap); - if (wasi == NULL) - exit_with_error("failed to instantiate WASI", NULL, trap); - - wasmtime_linker_t *linker = wasmtime_linker_new(store); - error = wasmtime_linker_define_wasi(linker, wasi); - if (error != NULL) - exit_with_error("failed to link wasi", error, NULL); - - // Instantiate the module - wasm_name_t empty; - wasm_name_new_from_string(&empty, ""); - wasm_instance_t *instance = NULL; - error = wasmtime_linker_module(linker, &empty, module); - if (error != NULL) - exit_with_error("failed to instantiate module", error, NULL); - - // Run it. - wasm_func_t* func; - wasmtime_linker_get_default(linker, &empty, &func); - if (error != NULL) - exit_with_error("failed to locate default export for module", error, NULL); - - wasm_val_vec_t args_vec = WASM_EMPTY_VEC; - wasm_val_vec_t results_vec = WASM_EMPTY_VEC; - error = wasmtime_func_call(func, &args_vec, &results_vec, &trap); - if (error != NULL) - exit_with_error("error calling default export", error, trap); - - // Clean up after ourselves at this point - wasm_name_delete(&empty); - wasm_module_delete(module); - wasm_store_delete(store); - wasm_engine_delete(engine); - return 0; -} - -static void exit_with_error(const char *message, wasmtime_error_t *error, wasm_trap_t *trap) { - fprintf(stderr, "error: %s\n", message); - wasm_byte_vec_t error_message; - if (error != NULL) { - wasmtime_error_message(error, &error_message); - wasmtime_error_delete(error); - } else { - wasm_trap_message(trap, &error_message); - wasm_trap_delete(trap); - } - fprintf(stderr, "%.*s\n", (int) error_message.size, error_message.data); - wasm_byte_vec_delete(&error_message); - exit(1); -} diff --git a/examples/wasi-fs/main.rs b/examples/wasi-fs/main.rs deleted file mode 100644 index 111ce1521e..0000000000 --- a/examples/wasi-fs/main.rs +++ /dev/null @@ -1,46 +0,0 @@ -//! Example of running a wasi binary in a memory filesystem - -// The corresponding wasm binary can be built with: -// `cargo build -p example-wasi-fs-wasm --target wasm32-wasi` -// -// then you can execute this example with `cargo run --example wasi-fs` - -use anyhow::Result; -use std::collections::HashMap; -use wasmtime::*; -use wasmtime_wasi::virtfs::{VecFileContents, VirtualDirEntry}; -use wasmtime_wasi::{Wasi, WasiCtxBuilder}; - -fn main() -> Result<()> { - tracing_subscriber::FmtSubscriber::builder() - .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) - .with_ansi(true) - .init(); - - let store = Store::default(); - let mut linker = Linker::new(&store); - - // Create an instance of `Wasi` which contains a `WasiCtx`. Note that - // `WasiCtx` provides a number of ways to configure what the target program - // will have access to. - let entry = VirtualDirEntry::File(Box::new(VecFileContents::with_content( - "world".as_bytes().to_owned(), - ))); - let mut map = HashMap::new(); - map.insert("test.txt".to_string(), entry); - let dir = VirtualDirEntry::Directory(map); - let ctx = WasiCtxBuilder::new() - .inherit_stdout() - .inherit_stderr() - .preopened_virt(dir, ".") - .build()?; - let wasi = Wasi::new(&store, ctx); - wasi.add_to_linker(&mut linker)?; - - // Instantiate our module with the imports we've created, and run it. - let module = Module::from_file(store.engine(), "target/wasm32-wasi/debug/wasi-fs.wasm")?; - linker.module("", &module)?; - linker.get_default("")?.get0::<()>()?()?; - - Ok(()) -} diff --git a/examples/wasi-fs/test.txt b/examples/wasi-fs/test.txt deleted file mode 100644 index 04fea06420..0000000000 --- a/examples/wasi-fs/test.txt +++ /dev/null @@ -1 +0,0 @@ -world \ No newline at end of file diff --git a/examples/wasi-fs/wasm/Cargo.toml b/examples/wasi-fs/wasm/Cargo.toml deleted file mode 100644 index 4bf1a06c63..0000000000 --- a/examples/wasi-fs/wasm/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "example-wasi-fs-wasm" -version = "0.0.0" -authors = ["The Wasmtime Project Developers"] -edition = "2018" -publish = false - -[[bin]] -path = "wasi-fs.rs" -name = "wasi-fs" diff --git a/examples/wasi-fs/wasm/wasi-fs.rs b/examples/wasi-fs/wasm/wasi-fs.rs deleted file mode 100644 index 218cfeb72c..0000000000 --- a/examples/wasi-fs/wasm/wasi-fs.rs +++ /dev/null @@ -1,4 +0,0 @@ -fn main() { - let contents = std::fs::read_to_string("test.txt").unwrap(); - println!("Hello, {}!", contents); -}