defn.h (4282B)
1 #ifndef KIT_BUILD_DEFN_H 2 #define KIT_BUILD_DEFN_H 3 4 #include <kit/core.h> 5 #include <stddef.h> 6 #include <stdint.h> 7 8 #include "build.h" 9 10 /* 11 * Package-local build definitions. A workspace is rooted externally by 12 * KitBuildOptions.workspace_root; each package directory has its own BUILD.kit 13 * (or opts->build_def_path basename). The file is a catalog: exact targets, 14 * defaults, simple rules, and redo-style default discovery settings. The ONLY 15 * catalog-derived input of a target is still its resolved recipe-id (BLAKE2b of 16 * the recipe FILE bytes), carried as a per-node scalar in the deepset and 17 * refreshed by recomputing it through the LIVE catalog. The whole BUILD.kit file 18 * is not hashed as a dependency. 19 * 20 * The definition does NOT carry argv: local argv is supplied entirely by the 21 * build request (empty when none is given) and forms the argv-id dimension of 22 * the resolution key — see KitBuildRequest. Pure parse + lookup, no I/O. 23 * 24 * Format v1 accepts exact target stanzas. v2 adds target type/default/rule and 25 * redo-defaults stanzas. Target names in package files are local names: 26 * 27 * kit-build 1 28 * [target server] 29 * recipe recipes/cc.sh 30 * [target core] 31 * recipe recipes/cc.sh 32 * ... 33 */ 34 35 /* One resolved target stanza: a name and the recipe it maps to. */ 36 typedef struct BuildTargetDefn { 37 char name[BUILD_TARGET_MAX]; /* local target name */ 38 char recipe_path[BUILD_PATH_MAX]; /* package-relative or //workspace path */ 39 char type[BUILD_KEY_MAX]; 40 int has_recipe; 41 int has_type; 42 } BuildTargetDefn; 43 44 typedef struct BuildDefaultDefn { 45 char type[BUILD_KEY_MAX]; 46 char recipe_path[BUILD_PATH_MAX]; /* package-relative or //workspace path */ 47 } BuildDefaultDefn; 48 49 typedef struct BuildRuleDefn { 50 char name[BUILD_KEY_MAX]; 51 char match[BUILD_TARGET_MAX]; 52 char recipe_path[BUILD_PATH_MAX]; /* package-relative or //workspace path */ 53 char type[BUILD_KEY_MAX]; 54 int has_recipe; 55 int has_type; 56 } BuildRuleDefn; 57 58 typedef struct BuildRedoDefaults { 59 int enabled; 60 int walk_parents; 61 char search[8][BUILD_PATH_MAX]; /* "." means current package/ancestor dir */ 62 size_t n_search; 63 } BuildRedoDefaults; 64 65 /* The parsed definition: an index of stanzas over caller-provided storage, plus 66 * the raw bytes (borrowed) kept alive for the definition's lifetime. The 67 * definition file as a whole is not a source dependency; only each target's 68 * resolved recipe-id is. */ 69 typedef struct BuildDefn { 70 const uint8_t* bytes; /* the whole definition file, borrowed */ 71 size_t len; 72 int version; 73 BuildTargetDefn* targets; 74 size_t n_targets; 75 size_t cap_targets; 76 BuildDefaultDefn* defaults; 77 size_t n_defaults; 78 size_t cap_defaults; 79 BuildRuleDefn* rules; 80 size_t n_rules; 81 size_t cap_rules; 82 BuildRedoDefaults redo; 83 } BuildDefn; 84 85 /* Parse a definition file into `out` over caller storage. Non-canonical input 86 * is a parse error -> BUILD_ERR with detail in err. */ 87 int build_defn_parse(const uint8_t* data, size_t len, BuildDefn* out, char* err, 88 size_t errcap); 89 90 /* Find a package-local target stanza by local name; returns NULL if absent. */ 91 const BuildTargetDefn* build_defn_find(const BuildDefn*, KitSlice name); 92 93 const BuildDefaultDefn* build_defn_default_find(const BuildDefn*, 94 KitSlice type); 95 const BuildRuleDefn* build_defn_rule_match(const BuildDefn*, KitSlice name, 96 int* ambiguous); 97 98 /* Label helpers. Canonical labels are [@repo]//package:name. 99 * `current_repo`/`current_package` are used for relative labels. */ 100 int build_target_canonicalize(KitSlice label, KitSlice current_repo, 101 KitSlice current_package, 102 char out[BUILD_TARGET_MAX], char* err, 103 size_t errcap); 104 int build_target_split_repo(KitSlice canonical, char repo[BUILD_KEY_MAX], 105 char package[BUILD_PATH_MAX], 106 char local[BUILD_TARGET_MAX]); 107 int build_target_split(KitSlice canonical, char package[BUILD_PATH_MAX], 108 char local[BUILD_TARGET_MAX]); 109 int build_recipe_path_resolve(KitSlice package, KitSlice recipe, 110 char out[BUILD_PATH_MAX]); 111 112 #endif