### Build and Run PureDOOM Example Source: https://github.com/explodingcamera/tinywasm/blob/main/examples/doom/README.md These commands are used to download and build the PureDOOM WebAssembly guest and then start Doom with a specified WAD file. ```sh # download & build `PureDOOM` ./examples/doom/build.sh ``` ```sh # start doom with the WAD you want to use cargo doom /path/to/doom.wad ``` -------------------------------- ### Run Specific Example Source: https://github.com/explodingcamera/tinywasm/blob/main/CONTRIBUTING.md Execute a specific example by its name. Run without arguments to see available examples. Note: Wasm test files for examples are not included and require Binaryen and WABT. ```bash cargo run --example {example_name} ``` -------------------------------- ### Install and Run Samply Profiler Source: https://github.com/explodingcamera/tinywasm/blob/main/CONTRIBUTING.md Install the Samply profiler and use it to profile a release build of the wasm-rust example. The output is directed to 'tinywasm'. ```bash cargo install --locked samply samply record -- cargo run --release --example wasm-rust -- tinywasm ``` -------------------------------- ### Install and Basic Usage of tinywasm-cli Source: https://github.com/explodingcamera/tinywasm/blob/main/crates/cli/README.md Install the tinywasm binary using cargo and view its help message. This is the initial step before using any specific commands. ```bash $ cargo install tinywasm-cli --version 0.9.0 --bin tinywasm $ tinywasm --help ``` -------------------------------- ### Run a WebAssembly Module Source: https://github.com/explodingcamera/tinywasm/blob/main/crates/cli/README.md Execute a WebAssembly module. If no --invoke flag is provided, it expects a start function or _start export. ```bash $ tinywasm ./module.wasm ``` -------------------------------- ### Run Full WebAssembly 2.0 Test Suite Source: https://github.com/explodingcamera/tinywasm/blob/main/CONTRIBUTING.md Execute the complete test suite for WebAssembly version 2.0. ```bash cargo test-wasm-2 ``` -------------------------------- ### Run Full WebAssembly 3.0 Test Suite Source: https://github.com/explodingcamera/tinywasm/blob/main/CONTRIBUTING.md Execute the complete test suite for WebAssembly version 3.0. ```bash cargo test-wasm-3 ``` -------------------------------- ### Basic Usage of tinywasm Runtime Source: https://github.com/explodingcamera/tinywasm/blob/main/README.md Demonstrates loading a WebAssembly module, creating a store, instantiating the module, and calling an exported function. Ensure the 'add.wasm' module is available in the specified path. ```rust use tinywasm::{ModuleInstance, Store}; // Load a module from bytes let wasm = include_bytes!("../examples/wasm/add.wasm"); let module = tinywasm::parse_bytes(wasm)?; // Create a new store let mut store = Store::default(); // Instantiate the module let instance = ModuleInstance::instantiate(&mut store, &module, None)?; // Call an exported function with typed parameters let func = instance.func::<(i32, i32), i32>(&mut store, "add")?; let result = func.call(&mut store, (1, 2))?; assert_eq!(result, 3); ``` -------------------------------- ### Run All Tests Source: https://github.com/explodingcamera/tinywasm/blob/main/CONTRIBUTING.md Execute all tests in the project. ```bash cargo test ``` -------------------------------- ### Compile a WebAssembly Text File to TinyWasm Archive Source: https://github.com/explodingcamera/tinywasm/blob/main/crates/cli/README.md Compile a .wat file into the TinyWasm archive format (.twasm). ```bash $ tinywasm compile ./module.wat -o ./module.twasm ``` -------------------------------- ### Run Single WAST Test File Source: https://github.com/explodingcamera/tinywasm/blob/main/CONTRIBUTING.md Execute a specific WAST (WebAssembly Text Format) test file. Replace {file} with the desired filename. ```bash cargo test-wast ./wasm-testsuite/data/wasm-v1/{file}.wast ``` -------------------------------- ### Execute WebAssembly Spec Tests Source: https://github.com/explodingcamera/tinywasm/blob/main/crates/cli/README.md Run WebAssembly spec tests from a .wast file. This command can accept individual files or entire folders containing .wast files. ```bash $ tinywasm wast ./spec-tests/address.wast ``` -------------------------------- ### Run WebAssembly MVP Test Suite Source: https://github.com/explodingcamera/tinywasm/blob/main/CONTRIBUTING.md Execute only the tests for the WebAssembly MVP (1.0) specification. ```bash cargo test-wasm-1 ``` -------------------------------- ### Invoke a Specific Function in a WebAssembly Module Source: https://github.com/explodingcamera/tinywasm/blob/main/crates/cli/README.md Run a WebAssembly module and invoke a specific function (e.g., 'add') with arguments. Arguments are parsed from the export signature. ```bash $ tinywasm run --invoke add ./module.wasm 1 2 ``` -------------------------------- ### Parse WebAssembly Bytes with tinywasm-parser Source: https://github.com/explodingcamera/tinywasm/blob/main/crates/parser/README.md Use this snippet to parse WebAssembly binaries directly from byte arrays. It shows how to initialize the parser and use default options or customize them. ```rust use tinywasm_parser::{Parser, ParserOptions}; let bytes = include_bytes!("./file.wasm"); let parser = Parser::new(); let module = parser.parse_module_bytes(bytes)?; let parser = Parser::with_options(ParserOptions::default().with_rewrite_optimization(false)); let module = parser.parse_module_bytes(bytes)?; ``` -------------------------------- ### Run Specific Benchmark Source: https://github.com/explodingcamera/tinywasm/blob/main/CONTRIBUTING.md Execute a particular benchmark by specifying its name. Run without arguments to list available benchmarks. ```bash cargo bench --bench {bench_name} ``` -------------------------------- ### Run Custom Wasm Tests Source: https://github.com/explodingcamera/tinywasm/blob/main/CONTRIBUTING.md Execute custom WebAssembly tests located in crates/tinywasm/tests/wasm-custom. ```bash cargo test-wasm-custom ``` -------------------------------- ### Parse WebAssembly from File or Stream with tinywasm-parser Source: https://github.com/explodingcamera/tinywasm/blob/main/crates/parser/README.md This snippet demonstrates parsing WebAssembly modules from a file path or an I/O stream. It utilizes the parser's file and stream parsing capabilities. ```rust let module = parser.parse_module_file("path/to/file.wasm")?; let mut stream = std::fs::File::open("path/to/file.wasm")?; let module = parser.parse_module_stream(&mut stream)?; ``` -------------------------------- ### Dump the Contents of a TinyWasm Archive Source: https://github.com/explodingcamera/tinywasm/blob/main/crates/cli/README.md Display the contents of a .twasm file. This command can also accept .wasm and .wat inputs. ```bash $ tinywasm dump ./module.twasm ``` -------------------------------- ### Inspect a WebAssembly Module Source: https://github.com/explodingcamera/tinywasm/blob/main/crates/cli/README.md Inspect a .wasm module, providing details about its structure. This command also accepts .wat and .twasm inputs. ANSI colors are used by default when outputting to a terminal. ```bash $ tinywasm inspect ./module.wasm ``` -------------------------------- ### Add tinywasm Dependency Source: https://github.com/explodingcamera/tinywasm/blob/main/README.md Add the tinywasm crate to your project's dependencies by including this snippet in your Cargo.toml file. ```toml [dependencies] tinywasm = "0.9" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.