This crate is a small wrapper around xtask-wasm that produces an additional AudioWorklet initialisation shim for use with waw-rs.
It is based on the xtask
concept, instead of using
external tooling like wasm-pack
.
This crate requires Rust 1.58.1 at a minimum because there is a security issue on a function we use from std in previous version (see cve-2022-21658).
The best way to add xtask-waw to your project is to create a workspace with two packages: your project's package and the xtask package.
-
Create a new directory that will contains the two package of your project and the workspace's
Cargo.toml
:mkdir my-project cd my-project touch Cargo.toml
-
Create the project package and the xtask package using
cargo new
:cargo new my-project cargo new xtask
-
Open the workspace's
Cargo.toml
and add the following:[workspace] default-members = ["my-project"] members = [ "my-project", "xtask", ]
-
Create a
.cargo/config.toml
file and add the following content:[alias] xtask = "run --package xtask --"
The directory layout should look like this:
project
├── .cargo
│ └── config.toml
├── Cargo.toml
├── my-project
│ ├── Cargo.toml
│ └── src
│ └── ...
└── xtask
├── Cargo.toml
└── src
└── main.rs
And now you can run your xtask package using:
cargo xtask
You can find more information about xtask here.
Finally, add the following to the xtask package's Cargo.toml
:
[dependencies]
xtask-waw = { git = "https://github.com/Marcel-G/waw-rs" }
This library gives you three structs:
Dist
- Generate a distributed package for Wasm.
They all implement clap::Parser
allowing them to be added easily to an existing CLI implementation and are
flexible enough to be customized for most use-cases.
You can find further information for each type at their documentation level.
use std::process::Command;
use xtask_waw::{anyhow::Result, clap};
#[derive(clap::Parser)]
enum Opt {
Dist(xtask_waw::Dist),
}
fn main() -> Result<()> {
let opt: Opt = clap::Parser::parse();
match opt {
Opt::Dist(dist) => {
dist
.dist_dir_path("dist")
.app_name("my-project")
.run_in_workspace(true)
.run("my-project")?;
}
}
Ok(())
}