### Run WASI Pipes Example Source: https://github.com/wasmerio/wasmer/blob/main/examples/README.md Execute the WASI Pipes example using Cargo. This builds on the WASI example to demonstrate stdio piping. Ensure the 'cranelift' and 'wasi' features are enabled. ```shell $ cargo run --example wasi-pipes --release --features "cranelift,wasi" ``` -------------------------------- ### Run WASI Example Source: https://github.com/wasmerio/wasmer/blob/main/examples/README.md Execute the WASI example using Cargo. Ensure the 'cranelift' and 'wasi' features are enabled. ```shell $ cargo run --example wasi --release --features "cranelift,wasi" ``` -------------------------------- ### Install cargo-insta CLI Source: https://github.com/wasmerio/wasmer/blob/main/tests/integration/README.md Install the cargo-insta CLI tool, which is used for managing snapshot tests. ```bash cargo install cargo-insta ``` -------------------------------- ### Execute Engine Example Source: https://github.com/wasmerio/wasmer/blob/main/examples/README.md Illustrates what an engine is and how to set it up. The example compiles a Wasm module, instantiates it, and calls an exported function. ```shell $ cargo run --example engine --release --features "cranelift" ``` -------------------------------- ### Example Content HTML Source: https://github.com/wasmerio/wasmer/blob/main/lib/cli/src/utils/package_wizard/templates/static-site/index.html This is an example of a 'content.html' file that can be loaded dynamically into the main template. It contains a simple heading and paragraph. ```html

About This Site

This content was loaded dynamically using JavaScript.

