(sigil build module-deps)
Module Dependency Tracking
This library provides dependency tracking for .sgl modules to enable:
- Correct build ordering (dependencies compiled before dependents)
- Incremental builds (skip unchanged modules via mtime checks)
- Future tree-shaking support for bundles
Example usage: (define source-files (glob "src/*/.sgl")) (define lib-paths '("build/lib" "~/.sigil/lib")) (compile-modules-incremental source-files "build/lib" lib-paths)
Exports
call-with-compiler-input-observationprocedureRun one read-only planning calculation with its own inspection scope. THUNK receives a content hasher. Tasks, compiler callbacks and writes must run outside this scope. Nested calls and exceptions restore it.
extract-module-importsvariableExtract source imports using FEATURE-SET, or current features for #f. An explicit list keeps target planning independent of host features.
read-file-formsprocedureRead ordinary forms without executing a language reader.
extract-imports-from-formsvariableExtract imports from a list of top-level forms. Looks for (define-library ...) or (library ...) forms. A file with no library form is a script: its top-level (import ...) forms (directly or inside a top-level cond-expand clause) are its imports. Such a file is loaded at runtime rather than imported (sigil-web-repl's src/main.sgl is the case), and its imports are dependency edges like any other so the build order and the cache identity include them (t-7d7e80).
library-form-present?procedureDoes a form list contain a library declaration form at top level?
extract-script-importsvariableImports of a script-style file: every top-level (import ...) plus those in the selected clause of a top-level (cond-expand ...). The declaration walker (extract-imports-from-decls) already handles exactly these two shapes and ignores everything else.
extract-imports-from-libraryvariableExtract imports from a define-library form. Handles: (define-library (name) (import ...) (export ...) ...) Also descends into (cond-expand ...) library-declaration clauses, selecting the branch that matches the BUILD-TARGET feature set (the same set the compiler's cond-expand sees — see feature-test-satisfied?). Without this, an (import ...) declared inside a cond-expand clause is invisible to the native module-meta extractor, so web-native-entry's topological init order misses that dependency edge and a re-export through such a facade never materializes under native codegen (t-0c0b).
extract-imports-from-declsvariableExtract imports from a list of library declarations (the body of a define-library or of a matching cond-expand clause).
extract-imports-from-cond-expandvariableGiven the clauses of a (cond-expand clause ...) form, return the imports of the first clause whose feature requirement is satisfied (mirroring R7RS cond-expand and the compiler's branch selection). An else clause matches unconditionally.
feature-test-satisfied?variableEvaluate a cond-expand feature requirement against the current build's feature set. Supports feature identifiers and (and ...)/(or ...)/ (not ...) combinators, matching cps_eval_feature_test in the compiler. Library presence follows cps_eval_feature_test: it tests the compiler's loaded registry, without loading or executing a prospective provider.
extract-import-setsprocedureExtract library names from import sets. Handles import set modifiers: only, except, prefix, rename
unwrap-import-setprocedureUnwrap import set modifiers to get the base library name. (only (lib name) ...) -> (lib name) (except (lib name) ...) -> (lib name) (prefix (lib name) ...) -> (lib name) (rename (lib name) ...) -> (lib name)
extract-library-nameprocedureExtract library name from a define-library form or bootstrap module creation form. (sigil core) uses %make-module instead of define-library, but native sidecar generation still needs a stable module name for object naming and reachability metadata. Returns the library name as a list of symbols.
library-name-to-pathprocedureConvert a library name to a relative file path. (sigil io) -> "sigil/io" (srfi srfi-9) -> "srfi/srfi-9"
resolve-module-pathprocedureResolve a library name to a file path. First searches source-files for .sgl, then lib-paths for .sgb. Returns: (cons 'source path) | (cons 'compiled path) | #f
find-compiled-fileprocedureFind a compiled file in lib-paths. Checks each path for <lib-path>/<rel-path>.sgb
validate-module-imports!procedureReject unresolved imports before a build can publish or cache outputs. Source fallbacks and modules registered by native extensions are valid providers too; the cache graph intentionally models them separately.
validate-module-import-names!procedureValidate selected compiler imports against file or linked C providers.
build-module-graphprocedureBuild a dependency graph for source files. Returns an alist of (source-path . (list of dependency paths)) Dependencies can be source paths or compiled paths.
compiler-input-hintsprocedureReturn SRC's complete ordinary dependency closure from GRAPH. Entries retain the existing (source . path) / (compiled . path) shape. This is compiler-input closure, not a second graph or cache.
compiler-selected-inputsprocedureReturn the selected identity and imports observed in this invocation.
write-compiler-input-metadata!procedureSchema-1 dependency metadata travels beside ordinary bytecode. It is not executable and is published atomically; compiled-only traversal fails closed when it is absent or malformed.
topological-sort-modulesprocedureTopologically sort source files by dependencies. Returns files in order: dependencies before dependents. Only sorts source files; compiled dependencies are not included in output.
sort-modules-by-depsprocedureSort source files by their dependencies. Simple wrapper that builds the graph and returns sorted file list. source-files: list of .sgl file paths lib-paths: list of paths to search for compiled dependencies Returns: source files in dependency order (dependencies first)
filter-source-depsprocedureFilter graph to only include source file dependencies. Removes compiled (.sgb) dependencies.
kahn-process-modulesprocedureKahn's algorithm main loop (module-specific version).
decrement-in-degrees-modulesprocedureDecrement in-degrees for a list of nodes.
detect-module-cyclesprocedureDetect cycles in module dependency graph. Returns list of nodes involved in cycles, or empty list.
module-needs-compile?procedureCheck if a module needs to be recompiled. Returns #t if:
- Output .sgb doesn't exist
- Source .sgl is newer than output .sgb
- Any dependency (source or compiled) is newer than output
- Any source dependency was recompiled this session
any-recompiled?procedureCheck if any dependency was recompiled this session.
any-dep-newer?procedureCheck if any compiled dependency is newer than output.
compile-modules-incrementalprocedureCompile modules in dependency order with incremental support. source-files: list of .sgl file paths output-dir: directory for .sgb output files lib-paths: list of paths to search for compiled dependencies glob-base: base directory for computing relative paths (optional) force?: if #t, recompile everything regardless of mtime
Returns: (list compiled-files skipped-files)
ensure-directoryprocedureEnsure directory exists
inspect-language-headervariable(No description)
compiler-input-closurevariable(No description)
compiler-effect-inputsvariable(No description)
reset-compiler-input-proofs!variable(No description)
register-compiler-input-proof!variable(No description)
register-compiler-input-proofs!variable(No description)
compiler-input-proofvariable(No description)
compiler-input-hashvariable(No description)
compiler-source-inputs-known?variable(No description)
compiler-source-unknown-inputvariable(No description)
compiler-source-output-selected?variable(No description)
compiler-input-metadata-pathvariable(No description)
bytecode-required-outputsvariable(No description)
bytecode-effect-pair-valid?variable(No description)
read-compiler-input-metadatavariable(No description)
compiler-native-module?variable(No description)