libpack packages Oak programs as standalone, self-contained executables by bundling source code, dependencies, and resources into a single binary.
pack := import('pack')
{ pack: pack, configure: configure } := import('pack')
- Standalone binaries: Creates executable files with embedded Oak runtime
- Dependency bundling: Automatically includes all imported modules
- Virtual filesystem: Embeds resources accessible at runtime
- Cross-platform: Generates executables for target platforms via
--interp - Zero dependencies: Resulting binary requires no external files
- Custom interpreter embedding: Choose which Oak interpreter binary to bundle
Configures the pack system.
Parameters (config object):
entry- Entry point file (required)output- Output executable path (required)includes- Additional modules to bundleincludeVFS- Files/directories for virtual filesystem. Supportstarget:sourcemapping syntax (e.g.,views:templates/), comma-separated values, and recursive directory walkinginterp- Path to the Oak interpreter binary to embed in the packed output. Defaults to the currently running interpreter. Use this to cross-compile for a different platform or OS by pointing to a different-platform Oak binaryoakExe- Path to the Oak executable used to run the build subprocess. Defaults to the current process executableweb?- Experimental: web target for pack (boolean)wasm?- Experimental: wasm target for pack (boolean)log- Logging functionabort- Error handlerexec- Custom exec function (default:execbuiltin)
{ configure: configure } := import('pack')
configure({
entry: 'src/main.oak'
output: 'myapp'
includeVFS: 'assets/'
})
Executes the packing process.
{ configure: configure, pack: pack } := import('pack')
configure({
entry: 'app.oak'
output: 'dist/myapp'
})
pack()
println('Executable created!')
configure({
entry: 'main.oak'
output: 'app'
includeVFS: 'templates/'
})
// Runtime access:
// Virtual.readFile('templates/index.html')
configure({
entry: 'main.oak'
output: 'app'
includeVFS: [
'templates/'
'static/css/'
'static/js/'
]
})
configure({
entry: 'main.oak'
output: 'app'
includeVFS: [
'views:templates/' // templates/ → views/
'assets:static/' // static/ → assets/
]
})
// Runtime: Virtual.readFile('views/index.html')
{ configure: configure, pack: pack } := import('pack')
configure({
entry: 'hello.oak'
output: 'hello'
})
pack()
{ configure: configure, pack: pack } := import('pack')
configure({
entry: 'server.oak'
output: 'webserver'
includes: ['lib/http.oak', 'lib/router.oak']
includeVFS: [
'static/css/'
'static/js/'
'templates/'
]
})
pack()
println('Packaged web server created!')
{ configure: configure, pack: pack } := import('pack')
{ printf: printf } := import('fmt')
configure({
entry: 'src/cli.oak'
output: 'bin/mytool'
includeVFS: 'config/'
log: fn(msg) {
printf('[PACK] {{0}}', msg)
}
})
pack()
Use --interp to point to a different-platform Oak binary for cross-compilation:
{ configure: configure, pack: pack } := import('pack')
{ printf: printf } := import('fmt')
platforms := [
{ name: 'linux-x64', output: 'dist/app-linux', interp: 'bin/oak-linux-amd64' }
{ name: 'windows-x64', output: 'dist/app-windows.exe', interp: 'bin/oak-windows-amd64.exe' }
{ name: 'darwin-x64', output: 'dist/app-macos', interp: 'bin/oak-darwin-amd64' }
]
each(platforms, fn(platform) {
printf('Building for {{0}}...', platform.name)
configure({
entry: 'src/main.oak'
output: platform.output
interp: platform.interp
includeVFS: 'resources/'
})
pack()
printf('✓ {{0}} complete', platform.name)
})
Files included via includeVFS are accessible through the Virtual library:
// At build time
configure({
includeVFS: 'templates/'
})
// At runtime in main.oak
Virtual := import('Virtual')
template := Virtual.readFile('templates/index.html')
if template != ? -> {
println('Template loaded: ' + string(len(template)) + ' bytes')
}
- Parse entry point
- Resolve dependencies (imports)
- Collect VFS files from
includeVFS - Bundle all Oak code into single AST
- Embed runtime + code + VFS data
- Generate executable binary
- Write output file with execute permissions
configure({
entry: 'app.oak'
output: 'myapp' // Creates executable 'myapp'
})
configure({
entry: 'app.oak'
output: 'myapp.exe' // Creates 'myapp.exe'
})
The packed binary consists of the Oak interpreter with appended data segments:
- Oak bundle — The bundled Oak source code, followed by its byte-length and the magic bytes
oak \x19\x98\x10\x15 - VFS data — Serialized virtual filesystem contents, followed by its byte-length and magic bytes
vfs \x01\x00\x00\x00
At runtime, the interpreter detects these appended segments and loads the bundle and VFS automatically.
oak pack --entry [src] --output [dest] [options]
Options:
--entry— Entrypoint for the bundle--output/-o— Output binary path--include— Comma-separated list of modules to include explicitly--interp— Path to the Oak interpreter to embed (default: current process)
build: Compiles to JavaScript/WebAssembly/Oak source
pack: Creates standalone native executable
// build - outputs JavaScript
build.configure({ entry: 'app.oak', output: 'app.js', web?: true })
build.compile()
// pack - outputs executable binary
pack.configure({ entry: 'app.oak', output: 'app' })
pack.pack()
- Uses
buildlibrary internally for bundling - Embeds Oak runtime into output binary
- Sets executable permissions on Unix platforms
- Recursively processes directories in
includeVFS - Preserves directory structure in virtual filesystem
- Uses
pack-utilsfor platform-specific operations
- Output file size includes runtime + all dependencies
- No compression of embedded resources
- Cannot update VFS files after packing
- Limited to including text files (binary files may have issues)
- No code signing or notarization
- No custom runtime flags
- CLI tools: Self-contained command-line utilities
- Web servers: Embed templates and static assets
- Scripts: Distribute Oak scripts as executables
- Games: Bundle assets with game logic
- Installers: Create setup programs
- Pack time scales with number of files in VFS
- Runtime VFS access is in-memory (fast)
- Larger VFS increases binary size
- First load extracts VFS to memory
- build.md - Oak compiler and bundler
- virtual-fs.md - Virtual filesystem documentation
- pack-utils.md - Pack utility functions
Virtuallibrary - Runtime VFS access