vfs-host
Host trait implementation that enables multiple WASM applications to share a single in memory filesystem at runtime.
Overview
vfs-host implements WASI filesystem Host traits using fs-core directly. Multiple applications can concurrently access and modify the same VFS instance through Arc<Fs>. Thread safety is handled internally by fs-core via DashMap, so no external locking is required.
Features
- Shared VFS state across multiple applications via
Arc<Fs> - Thread safe without external locks
- VFS state persists as long as any application holds a reference
- Full WASI Preview 2 filesystem trait implementation
- Stream API support (
read_via_stream,write_via_stream,append_via_stream) - Optional S3 synchronization via the
s3-syncfeature
Usage
Basic
use VfsHostState;
use ;
// Create engine with component model support
let mut config = new;
config.wasm_component_model;
let engine = new?;
// Create VFS host (uses fs-core directly, no WASM adapter needed)
let vfs_host = new?;
// Create application store
let mut store = new;
Sharing VFS across multiple applications
use VfsHostState;
use ;
// Create shared VFS host
let vfs_host = new?;
// Create multiple application contexts sharing the same VFS
let vfs_host2 = vfs_host.clone_shared;
let vfs_host3 = vfs_host.clone_shared;
// Create stores for each application
let mut store1 = new;
let mut store2 = new;
let mut store3 = new;
// All three stores share the same VFS instance
State Persistence Example
use VfsHostState;
let vfs_host = new?;
let vfs_host2 = vfs_host.clone_shared;
// App2 starts AFTER App1 terminated
let mut store2 = new;
// App2 can still access files created by App1
// VFS state persisted because vfs_host2 still held a reference
Architecture
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Application1 │ │ Application2 │ │ Application3 │
└──────┬───────┘ └──────┬───────┘ └──────┬───────┘
│ │ │
│ VfsHostState (clone_shared()) │
└───────────────────┼───────────────────┘
│
Arc<Fs>
│
┌───────┴───────┐
│ fs-core │
│ (In Memory) │
└───────────────┘
S3 Sync
Enable the s3-sync feature to synchronize the in memory filesystem with S3.
let vfs_host = new_with_s3.await?;
Example
See examples/host-trait/runtime-linker for a complete working example.
License
MIT