Skip to content
A lightweight Cargo subcommand to build Rust code for the `wasm32-wasi` target
Rust
Branch: master
Clone or download
MarkMcCaskey and alexcrichton Check CARGO_TARGET_WASM32_WASI_RUNNER for runtime override (#32)
* Check CARGO_TARGET_WASM32_WASI_RUNNER for runtime override

* Improve runtime override logic, add tests for runtime override

This commit updates the logic to handle file paths, which are quite
useful for debugging, as well as commands found on $PATH.

It also adds various tests to make sure that the override works
correctly.

* Update echo test to not assume forward slash for Windows
Latest commit f85ca88 Dec 11, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows Only run CI on the master branch Dec 5, 2019
crates
doc Check CARGO_TARGET_WASM32_WASI_RUNNER for runtime override (#32) Dec 11, 2019
examples Note that `--release` is needed for the markdown example Nov 19, 2019
src Check CARGO_TARGET_WASM32_WASI_RUNNER for runtime override (#32) Dec 11, 2019
tests/tests Check CARGO_TARGET_WASM32_WASI_RUNNER for runtime override (#32) Dec 11, 2019
.gitignore
CODE_OF_CONDUCT.md
CONTRIBUTING.md Update URLs to new home Nov 12, 2019
Cargo.toml Update assert_cmd requirement from 0.11.1 to 0.12.0 (#31) Dec 5, 2019
LICENSE Relicense to Apache 2.0 with LLVM exception Nov 15, 2019
ORG_CODE_OF_CONDUCT.md Make it a Bytecode Alliance project (#15) Nov 12, 2019
README.md Clarify contrib docs in README Nov 18, 2019
SECURITY.md Make it a Bytecode Alliance project (#15) Nov 12, 2019
build.rs Start fleshing out commands Oct 23, 2019

README.md

cargo wasi

A Bytecode Alliance project

A lightweight Cargo subcommand to build code for the wasm32-wasi target.

Crates.io version Download docs.rs docs

Guide | Contributing

Installation

To install this Cargo subcommand, first you'll want to install Rust and then you'll execute:

$ cargo install cargo-wasi

After that you can verify it works via:

$ cargo wasi --version

Read more about installation in the guide!

Usage

The cargo wasi subcommand is a thin wrapper around cargo subcommands, providing optimized defaults for the wasm32-wasi target. Using cargo wasi looks very similar to using cargo:

  • cargo wasi build — build your code in debug mode for the wasi target.

  • cargo wasi build --release — build the optimized version of your *.wasm.

  • cargo wasi run — execute a binary.

  • cargo wasi test — run your tests in wasm32-wasi.

  • cargo wasi bench — run your benchmarks in wasm32-wasi.

In general, if you'd otherwise execute cargo foo --flag you can likely execute cargo wasi foo --flag and everything will "just work" for the wasm32-wasi target.

To give it a spin yourself, try out the hello-world versions of programs!

$ cargo new wasi-hello-world
     Created binary (application) `wasi-hello-world` package
$ cd wasi-hello-world
$ cargo wasi run
   Compiling wasi-hello-world v0.1.0 (/code/wasi-hello-world)
    Finished dev [unoptimized + debuginfo] target(s) in 0.15s
     Running `cargo-wasi target/wasm32-wasi/debug/wasi-hello-world.wasm`
     Running `target/wasm32-wasi/debug/wasi-hello-world.wasm`
Hello, world!

Or a library with some tests:

$ cargo new wasi-hello-world --lib
     Created library `wasi-hello-world` package
$ cd wasi-hello-world
$ cargo wasi test
   Compiling wasi-hello-world v0.1.0 (/code/wasi-hello-world)
    Finished dev [unoptimized + debuginfo] target(s) in 0.19s
     Running target/wasm32-wasi/debug/deps/wasi_hello_world-9aa88657c21196a1.wasm
     Running `/code/wasi-hello-world/target/wasm32-wasi/debug/deps/wasi_hello_world-9aa88657c21196a1.wasm`

running 1 test
test tests::it_works ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Read more about cargo wasi usage in the guide!

License

This project is license under the Apache 2.0 license with the LLVM exception. See [LICENSE] for more details.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.

See the contributing section of the guide to start hacking on cargo wasi!

You can’t perform that action at this time.