@boltffi/runtime

中文文档
0.32.1发布于 2026/10/30MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 19.2万

WASM runtime for BoltFFI generated TypeScript bindings

原始使用文档
文档目录6 节
  1. Installation
  2. Usage
  3. Example
  4. Rust dependencies that call JavaScript
  5. Documentation
  6. License

@boltffi/runtime

WASM runtime for BoltFFI generated TypeScript bindings.

Installation

npm install @boltffi/runtime

Usage

This package is used internally by BoltFFI-generated WASM bindings. You don't need to install it directly - it's bundled with your generated package when you run boltffi pack wasm.

Example

When you run boltffi pack wasm, the generated TypeScript uses this runtime:

import { distance } from 'your-package';

const d = distance({ x: 0, y: 0 }, { x: 3, y: 4 });
console.log(d); // 5.0

Rust dependencies that call JavaScript

An exported Rust function can use a dependency such as uuid with its v4 and js features. The function still uses #[boltffi::export]. No #[wasm_bindgen] attribute is needed on the BoltFFI API.

boltffi pack wasm detects wasm-bindgen metadata in the compiled artifact and runs the matching wasm-bindgen CLI before stripping or optimizing it. The generated package contains both the BoltFFI bindings and the dependency's JavaScript bindings, connected to the same Wasm instance. Cargo's original artifact is preserved, including when packing again with --no-build.

Install the exact CLI version named in the pack error with cargo install wasm-bindgen-cli --version =VERSION --locked. An existing executable can be selected with BOLTFFI_WASM_BINDGEN or targets.wasm.wasm_bindgen_cli in boltffi.toml. Modules without wasm-bindgen metadata do not need this tool. TypeScript compilation requires this runtime and, for the Node entry, @types/node to be installed where the output's parent directories can resolve them.

The generated loaders support Node synchronous initialization, asynchronous initialization, browser fetches, and bundlers. A JavaScript glue module owns one Wasm instance. Initializing it again, concurrently, or after failed dependency startup is rejected. Local and inline JavaScript snippets are included; npm imports and dynamically computed module paths are rejected during packaging.

Functions are available during dependency startup so JavaScript can call back into BoltFFI. Computed constants are read after startup and are available when initialization completes. Their Rust conversions can then use JavaScript too.

This integration targets wasm32-unknown-unknown with non-shared memory and panic=abort. Threads, JSPI, and panic unwinding are outside this contract. The host must provide the JavaScript APIs a dependency calls; browser DOM APIs, for example, are unavailable in ordinary Node programs. Uncaught JavaScript exceptions and Rust traps retain their WebAssembly semantics. They do not become BoltFFI Result values or make the instance safe to reuse. If polling or cancelling a future throws, all pending BoltFFI futures reject and that instance's async manager stops polling. Discard the failed instance.

BoltFFI async exports still require Send futures. A wasm-bindgen JsFuture does not satisfy that bound. A JavaScript task can complete a channel awaited by a BoltFFI future, as the Wasm interop demo demonstrates.

Documentation

License

MIT

版本与发布记录

@boltffi/runtime 共发布 34 个版本,首次发布于 2026/02/17;过去 12 个月发布了 34 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.32.1latest2026/10/309 天前
0.32.02026/10/2811 天前
0.31.12026/10/1424 天前
0.31.02026/09/291 个月前
0.30.12026/08/182 个月前
0.30.02026/08/152 个月前

关于 @boltffi/runtime 的常见问题

@boltffi/runtime 是什么?

WASM runtime for BoltFFI generated TypeScript bindings

如何安装 @boltffi/runtime?

在项目目录运行 npm install @boltffi/runtime,或使用 pnpm add / yarn add / bun add。

@boltffi/runtime 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@boltffi/runtime 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@boltffi/runtime 可以商用吗?

@boltffi/runtime 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@boltffi/runtime 的下载量有多少?

根据 npm 官方下载统计,@boltffi/runtime 在 2026/10/09 – 2026/11/07 这 30 天内被下载 191,687 次,日均约 6,390 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@boltffi/runtime 还在维护吗?

最新版本 0.32.1 发布于 2026/10/30(9 天前);至今共发布 34 个版本,其中过去 12 个月发布了 34 个;首次发布于 2026/02/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。