当前位置: 首页 > 软件库 > 开发工具 > >

modern-wasm-starter

授权协议 Unlicense License
开发语言 C/C++
所属分类 开发工具
软件类型 开源软件
地区 不详
投 递 者 羊舌庆
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

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

 相关资料
  • Modern 是一个 Windows Runtime 的标准 C++ 语言项目。Modern 编译器生成一个只有 header 的库,提供给 C++ 开发者,可以使用 first-class 访问现代化 Windows API。

  • Wasm-bpf 是一个 WebAssembly eBPF 库和运行时, 基于 CO-RE(一次编写 – 到处运行) libbpf 和 wasm-micro-runtime 实现。 Wasm 最初是以浏览器安全沙盒为目的开发的,发展到目前为止,WebAssembly 已经成为一个用于云原生软件组件的高性能、跨平台和多语言软件沙箱环境,Wasm 轻量级容器也非常适合作为下一代无服务器平台运行时。另一

  • �� ✨ wasm-pack Your favorite Rust → Wasm workflow tool! Docs | Contributing | Chat Built with �� �� by The Rust and WebAssembly Working Group About This tool seeks to be a one-stop shop for building a

  • wasm-bindgen 是一个用于促进 wasm 模块和 JavaScript 之间进行高级交互的项目,改进 JavaScript 和 Rust 代码之间的互操作性。 目前这个工具是基于 Rust 编写的,不过它的底层基础是独立于语言的,随着这个工具日趋稳定,它还可以用于像 C/C++ 这种语言。 显著特性 将 JavaScript 功能导入到 Rust,如 DOM 操作、控制台日志记录以及性能

  • Modern ClojureScript (modern-cljs) 是一系列的 ClojureScript (CLJS) 教程,指导如何创建和运行 ClojureScript 项目。 CLJS 是 Clojure 编程语言的编译器,目的是转换成 JavaScript,这样可以运行在 Web 浏览器和其他客户端或者服务端 JavaScript 解析器中。 Modern ClojureScript 是使用 Clojure 语言编写的。

  • Modern JavaScript Video Project This is the repository for the project we'll refactor together during TylerMcGinnis.com's "Modern JavaScript" course, for more information on the course see tylermcginn