# WASM Usage

WebAssembly 2.0 is supported except for exceptions and threads. The supported WASM feature set is the same as the features supported by `wasm2c` 1.0.34 when used with default options (no cmd line switches passed). See WASM features supported by `wasm2c` in the following [table](https://github.com/WebAssembly/wabt/blob/1.0.34/README.md#supported-proposals).

From WASI only standard input and standard output are supported.

Use `/valida-toolchain/bin/compile-wasm.sh` to compile a `.wasm` program into a Valida executable:

```
/valida-toolchain/bin/compile-wasm.sh file.wasm -o output_path
```

`file.wasm` must export an entrypoint called `_start` that doesn't take any arguments and returns no value.

The `compile-wasm.sh` compilation pipeline involves an intermediate step that compiles WASM to C with `wasm2c`. Then C is compiled to Valida executable with Valida toolchain.

It's assumed that Valida toolchain is installed and is located at the default installation location: `/valida-toolchain`

It's assumed that `wasm2c` and `wat2wasm` in version 1.0.34 are in PATH. On Ubuntu 24.04 these can be installed with a command: `apt install wabt`.

See WASM examples bundled in the release package or in the toolchain Docker image at `/valida-toolchain/examples/wasm`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lita.gitbook.io/lita-documentation/quick-start/valida-compiler-toolchain/wasm-usage.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
