(sigil build bundle)
(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.
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.
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-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-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
bundle-write!procedureWrite the bundle to an output path Creates: output-path (executable with embedded archive)
generate-manifestprocedureGenerate the manifest file content Includes stdlib-modules and app-modules lists for rebundling support
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
combine-executable-archiveprocedureCombine executable with archive and write trailer exe-or-path: either a file path (string) or bytevector (extracted base)
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)
parse-bundle-optionsprocedureParse bundle options
alist-getprocedureHelper for alist lookup
find-static-base-executableprocedureFind static (musl) base executable
ensure-directoryprocedureHelper: ensure directory exists