(sigil build native)
Native Package Support
This module provides functions for detecting and building native packages (packages with C code) during the bundling process.
When an app depends on packages with native code (c-sources in their library definitions), we need to:
- Detect which packages have native code
- Generate an entrypoint that initializes all native modules
- Compile the native code
- Link a custom runtime
Exports
package-has-native-code?procedureCheck if a package has native code (C sources with native-init).
A package has native code if it has a libraries: field with at least one library that has c-sources and native-init.
find-native-packagesprocedureFind all native packages from a list of loaded packages.
Returns a list of packages that have native code.
collect-native-init-functionsprocedureCollect all native-init function names from packages.
Returns a list of strings (C function names) in dependency order.
collect-native-include-dirsprocedureCollect all C include directories from native packages.
Returns an alist of (package-path . include-dirs).
collect-native-sourcesprocedureCollect all C source files from native packages.
Returns an alist of (package-name . source-patterns).
collect-native-link-flagsprocedureCollect all linker flags from native packages.
Returns a flat list of linker flags in dependency order.
generate-native-entrypointprocedureGenerate the C code for a custom runtime entrypoint.
This creates a main.c that:
- Includes sigil.h and necessary headers
- Declares extern for each native init function
- Creates the VM and calls native init functions
- Reads manifest from bundled archive (if available)
- For scripts: loads the script with (load)
- For programs: imports entry module and calls (main)
init-functions: list of C function name strings entry-module: string like "(my-app main)" - fallback if no manifest
Returns the generated C code as a string.
entrypoint-headersprocedureGenerate common C headers for entrypoints.
entrypoint-native-declarationsprocedureGenerate native module forward declarations.
entrypoint-helper-functionsprocedureGenerate getexedir and path_join helper functions.
entrypoint-main-prologueprocedureGenerate main function prologue: exe_dir detection and VM creation.
entrypoint-native-initprocedureGenerate native module initialization calls.
entrypoint-lib-path-setupprocedureGenerate library path setup (adds ../lib relative to binary).
entrypoint-main-epilogueprocedureGenerate main function epilogue: cleanup and return.
generate-dev-entrypointprocedureGenerate a dev build entrypoint with native module support.
This is similar to generate-native-entrypoint but includes DEV_BUILD features like boot-eval command and dev library path setup.
init-functions: list of C function name strings entry-module: string like "(sigil cli)"
Returns the generated C code as a string.
generate-test-entrypointprocedureGenerate a test harness entrypoint with native module support.
This generates a standalone test runner that initializes native modules and then calls (sigil test cli) test-main with command-line arguments.
init-functions: list of C function names to call for native init
Returns the generated C code as a string.