Inject typed literal build-option values into a module - #41
Merged
Merged
Conversation
A repo's build.zig often synthesizes an options module from generated values (git commit, release version, feature flags) and imports it under a fixed name. tigerbeetle is the motivating case: src/config.zig does @import("vsr_options") and reads config_verify (bool), git_commit (?[40]u8), release and release_client_min ([]const u8). Azazel's build_options could only surface CLI flags (#Option: bool/string/u32), so a module needing injected values could not compile without the repo's own build.zig. Add an option_values list to #Module: each entry is a typed literal (bool / string / u32 / opt_commit, where opt_commit is a ?[40]u8 git hash, null unless a 40-char value is given). They are added to the same options module as build_options and imported under build_options_import. Verified end to end by building tigerbeetle's whole vsr library on 0.14: config.zig reads all four vsr_options fields via a comptime field loop, so a missing or mistyped field would fail to compile. 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 an
option_valueslist to#Module: typed literal values (bool/string/u32/opt_commit) injected into the module's build-options module, imported underbuild_options_import.opt_commitemits a?[40]u8git hash (null unless a 40-char value is given).Why
A repo's build.zig often synthesizes an options module from generated values (git commit, release version, feature flags). tigerbeetle is the motivating case:
src/config.zigdoes@import("vsr_options")and readsconfig_verify(bool),git_commit(?[40]u8),releaseandrelease_client_min([]const u8). Azazel's existingbuild_optionsonly surfaced CLI flags (#Option: bool/string/u32), so a module needing injected values could not compile without the repo's own build.zig. This also unblocks ghostty'sterminal_optionsand mach's module flags.How it flows
schema.cue:#OptionValue+option_valueson#Module. Fields avoid CUE's predeclaredbool/stringidentifiers.gen_build_spec.sh:OptionValuestruct + emitter.build.zig:addBuildOptionsalso injectsoption_values(with anopt_commit->?[40]u8branch) into the options module.build_spec_test.zig: shape assertions (kind is one of four; opt_commit is null or 40 chars).Verification
Built tigerbeetle's whole
vsrlibrary on 0.14 with an injectedvsr_optionsmodule (libtb_vsr.a). config.zig reads all four fields via a comptime field loop, so a missing or mistyped field would fail to compile. Azazel's own build and the 23 spec tests pass on 0.14.1. CI covers 0.14.1 / 0.15.2 / 0.16.0.