bkg is a CLI tool that can generate self-sufficient binaries from your Bun code for multiple platforms.
Fastest way to install:
curl -fsSL https://github.com/theseyan/bkg/raw/main/install.sh | sudo sh
OR, get the latest release for your platform (bkg_runtime-
binaries are not required, they will be automatically downloaded).
Run bkg --help
to get a list of options on usage:
Usage: bkg [options] <ProjectDirectory>
Example: bkg myProject -o myapp
Options:
-h, --help Display this help message.
-o, --output <str> Output file name
-t, --target <str> Target architecture to build for (default is Host)
--targets Display list of supported targets
--runtime <str> Path to custom Bun binary (not recommended)
-v, --version Display bkg version.
<str>...
bkg.config.json
bkg assumes index.js
to be the entry point of your application. This can be changed by creating bkg.config.json
at the root directory of your project:
{
"entry": "app.ts"
}
Since v0.0.4
, bkg has support for an experimental LTO mode.
When LTO is enabled, bkg will attempt to statically analyze your code, bundle sources and perform tree shaking/minification at compile time. For large projects, this drastically reduces application size and boosts cold startup times.
To enable LTO, compile with --lto
or add the following field to bkg.config.json
:
{
"lto": {
"format": "cjs"
}
}
Only reachable code is packaged into the executable; To include additional assets, use --include "path/to/files/*"
flag or set the lto.includes
field in configuration with a comma-separated list of glob file paths.
pkg
bkg and pkg (Node) have a number of differences arising either from a design decision or a Bun limitation:
v8::ScriptCompiler
yet, hence sources are kept intact in the compiled executable.fs
operations with relative paths, as there is no guarantee where the sources may be placed at runtime. This will be fixed when I complete overriding some of fs
default paths.bkg is written in Zig and compilation is fairly straightforward. The prerequisites are:
# Clone the repository and update submodules
git clone https://github.com/theseyan/bkg && cd bkg
git submodule update --init --recursive
# Build for x86_64-linux
zig build -Drelease-fast -Dtarget=x86_64-linux
# [Optional] Build runtime for x86_64-linux & strip it
zig build-exe -target x86_64-linux src/bkg_runtime.zig -fstrip -lc deps/lz4/lib/lz4.c deps/microtar/src/microtar.c --pkg-begin known-folders deps/known-folders/known-folders.zig --pkg-end
# Run bkg
./zig-out/bin/bkg --help
# OR, build runtime and CLI for all platforms
# Generated executables are placed in /build
chmod +x build.sh && ./build.sh
Release v0.1.0:
LZ4_compress_HC
instead of through the filesystemRoadmap: v1.0
node_modules
. Ideally, this will be replaced by Bun's own bundler.bkg.config.json
Optimizer Progress: See bOptimizer.