Standalone executables

Bun can embed OpenTUI’s native package binaries in bun build --compile executables when the native package import is statically analyzable.

Linux libc

Linux uses the glibc native package by default. For musl builds, define process.env.OPENTUI_LIBC at build time so Bun can remove the unused branch and embed only the musl package.

await Bun.build({
  entrypoints: ["./app.ts"],
  compile: {
    target: "bun-linux-x64-musl",
    outfile: "./app-linux-x64-musl",
  },
  define: {
    "process.env.OPENTUI_LIBC": JSON.stringify("musl"),
  },
})

Use "glibc" for glibc Linux builds:

define: {
  "process.env.OPENTUI_LIBC": JSON.stringify("glibc"),
}

If process.env.OPENTUI_LIBC is not defined at build time, Bun must keep both Linux native package branches for that architecture because runtime environment selection is still possible.

Native Packages

Make sure the target native packages are present in node_modules before compiling. For multi-platform release builds, install optional native packages for all target OS and CPU combinations before running Bun.build().

bun install --os="*" --cpu="*" @opentui/core@<version>

Alpine

Bun’s Linux musl standalone runtime can require the standard C++ runtime libraries on Alpine. Install them in minimal Alpine images:

apk add --no-cache libstdc++ libgcc