``` -------------------------------- ### Install Rustup on Linux/macOS Source: https://github.com/wasmerio/wasmer/blob/main/docs/BUILD.md Installs Rustup, the toolchain installer for Rust, on Linux and macOS systems. This is the recommended way to manage Rust installations. ```bash curl https://sh.rustup.rs -sSf | sh ``` -------------------------------- ### Execute Hello World Example Source: https://github.com/wasmerio/wasmer/blob/main/examples/README.md This command executes the 'hello-world' example, demonstrating the core concepts of compiling and executing WebAssembly with the Wasmer API. Ensure the 'cranelift' feature is enabled. ```shell $ cargo run --example hello-world --release --features "cranelift" ``` -------------------------------- ### Execute Instantiating Module Example Source: https://github.com/wasmerio/wasmer/blob/main/examples/README.md This command runs the 'instance' example, which covers the basics of using Wasmer to create an instance from a Wasm module. The 'cranelift' feature is required. ```shell $ cargo run --example instance --release --features "cranelift" ``` -------------------------------- ### Install Wasmer using curl Source: https://github.com/wasmerio/wasmer/blob/main/README.md Installs Wasmer by downloading and executing a script. This is the primary installation method. ```sh curl https://get.wasmer.io -sSfL | sh ``` -------------------------------- ### Install cargo-fuzz Source: https://github.com/wasmerio/wasmer/blob/main/fuzz/README.md Installs the cargo-fuzz library, which provides the 'cargo fuzz' subcommand for running fuzz tests. ```sh $ cargo install cargo-fuzz ``` -------------------------------- ### Configure Installation Prefix and DESTDIR Source: https://github.com/wasmerio/wasmer/blob/main/docs/PACKAGING.md Set the WASMER_INSTALL_PREFIX environment variable to define the installation root. Use DESTDIR to specify a staging directory for packaging, ensuring it includes the installation prefix. ```sh export WASMER_INSTALL_PREFIX=/usr make DESTDIR=/tmp/staging/usr make install ``` -------------------------------- ### Execute Features Example Source: https://github.com/wasmerio/wasmer/blob/main/examples/README.md Illustrates how to enable WebAssembly features that are not yet stable. ```shell $ cargo run --example features --release --features "cranelift" ``` -------------------------------- ### Execute Headless Engines Example Source: https://github.com/wasmerio/wasmer/blob/main/examples/README.md Explains headless engines and their benefits. The example instantiates a pre-compiled Wasm module and calls an exported function. ```shell $ cargo run --example engine-headless --release --features "cranelift" ``` -------------------------------- ### Execute LLVM Compiler Example Source: https://github.com/wasmerio/wasmer/blob/main/examples/README.md Explains how to use the `wasmer-compiler-llvm` compiler. ```shell $ cargo run --example compiler-llvm --release --features "llvm" ``` -------------------------------- ### Install Wasmer CLI using Cargo binstall Source: https://github.com/wasmerio/wasmer/blob/main/README.md Installs the Wasmer CLI using cargo-binstall, a tool for installing Rust binaries. This is a fast way to install Rust-based tools. ```sh cargo binstall wasmer-cli ``` -------------------------------- ### Execute Imported Global Example Source: https://github.com/wasmerio/wasmer/blob/main/examples/README.md This command runs the 'imported-global' example, which explains how to work with imported globals, including their creation, import, and value manipulation. The 'cranelift' feature is required. ```shell $ cargo run --example imported-global --release --features "cranelift" ``` -------------------------------- ### Run fork WASIX example Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/tests/README.md Executes a WASIX Wasm module that demonstrates a simple fork. This example serves as a crude implementation of multi-threading and is used by the `dash` shell. ```sh cd ../../cli cargo run --features compiler,cranelift,debug -- --enable-threads ../wasix/tests/example-fork.wasm ``` -------------------------------- ### Execute Imported Function Example Source: https://github.com/wasmerio/wasmer/blob/main/examples/README.md This command executes the 'imported-function' example, detailing how to define imported functions, covering both dynamic and static/native approaches. The 'cranelift' feature must be enabled. ```shell $ cargo run --example imported-function --release --features "cranelift" ``` -------------------------------- ### Basic Wasmer C API Example Source: https://github.com/wasmerio/wasmer/blob/main/lib/c-api/README.md This example demonstrates the fundamental steps of using the Wasmer C API: compiling a WebAssembly module from WAT, instantiating it, retrieving an exported function, and calling that function with arguments. It includes error handling for each major step. ```c #include #include "wasmer.h" int main(int argc, const char* argv[]) { const char *wat_string = "(module\n" " (type $sum_t (func (param i32 i32) (result i32)))\n" " (func $sum_f (type $sum_t) (param $x i32) (param $y i32) (result i32)\n" " local.get $x\n" " local.get $y\n" " i32.add)\n" " (export \"sum\" (func $sum_f)))"; wasm_byte_vec_t wat; wasm_byte_vec_new(&wat, strlen(wat_string), wat_string); wasm_byte_vec_t wasm_bytes; wat2wasm(&wat, &wasm_bytes); wasm_byte_vec_delete(&wat); printf("Creating the store...\n"); wasm_engine_t* engine = wasm_engine_new(); wasm_store_t* store = wasm_store_new(engine); printf("Compiling module...\n"); wasm_module_t* module = wasm_module_new(store, &wasm_bytes); if (!module) { printf("> Error compiling module!\n"); return 1; } wasm_byte_vec_delete(&wasm_bytes); printf("Creating imports...\n"); wasm_extern_vec_t import_object = WASM_EMPTY_VEC; printf("Instantiating module...\n"); wasm_instance_t* instance = wasm_instance_new(store, module, &import_object, NULL); if (!instance) { printf("> Error instantiating module!\n"); return 1; } printf("Retrieving exports...\n"); wasm_extern_vec_t exports; wasm_instance_exports(instance, &exports); if (exports.size == 0) { printf("> Error accessing exports!\n"); return 1; } printf("Retrieving the `sum` function...\n"); wasm_func_t* sum_func = wasm_extern_as_func(exports.data[0]); if (sum_func == NULL) { printf("> Failed to get the `sum` function!\n"); return 1; } printf("Calling `sum` function...\n"); wasm_val_t args_val[2] = { WASM_I32_VAL(3), WASM_I32_VAL(4) }; wasm_val_t results_val[1] = { WASM_INIT_VAL }; wasm_val_vec_t args = WASM_ARRAY_VEC(args_val); wasm_val_vec_t results = WASM_ARRAY_VEC(results_val); if (wasm_func_call(sum_func, &args, &results)) { printf("> Error calling the `sum` function!\n"); return 1; } printf("Results of `sum`: %d\n", results_val[0].of.i32); wasm_module_delete(module); wasm_extern_vec_delete(&exports); wasm_instance_delete(instance); wasm_store_delete(store); wasm_engine_delete(engine); } ``` -------------------------------- ### Execute Exported Memory Example Source: https://github.com/wasmerio/wasmer/blob/main/examples/README.md This command executes the 'exported-memory' example, demonstrating how to read from and write to exported memory. Ensure the 'cranelift' feature is enabled. ```shell $ cargo run --example exported-memory --release --features "cranelift" ``` -------------------------------- ### Execute Singlepass Compiler Example Source: https://github.com/wasmerio/wasmer/blob/main/examples/README.md Explains how to use the `wasmer-compiler-singlepass` compiler. ```shell $ cargo run --example compiler-singlepass --release --features "singlepass" ``` -------------------------------- ### Execute Tunables Limit Memory Example Source: https://github.com/wasmerio/wasmer/blob/main/examples/README.md Shows how to use Tunables to limit the size of an exported Wasm memory. This example covers basic tunables and memory. ```shell $ cargo run --example tunables-limit-memory --release --features "cranelift" ``` -------------------------------- ### Install Wasmer using Scoop Source: https://github.com/wasmerio/wasmer/blob/main/README.md Installs Wasmer on Windows using the Scoop package manager. This is an alternative installation method for Windows. ```sh scoop install wasmer ``` -------------------------------- ### Execute Wasm Table Example Source: https://github.com/wasmerio/wasmer/blob/main/examples/README.md Demonstrates how to use Wasm Tables from the Wasmer API. This example covers basic table operations. ```shell $ cargo run --example table --release --features "cranelift" ``` -------------------------------- ### Execute Cranelift Compiler Example Source: https://github.com/wasmerio/wasmer/blob/main/examples/README.md Explains how to use the `wasmer-compiler-cranelift` compiler. ```shell $ cargo run --example compiler-cranelift --release --features "cranelift" ``` -------------------------------- ### Execute Exported Global Example Source: https://github.com/wasmerio/wasmer/blob/main/examples/README.md This command executes the 'exported-global' example, illustrating how to work with exported globals, including getting/setting their values and retrieving type information. The 'cranelift' feature is required. ```shell $ cargo run --example exported-global --release --features "cranelift" ``` -------------------------------- ### Execute Exported Function Example Source: https://github.com/wasmerio/wasmer/blob/main/examples/README.md This command runs the 'exported-function' example, which explains how to access and call exported functions, covering both dynamic and static/native flavors. The 'cranelift' feature is required. ```shell $ cargo run --example exported-function --release --features "cranelift" ``` -------------------------------- ### Execute Cross-Compilation Example Source: https://github.com/wasmerio/wasmer/blob/main/examples/README.md Demonstrates cross-compiling a Wasm module for a custom target, showcasing the abstraction over engines and compilers. ```shell $ cargo run --example cross-compilation --release --features "cranelift" ``` -------------------------------- ### Execute Interacting with Memory Example Source: https://github.com/wasmerio/wasmer/blob/main/examples/README.md This command runs the 'memory' example, demonstrating basic interactions with Wasm module memory. Ensure the 'cranelift' feature is enabled for execution. ```shell $ cargo run --example memory --release --features "cranelift" ``` -------------------------------- ### Initialize Cranelift Compiler and Store Source: https://github.com/wasmerio/wasmer/blob/main/lib/compiler-cranelift/README.md Demonstrates how to create a new instance of the Cranelift compiler and initialize a Wasmer Store with it. This is the basic setup for using the Cranelift compiler. ```rust use wasmer::{Store, sys::EngineBuilder}; use wasmer_compiler_cranelift::Cranelift; let compiler = Cranelift::new(); let mut store = Store::new(compiler); ``` -------------------------------- ### Install Wasmer using Homebrew Source: https://github.com/wasmerio/wasmer/blob/main/README.md Installs Wasmer on macOS and Linux using the Homebrew package manager. Ensure Homebrew is installed first. ```sh brew install wasmer ``` -------------------------------- ### Execute Handling Errors Example Source: https://github.com/wasmerio/wasmer/blob/main/examples/README.md This command executes the 'errors' example, focusing on the fundamentals of interacting with Wasm module memory and error handling. The 'cranelift' feature must be enabled. ```shell $ cargo run --example errors --release --features "cranelift" ``` -------------------------------- ### Install Wasmer using Powershell Source: https://github.com/wasmerio/wasmer/blob/main/README.md Installs Wasmer on Windows using Powershell. This method is suitable for Windows users. ```powershell iwr https://win.wasmer.io -useb | iex ``` -------------------------------- ### Initialize LLVM Compiler Source: https://github.com/wasmerio/wasmer/blob/main/lib/compiler-llvm/README.md Instantiates the LLVM compiler and creates a new Wasmer store with it. This is the basic setup for using the LLVM compiler. ```rust use wasmer::{Store, EngineBuilder}; use wasmer_compiler_llvm::LLVM; let compiler = LLVM::new(); let mut store = Store::new(compiler); ``` -------------------------------- ### Install LLVM 22 on Debian-like Systems Source: https://github.com/wasmerio/wasmer/blob/main/lib/compiler-llvm/README.md Provides the command to install LLVM version 22 on Debian-based Linux distributions. This is a prerequisite for using the wasmer-compiler-llvm crate. ```bash wget https://apt.llvm.org/llvm.sh -O /tmp/llvm.sh sudo bash /tmp/llvm.sh 22 ``` -------------------------------- ### Checkout and Pull Main Branch Source: https://github.com/wasmerio/wasmer/blob/main/scripts/RELEASE.md Before starting the release process, ensure you are on the latest main branch. ```bash git checkout main git pull ``` -------------------------------- ### Rust Source Code Example Source: https://github.com/wasmerio/wasmer/blob/main/docs/en/examples-coredump.md A sample Rust program that will cause a panic, useful for generating a core dump. ```rust fn c(v: usize) { a(v - 3); } fn b(v: usize) { c(v - 3); } fn a(v: usize) { b(v - 3); } pub fn main() { a(10); } ``` -------------------------------- ### Initialize Singlepass Compiler Source: https://github.com/wasmerio/wasmer/blob/main/lib/compiler-singlepass/README.md Instantiate the Singlepass compiler and create a new Wasmer store with it. This is the basic setup for using the Singlepass compiler. ```rust use wasmer::{Store, sys::EngineBuilder}; use wasmer_compiler_singlepass::Singlepass; let compiler = Singlepass::new(); let mut store = Store::new(compiler); ``` -------------------------------- ### Run WebAssembly Module from WAT Format Source: https://github.com/wasmerio/wasmer/blob/main/lib/api/README.md Example of using Wasmer to load and execute a WebAssembly module defined in the WAT format. It demonstrates module instantiation, function export retrieval, and function calling. ```rust use wasmer::{Store, Module, Instance, Value, imports}; fn main() -> anyhow::Result<()> { let module_wat = r#"$( (module (type $t0 (func (param i32) (result i32))) (func $add_one (export "add_one") (type $t0) (param $p0 i32) (result i32) local.get $p0 i32.const 1 i32.add)) )"#.; let mut store = Store::default(); let module = Module::new(&store, &module_wat)?; // The module doesn't import anything, so we create an empty import object. let import_object = imports! {}; let instance = Instance::new(&mut store, &module, &import_object)?; let add_one = instance.exports.get_function("add_one")?; let result = add_one.call(&mut store, &[Value::I32(42)])?; assert_eq!(result[0], Value::I32(43)); Ok(()) } ``` -------------------------------- ### Run fork and execve WASIX example Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/tests/README.md Executes a WASIX Wasm module that demonstrates forking and execve. This is used to test the ability to fork a process and run a new image while retaining open file handles. ```sh cd ../../cli cargo run --features compiler,cranelift,debug -- --use wasmer/coreutils --enable-threads ../wasix/tests/example-execve.wasm ``` -------------------------------- ### Get Wasmer C API Libraries for Linking Source: https://github.com/wasmerio/wasmer/blob/main/lib/c-api/README.md List the libraries required to link your program against Wasmer components. ```bash wasmer config --libs ``` -------------------------------- ### Get Wasmer CLI Version Source: https://github.com/wasmerio/wasmer/blob/main/lib/cli/README.md Check the currently installed version of the Wasmer CLI. ```bash wasmer -V ``` -------------------------------- ### Build Wasmer Headless Minimal Source: https://github.com/wasmerio/wasmer/blob/main/docs/PACKAGING.md This command builds and installs the minimal headless version of the Wasmer CLI. This is recommended when splitting the Wasmer package into subpackages. ```sh make build-wasmer-headless-minimal install-wasmer-headless-minimal ``` -------------------------------- ### Run WASI Module Programmatically Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/README.md Execute a WASI-enabled WebAssembly module programmatically using the wasmer and wasmer-wasi libraries. This example demonstrates setting up the environment, compiling the module, and capturing its stdout. ```rust use std::io::Read; use wasmer::{Module, Store}; use wasmer_wasix::{Pipe, WasiEnv}; let wasm_path = "hello.wasm"; // Let's declare the Wasm module with the text representation. let wasm_bytes = std::fs::read(wasm_path)?; // Create a Store. let mut store = Store::default(); println!("Compiling module..."); // Let's compile the Wasm module. let module = Module::new(&store, wasm_bytes)?; let (stdout_tx, mut stdout_rx) = Pipe::channel(); // Run the module. WasiEnv::builder("hello") .args(&["Gordon"]) // .env("KEY", "Value") .stdout(Box::new(stdout_tx)) .run_with_store(module, &mut store)?; eprintln!("Run complete - reading output"); let mut buf = String::new(); stdout_rx.read_to_string(&mut buf).unwrap(); eprintln!("Output: {buf}"); ``` -------------------------------- ### JavaScript for Static Site Interaction Source: https://github.com/wasmerio/wasmer/blob/main/lib/cli/src/utils/package_wizard/templates/static-site/index.html A JavaScript file for handling dynamic content or user interactions on the static site. This example shows a placeholder for content loading. ```javascript document.addEventListener('DOMContentLoaded', function() { const contentSection = document.getElementById('content'); // Placeholder for loading dynamic content contentSection.innerHTML = '

