Coder Social home page Coder Social logo

wasmbuild's Introduction

wasmbuild

A build tool to generate wasm-bindgen glue code for Deno and the browser.

Setup

Add a task to the deno.json file in your project:

{
  "tasks": {
    "wasmbuild": "deno run -A https://deno.land/x/wasmbuild@VERSION_GOES_HERE/main.ts"
  }
}

Scaffold project (Optional)

To create a starter Rust crate in an rs_lib subfolder of your project, run:

$ deno task wasmbuild new

Building

To build, invoke deno task wasmbuild in your project:

$ deno task wasmbuild

Bindings will be generated at ./lib/<crate-name>.generated.js. Import the instantiate function and call it asynchronously to get the exports:

import { instantiate } from "./lib/deno_test.generated.js";

const { greet } = await instantiate();
greet("Deno");

Or instantiate and use the exports:

import { greet, instantiate } from "./lib/deno_test.generated.js";

await instantiate();
greet("Deno");

Compression

When instantiating, you might want to decompress Wasm bytes.

import { instantiate } from "./lib/deno_test.generated.js";
import { decompress } from "https://deno.land/x/[email protected]/mod.ts";

await instantiate(decompress);

Note, however, wasmbuild CLI does not compress the Wasm file automatically.

Checking output is up-to-date

It may occur that someone updates the Rust code, but forgets to build when submitting a PR. To ensure that the output is up-to-date, you can use the --check flag:

$ deno task wasmbuild --check

For example, in a GitHub action:

- name: Check Wasm up-to-date
  run: deno task wasmbuild --check

CLI flags

  • --debug - Build without optimizations.
  • --project <crate_name> / -p <crate_name> - Specifies the crate to build when using a Cargo workspace.
  • --out <dir_path> - Specifies the output directory. Defaults to ./lib
  • --js-ext <ext_no_period> - Extension to use for the wasm-bindgen JS file. Defaults to js.
  • --all-features - Build the crate with all features.
  • --no-default-features - Build the crate with no default features.
  • --features - Specify the features to create. Specify multiple features quoted and with spaces (ex. --features "wasm serialization").
  • --sync - Generate a synchronous module that stores the Wasm module inline as base64 text.
  • --skip-opt - Skip running wasm-opt.
  • --check - Checks if the output is up-to-date.

wasmbuild's People

Contributors

dsherret avatar g-plane avatar littledivy avatar lucacasonato avatar nissy-dev avatar ultirequiem avatar wilcokruijer 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.