• Stars
    star
    148
  • Rank 249,983 (Top 5 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created almost 3 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A virtual filesystem layer for WASI.

wasi-vfs

Crates.io

A virtual filesystem layer for WASI.

NOTICE: This project currently supports only WASI applications on the top of wasi-libc

This project provides a language and host-agnostic virtual filesystem layer for WASI.

Supported filesystems

  • Embedded file system: a read only file system embedded in the .wasm binary.
  • to be implemented more...

Installation

Binary

A typical installation from the release binaries might look like the following:

$ export WASI_VFS_VERSION=0.4.0

# For x86_64 Linux host machine
$ curl -LO "https://github.com/kateinoigakukun/wasi-vfs/releases/download/v${WASI_VFS_VERSION}/wasi-vfs-cli-x86_64-unknown-linux-gnu.zip"
$ unzip wasi-vfs-cli-x86_64-unknown-linux-gnu.zip

# For x86_64 macOS host machine
$ curl -LO "https://github.com/kateinoigakukun/wasi-vfs/releases/download/v${WASI_VFS_VERSION}/wasi-vfs-cli-x86_64-apple-darwin.zip"
$ unzip wasi-vfs-cli-x86_64-apple-darwin.zip

# For arm64 macOS host machine
$ curl -LO "https://github.com/kateinoigakukun/wasi-vfs/releases/download/v${WASI_VFS_VERSION}/wasi-vfs-cli-aarch64-apple-darwin.zip"
$ unzip wasi-vfs-cli-aarch64-apple-darwin.zip

# See release page for more platforms: https://github.com/kateinoigakukun/wasi-vfs/releases

$ mv wasi-vfs /usr/local/bin/wasi-vfs

Homebrew

$ brew tap kateinoigakukun/wasi-vfs https://github.com/kateinoigakukun/wasi-vfs.git
$ brew install kateinoigakukun/wasi-vfs/wasi-vfs

Building

To build the project, you need to install the wasi-sdk version 16.0 or later.

$ git clone https://github.com/kateinoigakukun/wasi-vfs.git --recurse-submodules
$ cd wasi-vfs
$ export WASI_VERSION=20
$ export WASI_VERSION_FULL=${WASI_VERSION}.0

# For x86_64 Linux host machine
$ curl -LO https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_VERSION}/wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz
$ tar xvf wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz

# For x86_64 and arm64 macOS host machine (since wasi-sdk doesn't provide prebuilt binaries for M1, so use x64 binaries on Rosetta)
$ curl -LO https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_VERSION}/wasi-sdk-${WASI_VERSION_FULL}-macos.tar.gz
$ tar xvf wasi-sdk-${WASI_VERSION_FULL}-macos.tar.gz

$ export WASI_SDK_PATH=$PWD/wasi-sdk-${WASI_VERSION_FULL}
$ cargo build --target wasm32-unknown-unknown

Demo

Prerequisites

Set $WASI_SDK_PATH environment variable to the path of the wasi-sdk (version 14 or later).

Build and run WASI application

$ git clone https://github.com/kateinoigakukun/wasi-vfs.git --recurse-submodules
$ cd wasi-vfs

# Build libwasi_vfs.a
$ cargo build --target wasm32-unknown-unknown

# Build a WASI app with libwasi_vfs.a
$ $WASI_SDK_PATH/bin/clang -target wasm32-unknown-wasi -o getline.wasm examples/getline.c ./target/wasm32-unknown-unknown/debug/libwasi_vfs.a

# Run the WASI app with --mapdir
$ wasmtime run --mapdir /::./examples/mnt getline.wasm -- /hello.txt
Hello

# Pack ./examples/mnt directory into a WASM binary
$ cargo run -p wasi-vfs-cli -- pack getline.wasm --mapdir /::./examples/mnt -o getline.packed.wasm

# Run the WASM binary again without --mapdir
$ wasmtime run getline.packed.wasm -- /hello.txt
Hello

Testing

Unit tests

$ CARGO_TARGET_WASM32_WASI_RUNNER=wasmtime cargo test --target wasm32-wasi

End-to-end tests

$ cargo build --target wasm32-unknown-unknown
$ LIB_WASI_VFS_A=$PWD/target/wasm32-unknown-unknown/debug/libwasi_vfs.a ./tools/run-make-test.sh

How does it work?

wasi-vfs pack command is a wrapper of wizer, which is a pre-initializer for Wasm applications. The initialization process scans the mapped directories, then copies them into in-memory virtual filesystem.

Limitations

Currently, this project only supports WASI applications on the top of wasi-libc because of the following reasons:

This project depends on wasm-ld and wasi-libc's imported symbol behavior. wasi-libc declares some external symbols to import WASI functions in C like below. When __imported_wasi_snapshot_preview1_fd_read is not defined in any input object files, wasm-ld produces a (import "wasi_snapshot_preview1" "fd_read") entry. This is how wasi-libc calls WASI functions.