Content loaded dynamically!

'; }); ``` -------------------------------- ### Install Wasmer CLI using Cargo Source: https://github.com/wasmerio/wasmer/blob/main/README.md Installs the Wasmer CLI directly using the Cargo package manager. This method requires Rust and Cargo to be installed. ```sh cargo install wasmer-cli ``` -------------------------------- ### Run longjmp WASIX example Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/tests/README.md Executes a WASIX Wasm module that demonstrates the use of longjmp. This functionality is often used for exception handling in C programs by saving and restoring the stack. ```sh cd ../../cli cargo run --features compiler,cranelift,debug -- --enable-threads ../wasix/tests/example-longjmp.wasm ``` -------------------------------- ### JavaScript for Static Site Interactivity Source: https://github.com/wasmerio/wasmer/blob/main/lib/cli/src/utils/package_wizard/templates/static-site/index.html A basic JavaScript file for adding interactive elements to a static site. This example includes a simple console log, which can be expanded for more complex functionality. ```javascript console.log('Static site script loaded!'); // Add your JavaScript logic here // For example, to add interactivity to elements: // document.addEventListener('DOMContentLoaded', () => { // const header = document.querySelector('header h1'); // header.addEventListener('click', () => { // alert('Header clicked!'); // }); // }); ``` -------------------------------- ### Install Wasmer using Chocolatey Source: https://github.com/wasmerio/wasmer/blob/main/README.md Installs Wasmer on Windows using the Chocolatey package manager. This is another alternative for Windows users. ```sh choco install wasmer ``` -------------------------------- ### Install Wasmer CLI with Cargo Source: https://github.com/wasmerio/wasmer/blob/main/lib/cli/README.md Install the Wasmer CLI using Cargo, specifying the 'singlepass' and 'cranelift' features for compiler support. ```bash cargo install wasmer-cli --features "singlepass,cranelift" ``` -------------------------------- ### WASIX 32-bit Socket Get Option Size Import Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/wia/wasixx_32v1.txt Imports the `sock_get_opt_size` function from the `wasix_32v1` module to get a socket option size. ```wat (func (import "wasix_32v1" "sock_get_opt_size") (param i32 i32 i32) (result i32)) ``` -------------------------------- ### Run Cowsay package with Wasmer Source: https://github.com/wasmerio/wasmer/blob/main/README.md Executes the 'cowsay' WebAssembly package with the message 'hello world'. This demonstrates running a simple package. ```bash $ wasmer run cowsay "hello world" ``` -------------------------------- ### WASIX 32-bit Socket Get Option Time Import Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/wia/wasixx_32v1.txt Imports the `sock_get_opt_time` function from the `wasix_32v1` module to get a socket option time. ```wat (func (import "wasix_32v1" "sock_get_opt_time") (param i32 i32 i32) (result i32)) ``` -------------------------------- ### WASIX 32-bit Socket Get Option Flag Import Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/wia/wasixx_32v1.txt Imports the `sock_get_opt_flag` function from the `wasix_32v1` module to get a socket option flag. ```wat (func (import "wasix_32v1" "sock_get_opt_flag") (param i32 i32 i32) (result i32)) ``` -------------------------------- ### Run a WebAssembly File Source: https://github.com/wasmerio/wasmer/blob/main/lib/cli/README.md Execute a WebAssembly module using the 'wasmer run' command. ```bash wasmer run myfile.wasm ``` -------------------------------- ### process_spawn Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/wia/wasixx_32v1.txt Spawns a new process with specified arguments and environment variables. ```APIDOC ## process_spawn ### Description Spawns a new process with specified arguments and environment variables. ### Signature (param i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32) (result i32) ### Parameters This function takes 13 i32 parameters. The exact meaning of each parameter would typically be detailed in the WASIX specification. ``` -------------------------------- ### Install LLVM on macOS using Homebrew Source: https://github.com/wasmerio/wasmer/blob/main/docs/BUILD.md Installs LLVM version 22.1 on macOS using the Homebrew package manager. This is required for enabling the LLVM backend when building Wasmer from source. ```bash brew install llvm@22 ``` -------------------------------- ### Build Wasmer with V8 Backend Source: https://github.com/wasmerio/wasmer/blob/main/docs/BUILD.md Enable and build the Wasmer runtime with the V8 backend. The build script downloads necessary libraries. ```bash ENABLE_V8=1 make build-wasmer ``` -------------------------------- ### Socket Get Option (Size) Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/wia/wasixx_64v1.txt Retrieves a size-based option for a socket. ```APIDOC ## sock_get_opt_size ### Description Retrieves a size-based option for a socket. ### Method (import "wasix_64v1" "sock_get_opt_size") ### Parameters - **param1** (i32) - **param2** (i32) - **param3** (i64) ### Result - **result1** (i32) ``` -------------------------------- ### Initialize FunctionEnv with an i32 environment Source: https://github.com/wasmerio/wasmer/blob/main/docs/migration_to_3.0.0.md Use FunctionEnv::new to initialize an environment with a simple i32 value. The environment type must implement the Any trait. ```rust let my_counter = 0_i32; let env = FunctionEnv::new(&mut store, my_counter); ``` -------------------------------- ### Socket Get Option (Time) Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/wia/wasixx_64v1.txt Retrieves a time-based option for a socket. ```APIDOC ## sock_get_opt_time ### Description Retrieves a time-based option for a socket. ### Method (import "wasix_64v1" "sock_get_opt_time") ### Parameters - **param1** (i32) - **param2** (i32) - **param3** (i64) ### Result - **result1** (i32) ``` -------------------------------- ### Compare Compilation Times Source: https://github.com/wasmerio/wasmer/blob/main/docs/dev/create-exe.md Demonstrates the performance difference between creating an executable directly from a .wasm file and using a pre-compiled object file. Using pre-compiled objects significantly reduces execution time. ```sh time wasmer create-exe myfile.wasm -o myfile.exe 1,53s user 0,24s system 157% cpu 1,124 total time wasmer create-exe myfile.wasm -o myfile.exe --precompiled-atom myfile:myfile.o 0,72s user 0,19s system 105% cpu 0,856 total ``` -------------------------------- ### Create Basic Executable Source: https://github.com/wasmerio/wasmer/blob/main/docs/dev/create-exe.md Use this command to compile a single .wasm file into a runnable executable. The output executable can then be run directly. ```sh wasmer create-exe myfile.wasm -o myfile.exe ./myfile.exe ``` -------------------------------- ### Socket Get Option (Flag) Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/wia/wasixx_64v1.txt Retrieves a flag-based option for a socket. ```APIDOC ## sock_get_opt_flag ### Description Retrieves a flag-based option for a socket. ### Method (import "wasix_64v1" "sock_get_opt_flag") ### Parameters - **param1** (i32) - **param2** (i32) - **param3** (i64) ### Result - **result1** (i32) ``` -------------------------------- ### Build Wasmer Binary Source: https://github.com/wasmerio/wasmer/blob/main/docs/BUILD.md Builds the main Wasmer binary. This command should be run after cloning the repository. ```text ./target/release/wasmer quickjs.wasm ``` -------------------------------- ### Directory Navigation Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/wia/wasixx_64v1.txt Functions for changing and getting the current working directory. ```APIDOC ## getcwd ### Description Retrieves the current working directory. ### Method N/A (WebAssembly import) ### Parameters - **buf** (i64) - Pointer to the buffer to store the path. - **buf_len** (i64) - The length of the buffer. ### Result i32 - WASI error code. ``` ```APIDOC ## chdir ### Description Changes the current working directory. ### Method N/A (WebAssembly import) ### Parameters - **path** (i64) - Pointer to the path of the new directory. - **path_len** (i64) - The length of the path. ### Result i32 - WASI error code. ``` -------------------------------- ### sock_open Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/wia/wasixx_32v1.txt Opens a new socket. ```APIDOC ## sock_open ### Description Opens a new socket. ### Signature (param i32 i32 i32 i32) (result i32) ### Parameters This function takes 4 i32 parameters. The exact meaning of each parameter would typically be detailed in the WASIX specification, likely including address family, socket type, and protocol. ``` -------------------------------- ### Socket Open Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/wia/wasixx_64v1.txt Opens a new socket. ```APIDOC ## sock_open ### Description Opens a new socket. ### Method (import "wasix_64v1" "sock_open") ### Parameters - **param1** (i32) - **param2** (i32) - **param3** (i32) - **param4** (i64) ### Result - **result1** (i32) ``` -------------------------------- ### Process Management Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/wia/wasixx_32v1.txt Functions for process control, including exiting, raising signals, and getting process IDs. ```APIDOC ## proc_exit ### Description Exits the current process. ### Signature (param i32) ## proc_raise ### Description Raises a signal in the current process. ### Signature (param i32) (result i32) ## getpid ### Description Gets the process ID. ### Signature (param i32) (result i32) ``` -------------------------------- ### Execute Release Process Source: https://github.com/wasmerio/wasmer/blob/main/docs/dev/release.md This sequence of commands outlines the steps to create a new Wasmer release. It includes logging into GitHub CLI, initiating the release PR, manually triggering the build workflow if necessary, and publishing crates.io. ```sh gh login python3 scripts/make-release.py 3.2.0 git checkout master git tag v3.2.0 && git push origin v3.2.0 gh workflow run build.yml --ref v3.2.0 --field release=v3.2.0 python3 scripts/make-release.py 3.2.0 git checkout v3.2.0 python3 scripts/publish.py publish ``` -------------------------------- ### WASIX 32-bit Socket Status Import Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/wia/wasixx_32v1.txt Imports the `sock_status` function from the `wasix_32v1` module to get the status of a socket. ```wat (func (import "wasix_32v1" "sock_status") (param i32 i32) (result i32)) ``` -------------------------------- ### WASIX 32-bit Process Spawn Import Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/wia/wasixx_32v1.txt Imports the `process_spawn` function from the `wasix_32v1` module for creating new processes. ```wat (func (import "wasix_32v1" "process_spawn") (param i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32) (result i32)) ``` -------------------------------- ### WASIX 32-bit Socket Open Import Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/wia/wasixx_32v1.txt Imports the `sock_open` function from the `wasix_32v1` module to open a socket. ```wat (func (import "wasix_32v1" "sock_open") (param i32 i32 i32 i32) (result i32)) ``` -------------------------------- ### Get Wasmer C API Library Directory Source: https://github.com/wasmerio/wasmer/blob/main/lib/c-api/README.md Retrieve the directory path where the Wasmer library files are located. ```bash wasmer config --libdir ``` -------------------------------- ### sock_connect Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/wia/wasixx_32v1.txt Initiates a connection to a remote host. ```APIDOC ## sock_connect ### Description Initiates a connection to a remote host. ### Signature (param i32 i32) (result i32) ### Parameters - **socket_id** (i32) - Required - The identifier of the socket. - **addr** (i32) - Required - The address of the remote host to connect to. ``` -------------------------------- ### WASIX 32-bit Port MAC Import Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/wia/wasixx_32v1.txt Imports the `port_mac` function from the `wasix_32v1` module to get the MAC address of a port. ```wat (func (import "wasix_32v1" "port_mac") (param i32) (result i32)) ``` -------------------------------- ### WASIX 32-bit Socket Listen Import Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/wia/wasixx_32v1.txt Imports the `sock_listen` function from the `wasix_32v1` module to listen for incoming connections on a socket. ```wat (func (import "wasix_32v1" "sock_listen") (param i32 i32) (result i32)) ``` -------------------------------- ### WASIX 32-bit HTTP Status Import Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/wia/wasixx_32v1.txt Imports the `http_status` function from the `wasix_32v1` module to get the status of an HTTP request. ```wat (func (import "wasix_32v1" "http_status") (param i32 i32)) ``` -------------------------------- ### Socket Connect Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/wia/wasixx_64v1.txt Establishes a connection to a remote host. ```APIDOC ## sock_connect ### Description Establishes a connection to a remote host. ### Method (import "wasix_64v1" "sock_connect") ### Parameters - **param1** (i32) - **param2** (i64) ### Result - **result1** (i32) ``` -------------------------------- ### Passing Host Functions: Wasmer 1.x (Dynamic) Source: https://github.com/wasmerio/wasmer/blob/main/docs/migration_to_1.0.0.md Demonstrates how to define and pass a dynamic host function with a specific signature in Wasmer 1.x using `Function::new`. ```rust let sum_signature = FunctionType::new(vec![Type::I32, Type::I32], vec![Type::I32]); let sum = Function::new(&store, &sum_signature, |args| { let result = args[0].unwrap_I32() + args[1].unwrap_i32(); Ok(vec![Value::I32(result)]) }); ``` -------------------------------- ### WASIX 32-bit Socket Peer Address Import Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/wia/wasixx_32v1.txt Imports the `sock_addr_peer` function from the `wasix_32v1` module to get the peer address of a socket. ```wat (func (import "wasix_32v1" "sock_addr_peer") (param i32 i32) (result i32)) ``` -------------------------------- ### Create Executable using Pre-compiled Object File Source: https://github.com/wasmerio/wasmer/blob/main/docs/dev/create-exe.md This command creates an executable by linking a pre-compiled object file. It uses the `--precompiled-atom` flag to specify the atom name and the path to the object file, which can significantly speed up the compilation process compared to compiling from .wasm directly. ```sh # Run create-exe with the cached object file wasmer create-exe myfile.wasm --precompiled-atom=myfile:myfile.o -o myfile.exe ``` -------------------------------- ### WASIX 32-bit Socket Local Address Import Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/wia/wasixx_32v1.txt Imports the `sock_addr_local` function from the `wasix_32v1` module to get the local address of a socket. ```wat (func (import "wasix_32v1" "sock_addr_local") (param i32 i32) (result i32)) ``` -------------------------------- ### Get Wasmer C API Include Directory Source: https://github.com/wasmerio/wasmer/blob/main/lib/c-api/README.md Retrieve the directory path containing the Wasmer header files needed for compilation. ```bash wasmer config --includedir ``` -------------------------------- ### Module Instantiation: Wasmer 0.x vs 1.x Source: https://github.com/wasmerio/wasmer/blob/main/docs/migration_to_1.0.0.md Compares the code for instantiating a WebAssembly module in Wasmer 0.x and 1.x. Wasmer 1.x offers more control over configuration. ```diff - let module = compile(&wasm_bytes[..])?; + let engine = JIT::new(Cranelift::default()).engine(); + let store = Store::new(&engine); + let module = Module::new(&store, wasm_bytes)?; - let instance = module.instantiate(&imports)?; + let instance = Instance::new(&module, &import_object)?; ``` -------------------------------- ### Passing Host Functions: Wasmer 0.x vs 1.x (Native) Source: https://github.com/wasmerio/wasmer/blob/main/docs/migration_to_1.0.0.md Illustrates how to pass a native host function ('sum') to a guest module in Wasmer 0.x using `func!` and in Wasmer 1.x using `Function::new_native`. ```diff let import_object = imports! { "env" => { - "sum" => func!(sum), + "sum" => Function::new_native(&store, sum), } } ``` -------------------------------- ### Get Wasmer C API Compiler Flags Source: https://github.com/wasmerio/wasmer/blob/main/lib/c-api/README.md Retrieve the compiler flags, including include paths, needed to build against Wasmer components. ```bash wasmer config --cflags ``` -------------------------------- ### JavaScript for Dynamic Content Loading Source: https://github.com/wasmerio/wasmer/blob/main/lib/cli/src/utils/package_wizard/templates/static-site/index.html This JavaScript code demonstrates how to fetch and display content dynamically. It assumes a 'content.html' file exists and loads it into the '#content' section. ```javascript document.addEventListener('DOMContentLoaded', function() { const contentSection = document.getElementById('content'); fetch('content.html') .then(response => { if (!response.ok) { throw new Error('Network response was not ok'); } return response.text(); }) .then(html => { contentSection.innerHTML = html; }) .catch(error => { console.error('Error loading content:', error); contentSection.innerHTML = '

