Skip to main content

Module run_wasm

Module run_wasm 

Source
Expand description

cargo xtask run-wasm: build and serve the web examples.

The pipeline is the standard one for a wasm32-unknown-unknown binary a browser runs: build for the target, hand the wasm to wasm-bindgen so it gets a JS loader, then put the pages and the wasm behind a static file server β€” WebGPU is only available in a secure context, and localhost is one, while a file:// URL is not. The server is built in (super::http), so nothing needs to be installed.

The output directory is the one the Pages workflow publishes: a landing page at the root, one directory per example beside it, and the API docs under docs/ β€” which only the workflow builds. --app picks which examples are built; the landing page links the ones that are there.

Re-exportsΒ§

use std::path::Path; πŸ”’
use std::path::PathBuf; πŸ”’
use super::RunWasmArgs; πŸ”’
use super::WebApp; πŸ”’
use super::http; πŸ”’
use super::step; πŸ”’

StructsΒ§

Example
One example the site can show.

ConstantsΒ§

DOCS_DIR πŸ”’
Where the API docs sit under the site’s root.
EXAMPLES
Every example the site can show, in the order the landing page lists them.
EXAMPLE_HTML πŸ”’
The page that starts one example.
LANDING_HTML πŸ”’
The site’s landing page: what the examples are, and where the docs are.
OUT_DIR
Where the bindgen output lands, inside target/.
PORT πŸ”’
The port the site prefers to be served on. Fixed, so the URL to open is predictable; if it is taken, the server tries the ports after it.
PROFILE
The cargo profile every wasm build of this repository uses, defined in the workspace manifest: release’s settings at a size-oriented opt-level, the trade-off the name keeps from the wasm-dev it was renamed from β€” wasm builds are only ever made for a browser to download, so none of them pay for the larger binary --release produces.
TARGET
The target triple the web build runs on.

FunctionsΒ§

build
Build the selected examples and the landing page into one directory.
build_example
Compile one example for wasm32-unknown-unknown, and bindgen it.
example_page πŸ”’
The page that starts one example.
examples πŸ”’
The examples app asks for.
landing_page πŸ”’
The landing page: a link to each example that was built, and the API docs.
run
Build and serve the web site.