sigildocs

(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:

  1. A base executable (sigil or a static musl build)
  2. A ZIP archive appended to it containing:
  • Compiled bytecode modules (.sgb files)
  • Assets (images, sounds, etc.)
  • A manifest listing the entry point
  1. 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

bundleprocedure

A 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?procedure

Test if a value is a bundle struct.

bundle-nameprocedure

Bundle name (used for output filename).

bundle-entryprocedure

Entry point as '((library-name ...) proc-name), or #f for no entry.

Compiled modules as ((archive-path . bytevector) ...) alist.

bundle-assetsprocedure

Static assets as ((archive-path . bytevector) ...) alist.

Path to base executable to append bundle to, or #f for default sigil-run.

If #t, compress bundle entries with DEFLATE.

List of stdlib module paths included (for rebundling support).

List of application-specific module paths.

If #t, this is a script bundle that runs top-level code without calling main.

Set the entry field of a bundle struct.

Set the modules field of a bundle struct.

Set the assets field of a bundle struct.

Set the base-executable field of a bundle struct.

Set the stdlib-modules field of a bundle struct.

Set the app-modules field of a bundle struct.

Set the script? field of a bundle struct.

make-bundleprocedure

Create a new bundle

Set the entry point for the bundle

Set the base executable

Set stdlib module paths (for rebundling support)

Set app module paths (for rebundling support)

Set script mode (scripts run top-level code, programs call main)

Add a module from memory archive-path: path within archive (e.g., "my-app/main.sgb") content: bytevector or string containing the module

Add a module from a file

Add an asset from memory

Add an asset from a file

Add all files from a directory as assets

These 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"

Convert a library name to its filesystem path relative to lib-path e.g., (sigil core), "build/lib" -> "build/lib/sigil/core.sgb"

Add 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

Add 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 entire file as string (for text files)

Read entire file as bytevector (for binary files)

bundled?procedure

These functions enable any bundled sigil binary to create new standalone executables without external dependencies.

When running from a bundled binary:

  1. Extract the base executable (first N bytes before archive)
  2. Read stdlib modules from current bundle's manifest
  3. Copy stdlib modules to new bundle
  4. Add new app modules
  5. Create new bundle with combined modules Check if currently running from a bundled executable

Parse the manifest from current bundle Returns an alist with 'name, 'entry, 'version, 'stdlib-modules, 'app-modules

Parse manifest string into alist

Parse manifest fields into alist

Get stdlib module paths from current bundle's manifest Returns list of archive paths or '() if not bundled or no stdlib

Add stdlib modules from current bundle to a new bundle This copies all stdlib modules from the running bundle

bundle-write!procedure

Write the bundle to an output path Creates: output-path (executable with embedded archive)

Generate the manifest file content Includes stdlib-modules and app-modules lists for rebundling support

Find the base executable to use Returns either a file path (string) or bytevector (if extracted from bundle)

Find 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 first existing file in list

Combine executable with archive and write trailer exe-or-path: either a file path (string) or bytevector (extracted base)

make-trailerprocedure

Create the 16-byte bundle trailer Format: "SGLPAK" (6) + reserved (2) + offset (8 little-endian)

write-u64-le!procedure

Write uint64 in little-endian format to bytevector

Make a file executable (Unix-specific)

Parse bundle options

alist-getprocedure

Helper for alist lookup

Find static (musl) base executable

Helper: ensure directory exists