Error loading content.

'; }); }); ``` -------------------------------- ### Compile a WebAssembly File Source: https://github.com/wasmerio/wasmer/blob/main/lib/cli/README.md Compile a WebAssembly file to a Wasmer module format using the 'wasmer compile' command. ```bash wasmer compile myfile.wasm -o myfile.wasmu ``` -------------------------------- ### Run WASIX vfork Test Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/tests/README.md Executes the WASIX vfork test example using cargo run. This test verifies lightweight forking functionality. ```sh cd ../../cli cargo run --features compiler,cranelift,debug -- --enable-threads ../wasix/tests/example-vfork.wasm ``` -------------------------------- ### http_request Source: https://github.com/wasmerio/wasmer/blob/main/lib/wasix/wia/wasixx_32v1.txt Initiates an HTTP request. ```APIDOC ## http_request ### Description Initiates an HTTP request. ### Signature (param i32 i32 i32 i32 i32 i32 i32 i32) (result i32) ### Parameters This function takes 8 i32 parameters. The exact meaning of each parameter would typically be detailed in the WASIX specification, likely including details about the URL, method, headers, and body. ``` -------------------------------- ### Run Javascript Service Worker Locally Source: https://github.com/wasmerio/wasmer/blob/main/tests/integration/cli/tests/packages/js/README.md Execute the Javascript Service Worker locally using the Wasmer CLI. Ensure you have Wasmer installed and the project is set up. ```bash wasmer run . --net ```