All Projects → TheLartians → Modern Wasm Starter

TheLartians / Modern Wasm Starter

Licence: unlicense
🛸 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.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
cpp
1120 projects

Projects that are alternatives of or similar to Modern Wasm Starter

Dcmjs
dcmjs is a javascript cross-compile of dcmtk (dcmtk.org).
Stars: ✭ 92 (-34.29%)
Mutual labels:  cmake, emscripten, webassembly, wasm, asmjs
Emscripten Docker
Docker image with Emscripten to compile ASM.js and WebAssembly
Stars: ✭ 92 (-34.29%)
Mutual labels:  emscripten, webassembly, wasm, asmjs
TypeScriptXX
🧷 Stay safe! Type-safe scripting for C++ using TypeScriptToLua and CMake with auto-generated declarations.
Stars: ✭ 33 (-76.43%)
Mutual labels:  webassembly, wasm, emscripten, asmjs
Rust Wasm Webpack Tutorial
Finished example project for my guide on setting up a Webpack project with Rust and WebAssembly
Stars: ✭ 122 (-12.86%)
Mutual labels:  webpack, emscripten, webassembly
Securityworker
The best javascript code protection solution ever.
Stars: ✭ 626 (+347.14%)
Mutual labels:  emscripten, webassembly, asmjs
Cppwasm Book
📚 WebAssembly friendly programming with C/C++ -- Emscripten practice
Stars: ✭ 956 (+582.86%)
Mutual labels:  emscripten, webassembly, wasm
Rustynes
👾 An NES emulator by Rust and WebAssembly
Stars: ✭ 399 (+185%)
Mutual labels:  emscripten, webassembly, wasm
Wasmjit
Small Embeddable WebAssembly Runtime
Stars: ✭ 1,063 (+659.29%)
Mutual labels:  emscripten, webassembly, wasm
Cargo Web
A Cargo subcommand for the client-side Web
Stars: ✭ 1,026 (+632.86%)
Mutual labels:  emscripten, webassembly, asmjs
Magnum Plugins
Plugins for the Magnum C++11/C++14 graphics engine
Stars: ✭ 66 (-52.86%)
Mutual labels:  cmake, emscripten, webassembly
Opus Stream Decoder
Instantly decode Ogg Opus audio streams in chunks with JavaScript & WebAssembly (Wasm)
Stars: ✭ 80 (-42.86%)
Mutual labels:  emscripten, webassembly, wasm
Wasmer
🚀 The leading WebAssembly Runtime supporting WASI and Emscripten
Stars: ✭ 11,047 (+7790.71%)
Mutual labels:  emscripten, webassembly, wasm
Lass
👧 Lass scaffolds a modern package boilerplate for Node.js
Stars: ✭ 615 (+339.29%)
Mutual labels:  starter, package, npm
Wasm Loader
✨ WASM webpack loader
Stars: ✭ 604 (+331.43%)
Mutual labels:  webpack, webassembly, wasm
Gub
CLI tool for create an npm package from any repos. 🐳
Stars: ✭ 31 (-77.86%)
Mutual labels:  starter, package, npm
Camaro
camaro is an utility to transform XML to JSON, using Node.js binding to native XML parser pugixml, one of the fastest XML parser around.
Stars: ✭ 438 (+212.86%)
Mutual labels:  emscripten, webassembly, wasm
Asm Dom Boilerplate
A simple boilerplate to start using asm-dom without configuration.
Stars: ✭ 49 (-65%)
Mutual labels:  webassembly, wasm, asmjs
Typescript Webpack Starter
⚡ create-ts-lib: A Starter Kit and a CLI to create your TypeScript / ES6 module bundled by Webpack without thinking about build or unit tests configurations. 🏠
Stars: ✭ 358 (+155.71%)
Mutual labels:  webpack, starter, npm
Wac
WebAssembly interpreter in C
Stars: ✭ 372 (+165.71%)
Mutual labels:  emscripten, webassembly, wasm
Magnum Bootstrap
Bootstrap projects for Magnum C++11/C++14 graphics engine
Stars: ✭ 69 (-50.71%)
Mutual labels:  cmake, emscripten, webassembly

Build 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.

Note: due to what seems to be a compiler bug, some emsdk versions seem to crash the compiler. The most recently tested working version is 1.39.20.

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].