Import a module generated by a repo's host tool - #42
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a
gen_importslist to#Module. Each entry declares a host tool (tool_root,tool_name), an ordered argument list (each arg isliteral,input_file, oroutput_file), and whichoutput_filebecomes the generated module's root. Azazel builds the tool forb.graph.host, runs it (addFileArgfor inputs,addOutputFileArgfor outputs), and imports the captured output path underalias.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.zigcompilessrc/tools/config_gen.zig, runs it with the langref as input, and imports the emittedversion_data.zigas theversion_datamodule. 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, andgen_importson#Module.gen_build_spec.sh:GenArg/GeneratedImportstructs + emitter.build.zig:generatedModulebuilds the host tool, runs it capturing each output file's LazyPath, and returns a module over the one named byoutput. Wired into the module loop alongsidepkg_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_genon the mach 0.17 toolchain: Azazel compiles the tool, runs it to emit the 2456-lineversion_data.zig, and the probe imports and references itsbuiltinsmap, then runs. Azazel's own build and the 23 spec tests pass on 0.14.1 / 0.15.2 / 0.16.0 (b.graph.hostandsingle_threadedcompile on all three).