int32_t __imported_wasi_snapshot_preview1_fd_read(int32_t arg0, int32_t arg1, int32_t arg2, int32_t arg3) __attribute__((
    __import_module__("wasi_snapshot_preview1"),
    __import_name__("fd_read")
));

This project exploits that external symbols to hook WASI function calls by defining them in libwasi_vfs.a. If those symbols are defined, wasm-ld doesn't produce import entries, and it links symbols normally.

Therefore, this project currently doesn't support Rust application, which calls WASI functions directly without using wasi-libc.

After module-linking and interface-types will be merged, and WASI will adopt shared-nothing architecture, this project will be able to support all WASI applications.

More Repositories

1

StubKit

A smart stubbing system.
Swift
292
star
2

TouchTypist

Reduce up your build time. A tool that rewrites your source code as type annotated.
Swift
115
star
3

wasminspect

An interactive debugger for WebAssembly
Rust
100
star
4

irb.wasm

IRB on browser powered by WebAssembly
TypeScript
77
star
5

swiftwasm-game-of-life

Demo project of Swift on Web App
Swift
72
star
6

wasmic-ios

Wasmic allows you to run WebAssembly in a safe way on iOS.
Swift
66
star
7

swift-indexstore

SwiftIndexStore is a IndexStore reader library for Swift.
Swift
49
star
8

mull-xctest

Experimental mutation testing tool for Swift and XCTest powered by mull
C++
44
star
9

swift-playdate

Swift
32
star
10

AnyEquatable

Swift
23
star
11

ruby-compute-runtime

C
18
star
12

swift-renamer

SwiftRenamer is a tool that renames Swift identifiers
Swift
17
star
13

MergeableLibraryInternals

Internals of Mach-O Mergeable Library
16
star
14

chibi-link

A toy linker for WebAssembly object files.
Swift
15
star
15

swift-fastly-edge-example

PoC of Swift for Compute@Edge
Swift
12
star
16

BlurEditor

This provides image editor for drawing blur effects.
Swift
11
star
17

swift-concurrency-playground

C++
9
star
18

DispatchBenchmark

Swift
9
star
19

AnnictAPI

[Deprecated] Use GraphQL API
Swift
8
star
20

wasi-preset-args

A tool to preset command-line arguments to a WASI module
Rust
8
star
21

llvm-next-function-merging

An experimental LLVM pass plugin that allows you to apply the State of the Art function merging techniques
LLVM
8
star
22

kcc-swift

kateinoigakukun's C compiler written in Swift
Swift
7
star
23

swift-lto-benchmark

CMake
7
star
24

MachOParser

Swift
7
star
25

swift-objdump

Swift
6
star
26

optcarrot.wasm

A NES emulator written in Ruby on browser powered by WebAssembly
TypeScript
6
star
27

jupyterlite-ruby-kernel

TypeScript
6
star
28

rbwasm

Rust
5
star
29

rb-wasm-support

C
5
star
30

wasminspect-agent.js

A debugger agent of wasminspect for JavaScript host environment.
TypeScript
4
star
31

IBCodeGen

A tool to transition from Interface Builder to Swift code
Swift
4
star
32

swift-demangle-vim

Translates cryptic Swift symbols into a human-readable form.
Vim Script
4
star
33

swift-stepic

Swift Image steganography
Swift
4
star
34

PoppyBot

A chat bot for Slack
Swift
3
star
35

swiftwasm-simd-samples

swiftwasm-simd-samples
Swift
3
star
36

swiftwasm-threading-example

JavaScript
3
star
37

wasm-shrink

Rust
3
star
38

swiftwasm-scripts

Shell
3
star
39

fastlane-plugin-compilation_time_profiler

Ruby
3
star
40

ruby-component-linking-demo

Demo of Ruby + Wasm + Component Model + Extension libraries
Makefile
2
star
41

KateiSandbox-Carthage-As-Static

Swift
2
star
42

SwiftAwake

Swift
2
star
43

XcodeGenWithPods

Swift
1
star
44

chibi-ray

Swift
1
star
45

CodableURL

Swift
1
star
46

chibi-sat

A toy SAT solver written in Swift
Swift
1
star
47

swift-autolink-issue-repro

Swift
1
star
48

swift-wasm-distributed-actor-samples

Swift
1
star
49

swiftc

Swift
1
star
50

kfortran

Swift
1
star
51

swift-malloctrace

MallocTrace
C
1
star
52

swiftwasm-issue-2851

Swift
1
star
53

sudoku-solver

A PoC project of chibi-sat, which is a toy SAT solver written in Swift.
Swift
1
star
54

swiftwasm-destination

swiftwasm-destination
Ruby
1
star
55

swift-stringify-macro.wasm

Swift
1
star