268: add experimental virtual filesystem r=lachlansneff a=xmclark This PR introduces some changes to the runtime and adds a new feature: virtual file system. In the future, we may want to bundle data with our wasm apps. That data can be made available to apps in a virtual filesystem by the wasmer runtime. To do this: - wasmer must understand custom section data - wasmer must re-wire emscripten calls to access a virtual file system - these features are experimental and should be guarded by a feature flag (`--features vfs`) ~This PR adds support for the `read` syscall. ~ Just kidding, this PR does a lot more. Enough syscalls were re-implemented that a code reorg was warranted. Additions below ⬇️ Several new modules live under and around the `syscalls` module. These features are only supported on linux, but can be expanded to windows. There are effectively two implementations: one for VFS and one for the host FS. In the future, we will have more tight control over access to the host, but this will do for now. The `select` function was also extracted into a new module as the complexity increased significantly. `select`should be refactored in the future to use a runtime like tokio, but that will need to wait. The introduction of the libsodium dependency introduced some stumbling blocks, so I forked the zbox project and added a new build step. See it [here](https://github.com/wasmerio/zbox/blob/bundle-libsodium/build.rs). This will build libsodium at `cargo build` time and will automatically configure the environment. This will help with adoption and it is something we may be able to give back to zbox. Additional changes: After review, this PR is just a bit too large. We will implement the emscripten changes in another PR. This will help accelerate the work on WASI. Co-authored-by: Mackenzie Clark <mackenzie.a.z.c@gmail.com>
Introduction
Wasmer is a standalone JIT WebAssembly runtime, aiming to be fully compatible with WASI and Emscripten.
Install Wasmer with:
curl https://get.wasmer.io -sSfL | sh
NEW ✨: You can now embed Wasmer in your Rust application, check our example repo to see how!
Usage
Wasmer can execute both the standard binary format (.wasm
) and the text
format defined by the WebAssembly reference interpreter (.wat
).
Once installed, you will be able to run any WebAssembly files (including nginx and Lua!):
# Run Lua
wasmer run examples/lua.wasm
# Run nginx
wasmer run examples/nginx/nginx.wasm -- -p examples/nginx -c nginx.conf
Code Structure
Wasmer is structured into different directories:
src
: code related to the Wasmer executable itselflib
: modularized libraries that Wasmer uses under the hoodexamples
: some useful examples to getting started with Wasmer
Dependencies
Building Wasmer requires rustup.
To build on Windows, download and run rustup-init.exe
then follow the onscreen instructions.
To build on other systems, run:
curl https://sh.rustup.rs -sSf | sh
Other dependencies
Please select your operating system:
macOS
If you have Homebrew installed:
brew install cmake
Or, in case you have MacPorts:
sudo port install cmake
Debian-based Linuxes
sudo apt install cmake
Windows (MSVC)
Windows support is highly experimental. Only simple Wasm programs may be run, and no syscalls are allowed. This means nginx and Lua do not work on Windows. See this issue regarding Emscripten syscall polyfills for Windows.
-
Install Visual Studio
-
Install Rust for Windows
-
Install Python for Windows. The Windows x86-64 MSI installer is fine. Make sure to enable "Add python.exe to Path" during installation.
-
Install Git for Windows. Allow it to add
git.exe
to your PATH (default settings for the installer are fine). -
Install CMake. Ensure CMake is in your PATH.
-
Install LLVM 7.0
Building
Wasmer is built with Cargo, the Rust package manager.
# checkout code
git clone https://github.com/wasmerio/wasmer.git
cd wasmer
# install tools
# make sure that `python` is accessible.
cargo install --path .
Testing
Thanks to spec tests we can ensure 100% compatibility with the WebAssembly spec test suite.
Tests can be run with:
make test
If you need to regenerate the Rust tests from the spec tests you can run:
make spectests
You can also run integration tests with:
make integration-tests
Benchmarking
Benchmarks can be run with:
cargo bench --all
Roadmap
Wasmer is an open project guided by strong principles, aiming to be modular, flexible and fast. It is open to the community to help set its direction.
Below are some of the goals of this project (in order of priority):
- It should be 100% compatible with the WebAssembly spec tests
- It should be fast (partially achieved)
- Support WASI (in the works)
- Support Emscripten calls (in the works)
- Support Rust ABI calls
- Support Go ABI calls
Architecture
If you would like to know how Wasmer works under the hood, please see ARCHITECTURE.md.
License
Wasmer is primarily distributed under the terms of the MIT license (LICENSE).