cfg.h (4271B)
1 #ifndef KIT_BUILD_CFG_H 2 #define KIT_BUILD_CFG_H 3 4 #include <kit/build_coord.h> /* KitBuildKV (the `need` overlay pair) */ 5 #include <kit/core.h> 6 #include <stddef.h> 7 #include <stdint.h> 8 9 #include "build.h" 10 11 /* 12 * The two configuration value forms used by the build coordinator: 13 * 14 * BuildConfig - a PROPAGATED config map. Effective maps flow down the subtree 15 * and are hashed for resolution identity; traces record only 16 * consumed observations. Explicit `need` overlay maps are 17 * serialized by value as CAS blobs for shallow replay. 18 * BuildArgv - the LOCAL config: the target's argv vector, supplied by the 19 * build request, visible only to that recipe and never 20 * propagated. It is serialized by value as an `argv-id` blob. 21 * 22 * Pure value logic: canonicalize, hash, parse, look up, overlay. No I/O — the 23 * store persists/loads overlay and argv blobs through the CAS. Entries hang off 24 * caller-provided storage so there are no VLAs and the api layer owns sizing. 25 */ 26 27 /* The propagated-config value types are part of the public build model 28 * (<kit/build_coord.h>, included above); keep the internal short names as 29 * aliases so src/build code is unchanged and there is one definition site. */ 30 typedef KitBuildConfigEntry BuildConfigEntry; 31 typedef KitBuildConfig BuildConfig; 32 33 /* A local argv vector. `args` is caller-owned; order is significant and 34 * preserved (argv is positional, not a map). */ 35 typedef struct BuildArgv { 36 char (*args)[BUILD_VAL_MAX]; 37 size_t n; 38 size_t cap; 39 } BuildArgv; 40 41 /* Initialize a map/vector over caller storage. */ 42 void build_config_init(BuildConfig*, BuildConfigEntry* storage, size_t cap); 43 void build_argv_init(BuildArgv*, char (*storage)[BUILD_VAL_MAX], size_t cap); 44 45 /* Set key=value (replacing any existing key). Returns BUILD_ERR if full or the 46 * key/value overflows its cap. */ 47 int build_config_set(BuildConfig*, KitSlice key, KitSlice value); 48 49 /* Populate `out` (over its own storage) from a request's positional argv slices 50 * — the effective local argv. `args == NULL` or `n == 0` yields the empty argv 51 * (its argv-id is the fixed hash of the canonical empty vector); there is no 52 * build-definition default. Returns BUILD_ERR if full or an arg overflows its 53 * cap. */ 54 int build_argv_set(BuildArgv* out, const KitSlice* args, size_t n); 55 56 /* Look up `key`. On return *present is 0 when absent (== unset); *value (when 57 * present) borrows the stored value until the map is mutated. */ 58 int build_config_get(const BuildConfig*, KitSlice key, KitSlice* value, 59 int* present); 60 61 /* Produce `out` = `base` with each k=v in `overrides` applied (the `need` 62 * overlay). `out` must be initialized over its own storage; it is filled and 63 * canonicalized. */ 64 int build_config_overlay(const BuildConfig* base, const KitBuildKV* overrides, 65 size_t noverrides, BuildConfig* out); 66 67 /* Produce `out` = `base` with every entry in `overrides` applied. This is the 68 * replay form for a recorded need overlay recovered from its config-map blob. */ 69 int build_config_overlay_map(const BuildConfig* base, 70 const BuildConfig* overrides, BuildConfig* out); 71 72 /* Emit the canonical, byte-stable serialized form (BUILD_CONFIG_MAGIC version 73 * line, then sorted `key value` rows). Sorting/dedup happens here. */ 74 int build_config_emit(const BuildConfig*, KitWriter* out); 75 int build_argv_emit(const BuildArgv*, KitWriter* out); 76 77 /* Parse a serialized map/vector (e.g. a CAS blob recovered by id) back into a 78 * value. A non-canonical body is a parse error. */ 79 int build_config_parse(const uint8_t* data, size_t len, BuildConfig* out, 80 char* err, size_t errcap); 81 int build_argv_parse(const uint8_t* data, size_t len, BuildArgv* out, char* err, 82 size_t errcap); 83 84 /* Compute the content id of the canonical serialization: 85 * config-id = BLAKE2b(canonical map), argv-id = BLAKE2b(canonical argv). 86 * Equivalent to emitting then hashing; needs a heap for the scratch writer. */ 87 int build_config_id(KitHeap*, const BuildConfig*, uint8_t out[BUILD_HASH_LEN]); 88 int build_argv_id(KitHeap*, const BuildArgv*, uint8_t out[BUILD_HASH_LEN]); 89 90 #endif