Modern Wasm Starter

🛸 Run C++ code on web and create blazingly fast websites! A starter template to easily create WebAssembly packages using type-safe C++ bindings with automatic TypeScript declarations.
Alternatives To Modern Wasm Starter
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Modern Wasm Starter197
8 months ago26October 12, 20221unlicenseTypeScript
🛸 Run C++ code on web and create blazingly fast websites! A starter template to easily create WebAssembly packages using type-safe C++ bindings with automatic TypeScript declarations.
Scala Js Chrome6924 years ago6May 01, 201714mitScala
ScalaJS bindings for Chrome Extention/App and ChromeOS APIs
Feliz.plotly52
3 months ago53June 17, 20215mitF#
Fable bindings written in the Feliz-style for plotly.js.
Ocaml Lmdb40
2 years ago1mitOCaml
Ocaml bindings for lmdb.
Hs Hdf528
10 years ago3Haskell
Low-level typesafe HDF5 bindings
Wlroots Ocaml23
2 years ago3lgpl-2.1OCaml
OCaml bindings to wlroots [experimental]
Tinysqlite15
46 years ago10October 22, 20181mitSwift
A lightweight wrapper for SQLite written in Swift
Observe11
2 years ago1mitTypeScript
Type-safe observable values (made with Deno)
Bs Tape65103 years ago5May 21, 20181iscOCaml
BuckleScript bindings for tape
Dart Rtlsdr5
2 months agootherDart
Dart bindings for librtlsdr.
Alternatives To Modern Wasm Starter
Select To Compare


Alternative Project Comparisons
Readme

Check npm version

Modern WASM Starter

A starter template to easily create WebAssembly packages for npm using type-safe C++ code with automatic declarations. This project should take care of most of the boilerplate code required to create a modern and type-safe WebAssembly project.

Features

Usage

Get started

Use this repo as a template to quickly start your own projects!

Build WebAssembly code

To be able to build WebAssembly code from C++ using Emscripten, you must first install and activate the emsdk. To compile the C++ code to WebAssembly, run the following command from the project's root directory.

npm install

This will create the files source/WasmModule.js and source/WasmModule.d.ts from the C++ code in the wasm directory and transpile everything into a JavaScript module in the dist directory. To build your code as wasm, add it as a CPM.cmake dependency in the CMakeLists.txt file and define the bindings in the wasmGlue.cpp source file. To update the wasm and TypeScript declarations, you can run npm run build:wasm.

Run tests

The following command will build and run the test suite.

npm test

For rapid developing, tests can also be started in watch mode, which will automatically run on any code change to the TypeScript or JavaScript sources.

npm start

Fix code style

The following command will run prettier on the TypeScript and clang-format on the C++ source code.

npm run fix:style

Writing bindings

This starter uses the Glue project to create bindings and declarations. Update the wasmGlue.cpp source files to expose new classes or functions. See the Glue or EmGlue projects for documentation and examples.

Memory management

As JavaScript has no destructors, any created C++ objects must be deleted manually, or they will be leaked. To simplify this, the project introduces memory scopes that semi-automatically take care of memory management. The usage is illustrated below.

import { withGreeter } from "modern-wasm-starter";

// `withGreeter()` will run the callback asynchronously in a memory scope and return the result in a `Promise`
withGreeter(greeterModule => {
  // construct a new C++ `Greeter` instance
  const greeter = new greeterModule.Greeter("Wasm");

  // call a member function
  console.log(greeter.greet(greeterModule.LanguageCode.EN));
  
  // any created C++ objects will be destroyed after the function exits, unless they are persisted
});

To see additional techniques, such as synchronous scopes or persisting and removing values outside of the scope, check out the tests or API.

Popular Bindings Projects
Popular Type Safe Projects
Popular Libraries Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Javascript
Typescript
C Plus Plus
Cpp
Bindings
Cmake
Emscripten
Typesafe