Skip to content

Rust WASM

Rust and WebAssembly Documentation | Rust and WebAssembly

unknown target

环境配置

通过 rustup 安装 wasm target rustup target add wasm32-unknown-unknown

步骤

Build wasm target cargo build --target=wasm32-unknown-unknown

Use wasm-bindgen-cli wasm-bindgen target/wasm32-unknown-unknown/debug/calculator.wasm --out-dir out --web

Create .html

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Tour - Iced</title>
  </head>
  <body>
    <script type="module">
      import init from "./tour/tour.js";

      init("./tour/tour_bg.wasm");
    </script>
  </body>
</html>

Use trunk trunk serve

wasm-bindgen

wasm-pack

wasi target

rustup target add wasm32-wasi

使用 WasmEdge

GitHub - apepkuss/wasmedge-rust-examples