Bun single-file executable
Embed Takumi's native addon in an executable from bun build --compile, which leaves the addon out on its own.
bun build --compile bundles your code into one executable, but it leaves out the native addon takumi-js loads at runtime, so the executable fails with Cannot find native binding on another machine. Embed the addon as a file and point Takumi at it.
Embed the addon
Import the addon of the platform you build for with type: "file", and set TAKUMI_CORE_TARGET to its path before takumi-js loads. A static import would load takumi-js first, so import it dynamically.
import addon from "@takumi-rs/core-linux-x64-gnu/core.linux-x64-gnu.node" with { type: "file" };
process.env.TAKUMI_CORE_TARGET = addon;
const { render } = await import("takumi-js");
const png = await render(`<div style="font-size: 64px">Hello Takumi</div>`, {
width: 1200,
height: 630,
});
await Bun.write("hello.png", png);Build for another platform
The addon package matches the platform it was built for, such as @takumi-rs/core-darwin-arm64 or @takumi-rs/core-linux-x64-musl. Install the package of the target platform, import its .node file, and pass the same target to bun build --compile --target.
On an x86-64 CPU without AVX, such as some virtual machines, the WebAssembly backend is no way
around this. JavaScriptCore, Bun's engine, turns WebAssembly SIMD off on such CPUs, and Takumi's
WebAssembly binary uses SIMD, so a module option fails with WebAssembly.Module doesn't parse.
Last updated on