(sigil build bundle)
Bundle Creation Library
This library provides functionality for creating standalone bundled executables with embedded modules and assets. It wraps the (sigil archive) module's low-level ZIP operations.
A bundle is:
- A base executable (sigil or a static musl build)
- A ZIP archive appended to it containing:
- Compiled bytecode modules (.sgb files)
- Assets (images, sounds, etc.)
- A manifest listing the entry point
- A trailer with magic "SGLPAK" and offset to the archive
The bundled executable:
- Loads modules from the embedded archive first
- Falls back to filesystem if not found
- Runs the entry point specified in the manifest
Example usage:
(define bundle (make-bundle "my-app")) (bundle-set-entry! bundle '(my-app main)) (bundle-add-module! bundle "lib/my-app.sgb" "my-app/main.sgb") (bundle-add-asset-directory! bundle "assets") (bundle-write! bundle "dist/my-app")
Exports
bundleprocedureA bundle being constructed for creating standalone executables.
Bundles package compiled modules and assets into a single executable by appending a ZIP archive to the base sigil-run binary.
bundle?procedureTest if a value is a bundle struct.
bundle-nameprocedureBundle name (used for output filename).
bundle-entryprocedureEntry point as '((library-name ...) proc-name), or #f for no entry.
bundle-modulesprocedureCompiled modules as ((archive-path . bytevector) ...) alist.
bundle-assetsprocedureStatic assets as ((archive-path . bytevector) ...) alist.
bundle-base-executableprocedurePath to base executable to append bundle to, or #f for default sigil-run.
bundle-compress?procedureIf #t, compress bundle entries with DEFLATE.
bundle-stdlib-modulesprocedureList of stdlib module paths included (for rebundling support).
bundle-app-modulesprocedureList of application-specific module paths.
bundle-script?procedureIf #t, this is a script bundle that runs top-level code without calling main.
bundle-app-versionprocedureApplication version string (from package.sgl version: field), or #f if absent. Read at runtime via (app-version) from (sigil meta).
bundle-app-commitprocedureGit provenance of the consuming application workspace.
bundle-file-assetsprocedureDeferred assets as ((archive-path . source-path) ...) alist.
set-bundle-entry!procedureSet the entry field of a bundle struct.
set-bundle-modules!procedureSet the modules field of a bundle struct.
set-bundle-assets!procedureSet the assets field of a bundle struct.
set-bundle-base-executable!procedureSet the base-executable field of a bundle struct.
set-bundle-stdlib-modules!procedureSet the stdlib-modules field of a bundle struct.
set-bundle-app-modules!procedureSet the app-modules field of a bundle struct.
set-bundle-script?!procedureSet the script? field of a bundle struct.
set-bundle-app-version!procedureSet the app-version field of a bundle struct.
set-bundle-app-commit!procedureSet the app-commit field of a bundle struct.
set-bundle-file-assets!procedureSet the file-assets field of a bundle struct.
make-bundleprocedureCreate a new bundle
bundle-set-entry!procedureSet the entry point for the bundle
bundle-set-base!procedureSet the base executable
bundle-set-stdlib-modules!procedureSet stdlib module paths (for rebundling support)
bundle-set-app-modules!procedureSet app module paths (for rebundling support)
bundle-set-script!procedureSet script mode (scripts run top-level code, programs call main)
bundle-set-app-version!procedureSet the application version (from package.sgl version: field). Recorded in MANIFEST.sgl so (app-version) from (sigil meta) can return it instead of falling back to the sigil runtime version.
bundle-add-module!procedureAdd a module from memory archive-path: path within archive (e.g., "my-app/main.sgb") content: bytevector or string containing the module
bundle-add-module-file!procedureAdd a module from a file
bundle-add-asset!procedureAdd an asset from memory
bundle-add-asset-file!procedureAdd an asset from a file
bundle-add-file-asset!procedureAdd a file-backed asset without reading its contents into memory.
The source file is read when bundle-write! runs. Keep it unchanged until the write finishes. Archive names must be unique across modules, in-memory assets and file-backed assets; collisions are rejected before writing. Existing bundle-add-asset-file! keeps its eager-read behavior.
bundle-add-asset-directory!procedureAdd all files from a directory as assets
library-name->archive-pathprocedureThese helpers make it easy to bundle standard library modules with your application. Convert a library name to its archive path e.g., (sigil core) -> "lib/sigil/core.sgb"
library-name->file-pathprocedureConvert a library name to its filesystem path relative to lib-path e.g., (sigil core), "build/lib" -> "build/lib/sigil/core.sgb"
bundle-add-stdlib!procedureAdd a standard library module to the bundle by name lib-name: library name as a list of symbols, e.g., (sigil core) lib-path: optional path to the lib directory (default: build/boot/lib) Returns the bundle, or raises an error if the library isn't found
bundle-add-core-stdlib!procedureAdd the core standard library modules needed by most applications This includes (sigil core) which provides essential macros and primitives lib-path: optional path to lib directory (default: build/boot/lib)
read-file-stringprocedureRead entire file as string (for text files)
read-file-bytesprocedureRead entire file as bytevector (for binary files)
bundled?procedureThese functions enable any bundled sigil binary to create new standalone executables without external dependencies.
When running from a bundled binary:
- Extract the base executable (first N bytes before archive)
- Read stdlib modules from current bundle's manifest
- Copy stdlib modules to new bundle
- Add new app modules
- Create new bundle with combined modules Check if currently running from a bundled executable
get-bundled-manifestprocedureParse the manifest from current bundle Returns an alist with 'name, 'entry, 'version, 'stdlib-modules, 'app-modules
parse-manifestprocedureParse manifest string into alist
parse-manifest-fieldsprocedureParse manifest fields into alist
get-bundled-stdlib-modulesprocedureGet stdlib module paths from current bundle's manifest Returns list of archive paths or '() if not bundled or no stdlib
bundle-add-stdlib-from-bundle!procedureAdd stdlib modules from current bundle to a new bundle This copies all stdlib modules from the running bundle
sort-bundle-entriesprocedureWrite the bundle to an output path Creates: output-path (executable with embedded archive) Sort bundle entries ((archive-path . content) pairs) by archive path so the emitted ZIP order is deterministic regardless of the readdir order in which the entries were collected. list-sort is a stable merge sort; archive paths within a bundle are unique, so the ordering is total. This is the key to byte-reproducible native release bundles.
sort-manifest-modulesprocedureSort a manifest module list deterministically. Elements are archive paths (strings) on the native/release path, but other bundle paths may pass module-name data; sorting by the printed representation is total and stable for either form.
bundle-write-zip!procedureWrite the module and asset ZIP to a private path for the caller to append to a baseline or pass to the executable link.
generate-manifestprocedureGenerate the manifest file content Includes stdlib-modules and app-modules lists for rebundling support. Format version 5 adds the optional (app-commit "...") field. Older bundles without this field cause (app-version) from (sigil meta) to fall back to the sigil runtime version.
find-base-executableprocedureFind the base executable to use Returns either a file path (string) or bytevector (if extracted from bundle)
find-default-base-executableprocedureFind the default sigil executable If running from a bundled binary, extracts and returns the base as bytevector Otherwise, looks for sigil in standard locations
find-existing-fileprocedureFind first existing file in list
bundle-transform-base!procedureTransform a bundle's executable base without changing its archive.
TRANSFORM receives a private file containing only the executable bytes. It may modify that file (for example with strip or patchelf), including changing its size. Preserve the source ZIP exactly and update its SGLPAK trailer offset. Publish OUTPUT only after transformation succeeds and SOURCE remains unchanged. SOURCE and OUTPUT may name the same file. The operation streams data in bounded chunks and requires temporary disk space for the base, archive and completed output. SOURCE must be SGLPAK.
make-trailerprocedureCreate the 16-byte bundle trailer Format: "SGLPAK" (6) + reserved (2) + offset (8 little-endian)
write-u64-le!procedureWrite uint64 in little-endian format to bytevector
make-executableprocedureMake a file executable (Unix-specific)
alist-getprocedureHelper for alist lookup
create-bundlevariablecreate-bundle action for use in build tasks Creates a standalone bundled executable.
find-static-base-executableprocedureFind static (musl) base executable
ensure-directoryprocedureHelper: ensure directory exists
bundle-set-app-commit!variable(No description)
bundle-write!variable(No description)