Datasets:
Download tools/buildgraph.py from ego0op/ingot-zig: direct link, hf CLI and curl.
- Browser
- Download file 2.68 kB
-
https://huggingface.co/datasets/ego0op/ingot-zig/resolve/main/tools/buildgraph.py
- Command line
-
hf download hf://datasets/ego0op/ingot-zig/tools/buildgraph.py
-
curl -L -o buildgraph.py https://huggingface.co/datasets/ego0op/ingot-zig/resolve/main/tools/buildgraph.py
2.68 kB
| # Static module graph from a repo's build.zig text (Opus · Smelter, 2026-10-27). Works when build.zig itself no longer | |
| # compiles (stale build API): name -> repo-local root file, for modules declared with addModule/createModule and wired | |
| # with addImport / .imports = .{ .name, .module } / addAnonymousImport. External (b.dependency) modules are not resolved. | |
| import re, os | |
| PATH = r'(?:b\.path\(\s*"([^"]+)"\s*\)|\.\{\s*\.(?:src_)?path\s*=\s*"([^"]+)"\s*\}|"([^"]+\.zig)")' | |
| def _p(m): | |
| return next((g for g in m.groups() if g), None) | |
| def modules(root): | |
| txt = '' | |
| for f in ('build.zig',): | |
| try: txt += open(os.path.join(root, f), encoding='utf-8', errors='replace').read() | |
| except OSError: pass | |
| if not txt: return {} | |
| var, named = {}, {} | |
| # const V = b.createModule(.{ ... root_source_file = PATH ... }) / b.addModule("N", .{ ... }) | |
| for m in re.finditer(r'(?:const|var)\s+(\w+)\s*=\s*b\.(createModule|addModule)\(\s*(?:"([^"]+)"\s*,\s*)?\.\{', txt): | |
| body = txt[m.end():m.end() + 1500] | |
| pm = re.search(r'\.(?:root_source_file|source_file)\s*=\s*' + PATH, body) | |
| if pm: var[m.group(1)] = _p(pm); named[m.group(3)] = _p(pm) if m.group(3) else None | |
| for m in re.finditer(r'b\.addModule\(\s*"([^"]+)"\s*,\s*\.\{', txt): | |
| pm = re.search(r'\.(?:root_source_file|source_file)\s*=\s*' + PATH, txt[m.end():m.end() + 1500]) | |
| if pm: named[m.group(1)] = _p(pm) | |
| # X.addImport("N", V) / addModule("N", V) / .{ .name = "N", .module = V } | |
| for m in re.finditer(r'\.(?:addImport|addModule)\(\s*"([^"]+)"\s*,\s*(\w+)\s*\)', txt): | |
| if m.group(2) in var: named.setdefault(m.group(1), var[m.group(2)]) | |
| for m in re.finditer(r'\.name\s*=\s*"([^"]+)"\s*,\s*\.module\s*=\s*(\w+)\b', txt): | |
| if m.group(2) in var: named.setdefault(m.group(1), var[m.group(2)]) | |
| # inline: .{ .name = "N", .module = b.createModule(.{ .root_source_file = PATH }) } and addAnonymousImport("N", .{ ...PATH }) | |
| for m in re.finditer(r'\.name\s*=\s*"([^"]+)"\s*,\s*\.module\s*=\s*b\.createModule\(\s*\.\{', txt): | |
| pm = re.search(r'\.root_source_file\s*=\s*' + PATH, txt[m.end():m.end() + 600]) | |
| if pm: named.setdefault(m.group(1), _p(pm)) | |
| for m in re.finditer(r'\.(?:addAnonymousImport|addAnonymousModule)\(\s*"([^"]+)"\s*,\s*\.\{', txt): | |
| pm = re.search(r'\.(?:root_source_file|source_file)\s*=\s*' + PATH, txt[m.end():m.end() + 600]) | |
| if pm: named.setdefault(m.group(1), _p(pm)) | |
| out = {} | |
| for n, p in named.items(): | |
| if not n or not p: continue | |
| p = os.path.normpath(p) | |
| if not p.startswith('..') and os.path.isfile(os.path.join(root, p)): out[n] = p | |
| return out | |