Components Cont'd
In the previous chapter we built a simple WebAssembly component that demonstrated basic interface definitions and WASI integration. We covered a lot of ground, but the end result wasn't terribly interesting. We'll now return to our calculator project and build something more substantial!
In this chapter we will expand our parser by adding an evaluator that evaluates the parsed mathematical expressions. The evaluator should respect standard operator precedence rules - parentheses first, then multiplication and division, followed by addition and subtraction - and return the computed result as an f64.
Project Structure
Notice how the project now consists of a main.rs file instead of a lib.rs. We're now building a CLI WebAssembly component!
By compiling to the wasm32-wasip2 target, Rust automatically implements the wasi:cli/run interface for us, declaring us compatible with the behavior for traditional CLI executables.
You can run the exercise directly using cargo run --target wasm32-wasip2.
Note: Usually you cannot simply
cargo runexecutables compiled towasm32-wasip2the same way you cannot simply run executables compiled forx86on anaarch64machine. For your convenience this workshop provides a runner built onwasmtimethat allows you to run these as if the were native executables.
TODO exercise hints