Skip to content

Import a module generated by a repo's host tool - #42

Merged
godofecht merged 1 commit into
mainfrom
feat/generated-module-imports
Aug 5, 2026
Merged

godofecht merged 1 commit into
mainfrom
feat/generated-module-imports

Conversation

@godofecht

@godofecht godofecht commented Aug 5, 2026 •

Copy link
Copy Markdown
Owner

What

Adds a gen_imports list to #Module. Each entry declares a host tool (tool_root, tool_name), an ordered argument list (each arg is literal, input_file, or output_file), and which output_file becomes the generated module's root. Azazel builds the tool for b.graph.host, runs it (addFileArg for inputs, addOutputFileArg for outputs), and imports the captured output path under alias.

Why

Some repos generate a source module at build time by compiling a host tool, running it, and importing the file it writes. zls is the motivating case: build.zig compiles src/tools/config_gen.zig, runs it with the langref as input, and imports the emitted version_data.zig as the version_data module. Azazel modeled package and generated options but had no codegen-to-module primitive, so any module importing a generated module could not be built from the CUE model alone.

How it flows

  • schema.cue: #GenArg + #GeneratedImport, and gen_imports on #Module.
  • gen_build_spec.sh: GenArg / GeneratedImport structs + emitter.
  • build.zig: generatedModule builds the host tool, runs it capturing each output file's LazyPath, and returns a module over the one named by output. Wired into the module loop alongside pkg_imports.
  • build_spec_test.zig: shape assertions (tool_root ends in .zig; the named output is one of the output_file args).

Verification

Built a probe against zls's real config_gen on the mach 0.17 toolchain: Azazel compiles the tool, runs it to emit the 2456-line version_data.zig, and the probe imports and references its builtins map, then runs. Azazel's own build and the 23 spec tests pass on 0.14.1 / 0.15.2 / 0.16.0 (b.graph.host and single_threaded compile on all three).

Some repos generate a source module at build time: they compile a host
tool, run it, and import the file it writes. zls is the motivating case:
build.zig compiles src/tools/config_gen.zig into a host executable, runs
it with the langref as input, and imports the emitted version_data.zig
as the "version_data" module. Azazel could model package and generated
options but not this codegen step, so any module importing such a
generated module could not be built without the repo's own build.zig.

Add a gen_imports list to #Module. Each entry names a host tool
(tool_root, tool_name), an ordered arg list (literal / input_file /
output_file), and which output_file becomes the module root. build.zig
builds the tool for b.graph.host, runs it (addFileArg for inputs,
addOutputFileArg for outputs so the emitted file is a real build-graph
dependency), and imports the captured output path under the alias.

Verified end to end by building a probe against zls's real config_gen on
the mach 0.17 toolchain: Azazel compiles the tool, runs it to emit the
2456-line version_data.zig, and the probe imports and references its
builtins map. Azazel's own build and 23 spec tests pass on
0.14.1 / 0.15.2 / 0.16.0 (b.graph.host and single_threaded compile on all).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@godofecht
godofecht merged commit 00b91f4 into main Aug 5, 2026
3 checks passed
@godofecht
godofecht deleted the feat/generated-module-imports branch August 5, 2026 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant