Git Product home page Git Product logo

cargo-run-wasm's Introduction

cargo run-wasm

Crates.io Docs dependency status

Allows running wasm applications and examples as simply as:

cargo run-wasm crate_name

or

cargo run-wasm --example example_name

In the background it:

  1. Compiles the rust project to wasm
  2. Runs wasm-bindgen
  3. Generates an index.html that runs the wasm.
  4. Launches a tiny webserver to serve index.html + your wasm

Setup

  1. Setup your wasm runnable project as a crate within a cargo workspace
  2. Create a crate in the workspace named run-wasm with:

Cargo.toml:

[package]
name = "run-wasm"
version = "0.1.0"
edition = "2021"

[dependencies]
cargo-run-wasm = "0.1.0"

main.rs:

fn main() {
    cargo_run_wasm::run_wasm();
}
  1. Create a .cargo/config file containing:
[alias]
run-wasm = "run --release --package run-wasm --"
  1. Thats it, you can now run the commands described earlier. You can also run cargo run-wasm --help to view all the possible flags.

Advantages over an equivalent bash/powershell/bat script

  • cross platform
  • 0 external dependencies
  • better UX + more robust than anything hacked together with bash/powershell/bat
  • wasm-bindgen-cli version is always in sync with wasm-bindgen version because cargo update updates both of them at the same time thanks to being in the same workspace

cargo custom command

cargo-run-wasm is not available as a cargo custom command as that would cause:

  • issues with mismatches between wasm-bindgen versions
  • issues with keeping a stable interface with the wasm app
  • gives the idea that the command is compatible with every project that uses wasm which is not the case.

License

Licensed under either of

at your option.

cargo-run-wasm's People

Contributors

liamolucko avatar rukai avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.