code wiki / _hdl_build / nx_sov_build_run.nx

nx_sov_build_run.nx

buildroot/runtime/_hdl_build/nx_sov_build_run.nx

123764 B1868 linesdepth 6pulls 11 transitivereach 0 importersview sourcekind tooltopic sov
docsdependenciesstructsconstsfunctions

about

nx_sov_build_run.nx -- FULLY SOVEREIGN, REUSABLE build runner (operator: "no sh and no c build, from the hardware layer up"). Generalizes nx_retire_gcc_orchestrator from hardcoded targets to ANY module passed as argv[1]. The build path is bits-up sovereign end to end: nx_cc_sovereign.elf <module>.nx -> _build/<module>.s (the team's SELF-HOSTED compiler) nxasm_x86_main.elf <module>.s -> _build/<module>.sov.elf (the team's x86-64 assembler+linker) _build/<module>.sov.elf (run it; exit = its exit) ⚠OUTPUT PATH IS _build/, RELATIVE TO CWD -- NOT /tmp/. These three lines said /tmp/ until 2026-07-30, left stale by the flock change that moved artifacts to a per-target _build/<name>.lock+.s+.sov.elf so concurrent sweeps stop overwriting each other mid-build. A doc that disagrees with the code is a defect, not a nit: it is why callers hunt for the artifact, and it hid a REAL brick hazard -- nx_hostctl cmd_buildrun (nx_hostctl.nx) ONCE read only /tmp/<name>.sov.elf, which made this runner and that supervisor a MATCHED PAIR that had to ship together or every /api/build failed. CLOSED -- VERIFIED 2026-08-17 BY READING THE LIVE SOURCE, not by assuming: cmd_buildrun now probes the ABSOLUTE .../nishihost/buildroot/_build/<name>.sov.elf FIRST (the parent is not in the child's CWD, so it must name it absolutely), falls back to /tmp/ for pre-flock builders, and its failure line NAMES BOTH paths. The pairing constraint no longer holds and this runner ships alone. The old line also cited :3089 while the code now sits near :3571 -- a stale line number is the tell. * A STALE HAZARD NOTE IS ITSELF A HAZARD: it makes the next reader either avoid a safe change or hunt a defect that was already fixed. This estate has the receipt -- a standing RED-gate list that nobody re-measured cost NINE sessions the SAME nine investigations, and 5 of the 9 were already green. Re-measure a warning before repeating it. NO gcc, NO bash, NO .sh anywhere. Orchestration is NishiLang sys_fork/dup3/execve/wait4. Recompile-retry guards the known-good compiler's empty-.s nondeterminism. Usage: nx_sov_build_run.elf <module-basename-in-runtime/_hdl_build>

dependencies 7 imports · 0 importers

nx_syscalls.nx nx_itoa_lib.nx nx_sha256.nx nx_import.nx nx_builddeploy_lib.nx nx_build_key_identity_lib.nx nx_build_canon_input_lib.nx nx_sov_build_run.nx

imports: nx_syscalls.nxnx_itoa_lib.nxnx_sha256.nxnx_import.nxnx_builddeploy_lib.nxnx_build_key_identity_lib.nxnx_build_canon_input_lib.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sbr_puts sys_write sys_exit sys_openat_rd sys_close sys_chdir sys_mmap nxa_die sys_write ↻ sys_exit ↻ nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ bd_lane_flag_known bd_flag_equal bd_qualification_flag bd_qualification_flag ↻ bd_run_timeout_flag sbr_atoi bd_positive_ms bd_qualification_mode sys_mmap ↻ sbr_cat sbr_incumbent_flavour sys_mmap ↻ sys_read_file sys_openat_rd ↻ sys_lseek sys_mmap ↻ sys_read sys_munmap

structs

none

consts

45const SBR_STATBUF: i64 = 256
46const SBR_STAT_MTIME_OFF: i64 = 88
168const SBR_MAGIC_4096: i64 = 4096 // read-chunk size (folded from the buildroot branch's rule-11 sweep, 2026-07-29 merge)
181const SBR_SHA_HEX: i64 = 64
182const SBR_QMARK: i64 = 63 // '?' fills the digest slot when a file is unreadable / row absent
185const SBR_EMPTY_RESERVE: i64 = 4294967296
210const SBR_OK: i64 = 0
211const SBR_USAGE: i64 = 2
212const SBR_COMPILE_FAIL: i64 = 3
213const SBR_ASM_FAIL: i64 = 4
214const SBR_ADMIT_REFUSED: i64 = 6 // build admission said no; distinct from a compile/assemble failure
217const SBR_CANON_REFUSED: i64 = 7 // canon evidence unavailable, invalid, or divergent
218const SBR_CANON_PATH_BYTES: i64 = 512
219const SBR_RUNTIME_PREFIX_BYTES: i64 = 8
220const SBR_MIN_ASM_BYTES: i64 = 128 // empty/failed .s is ~0-byte header; the smallest real program (_min42) is 540B
221const SBR_MAX_RETRIES: i64 = 12
231const SBR_TIMEOUT_RC: i64 = 0 - 9 // sbr_run sentinel: NEGATIVE, so it cannot collide with a real
233const SBR_BUILD_TIMEOUT: i64 = 8 // process exit code; next free after CANON_REFUSED=7
234const SBR_SIGKILL: i64 = 9
235const SBR_POLL_MS: i64 = 100 // wait4(WNOHANG) poll interval; fork+WNOHANG liveness is already
237const SBR_NO_DEADLINE: i64 = 0 // explicit: RUNNING the built program must never be time-boxed
243const SBR_BUILD_DEADLINE_MS: i64 = 900000
367const SBR_CACHE_EXPAND_CAP: i64 = 33554432 // 32 MiB: biggest measured closure .s is ~9.2 MB (nx_browser);
383const SBR_STAT_MODE_OFF: i64 = 24
384const SBR_MODE_PERM_MASK: i64 = 511 // 0777: permission bits only; type bits never travel
398const SBR_STAT_SIZE_OFF: i64 = 48
399const SBR_STAT_SIZE_W: i64 = 8
525const SBR_CACHE_SIDE_SUFFIX: *u8 = ".sha"
526const SBR_CACHE_TMP_INFIX: *u8 = ".tmp-"
527const SBR_CACHE_TMPW: i64 = 512 // 4 x SBR_CACHE_PATHW, see derivation above
528const SBR_CACHE_SIDE_MAX: i64 = 256 // sha256= (7+64) + bytes= (6+20 max i64 digits) + key= (4+64) + 3 NL = 168 < 256
529const SBR_CACHE_ELF_SUFFIX_LEN: i64 = 8 // ".sov.elf" -- the key is the SBR_SHA_HEX hex chars before it
758const SBR_CACHE_BUDGET_DEFAULT: i64 = 1073741824
759const SBR_CACHE_DIRBUF: i64 = 65536
763const SBR_CACHE_PRUNE_SLOTS: i64 = 32768
769const SBR_CACHE_PATHW: i64 = 128

functions

47func sbr_mtime(path: *u8) -> i64
56func sbr_name_is(a: *u8, b: *u8) -> i64
62func sbr_is_toolchain(name: *u8) -> i64
called by 1: main calls 1: sbr_name_is
91func sbr_is_daemon(name: *u8) -> i64
186func sbr_sha_hex(path: *u8, out: *u8) -> i64
245func sbr_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
250func sbr_putn(v: i64) -> i64 { nxi_out(v); return 0 }
253func sbr_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { dst[off+i] = s[i]; i = i + 1 } return off + i }
256func sbr_ceq_at(a: *u8, ao: i64, al: i64, b: *u8, bo: i64, bl: i64) -> i64
called by 1: main
263func sbr_exitcode(status: i64) -> i64 { return (status >> 8) & 0xff }
called by 1: sbr_run
268func sbr_atoi(s: *u8) -> i64
291func sbr_run(path: *u8, argv: *i64, envp: *i64, redir_out: i64, redir_err: i64, deadline_ms: i64) -> i64
336func sbr_filesize(path: *u8) -> i64
385func sbr_src_mode(path: *u8) -> i64
400func sbr_stat_size(path: *u8) -> i64
412func sbr_copyfile(srcp: *u8, dstp: *u8) -> i64
439func bld_cache_cas_hex(d: *u8, out: *u8) -> i64
called by 1: sbr_cache_key
461func sbr_incumbent_flavour(path: *u8) -> i64
489func sbr_cache_key(src: *u8, compiler: *u8, asm_tool: *u8, want_debug: i64, out: *u8) -> i64
534func bld_cache_cas_field(buf: *u8, n: i64, key: *u8, out: *u8, cap: i64) -> i64
575func bld_cache_cas_verify(cachepath: *u8, shaout: *u8, bytesout: *i64) -> i64
611func bld_cache_cas_say(name: *u8, what: *u8, key: *u8) -> i64
616func bld_cache_cas_nl() -> i64 { let b: *u8 = sys_mmap(2); b[0] = 10 as u8; sys_write(1, b, 1); sys_munmap(b, 2); return 0 }
622func bld_cache_cas(cachekey: *u8, cachepath: *u8, elfpath: *u8, name: *u8) -> i64
681func bld_cache_cas_store(elfpath: *u8, cachepath: *u8, name: *u8) -> i64
774func sbr_cache_conf_int(key: *u8, dflt: i64) -> i64
817func sbr_cache_budget() -> i64
called by 1: sbr_cache_prune calls 1: sbr_cache_conf_int
823func sbr_cache_enabled() -> i64
called by 1: main calls 1: sbr_cache_conf_int
832func sbr_cache_prune() -> i64
939func main(argc: i64, argv: *i64) -> i64