code wiki / _hdl_build / nx_build_orchestrator.nx

nx_build_orchestrator.nx source

↩ module page · 62 lines · 3393 B

1// nx_build_orchestrator.nx -- SOVEREIGN build runner in NishiLang, retiring BASH (operator: "get rid of 2// the remaining dependencies... build the nishi team to retire those, only as benchmarking tools"). 3// Does what the .sh runners do, but in pure NishiLang via sys_fork/dup3/execve/wait4: compile (compiler 4// stdout -> .s), assemble+link (gcc -> .elf), run the .elf -- the ORCHESTRATION is sovereign, no shell. 5// (gcc is still exec'd for now = the next dep to retire with a sovereign assembler; bash is RETIRED.) 6// license_tier: ORIGINAL Follows the fork/exec pattern proven in nx_run_timeout. 7 8import "nx_syscalls.nx" 9 10func _puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 11func _putn(v: i64) -> i64 { let bb: *u8 = sys_mmap(28); var m: i64=v; if m<0 {m=0-m;sys_write(1,"-" as *u8,1)}; let t: *u8 = sys_mmap(28); var k: i64=0; if m==0 {t[0]=48;k=1}; while m>0 {t[k]=48+(m%10); m=m/10; k=k+1}; var i: i64=0; while i<k {bb[i]=t[k-1-i]; i=i+1}; sys_write(1, bb, k); return 0 } 12 13// exit code from a wait4 status (WEXITSTATUS). 14func _exitcode(status: i64) -> i64 { return (status >> 8) & 0xff } 15 16// fork + (optional stdout redirect to redir_fd) + execve(path, argv, envp); parent waits, returns exit code. 17func _run(path: *u8, argv: *i64, envp: *i64, redir_fd: i64) -> i64 { 18 let pid: i64 = sys_fork() 19 if pid == 0 { 20 if redir_fd >= 0 { sys_dup3(redir_fd, 1, 0) } 21 sys_execve(path, argv, envp) 22 sys_exit(127) // exec failed 23 } 24 let st: *i64 = sys_mmap(16) as *i64 25 sys_wait4(pid, st, 0) 26 return _exitcode(st[0]) 27} 28 29func main() -> i64 { 30 _puts("=== SOVEREIGN BUILD ORCHESTRATOR (NishiLang fork/exec, no bash) ===\n" as *u8) 31 let compiler: *u8 = "_offc/nx_cc_known_good.elf" as *u8 32 let source: *u8 = "runtime/_hdl_build/_orch_probe.nx" as *u8 33 let spath: *u8 = "/tmp/_orch_probe.s" as *u8 34 let elfpath: *u8 = "/tmp/_orch_probe.elf" as *u8 35 let gcc: *u8 = "/usr/bin/gcc" as *u8 36 37 // env with PATH so gcc can find its `as`/`ld` 38 let envp: *i64 = sys_mmap(8*4) as *i64 39 envp[0] = "PATH=/usr/bin:/bin" as *u8 as i64; envp[1] = 0 40 41 // STEP 1 -- compile: compiler source (stdout -> spath) 42 let sfd: i64 = sys_openat_wr(spath, 0x1a4) 43 let a1: *i64 = sys_mmap(8*4) as *i64 44 a1[0] = compiler as i64; a1[1] = source as i64; a1[2] = 0 45 let rc1: i64 = _run(compiler, a1, envp, sfd) 46 sys_close(sfd) 47 48 // STEP 2 -- assemble+link: gcc -nostdlib -no-pie -static spath -o elfpath 49 let a2: *i64 = sys_mmap(8*12) as *i64 50 a2[0]=gcc as i64; a2[1]="-nostdlib" as *u8 as i64; a2[2]="-no-pie" as *u8 as i64; a2[3]="-static" as *u8 as i64 51 a2[4]=spath as i64; a2[5]="-o" as *u8 as i64; a2[6]=elfpath as i64; a2[7]=0 52 let rc2: i64 = _run(gcc, a2, envp, 0 - 1) 53 54 // STEP 3 -- run the built ELF 55 let a3: *i64 = sys_mmap(8*4) as *i64 56 a3[0] = elfpath as i64; a3[1] = 0 57 let rc3: i64 = _run(elfpath, a3, envp, 0 - 1) 58 59 _puts(" compile rc=" as *u8); _putn(rc1); _puts(" gcc rc=" as *u8); _putn(rc2); _puts(" probe exit=" as *u8); _putn(rc3); _puts("\n" as *u8) 60 if rc3 == 0 { _puts(" RETIRED BASH for the build runner: a NishiLang program orchestrated compile->link->run, no shell. (gcc next.)\n" as *u8); sys_exit(0); return 0 } 61 _puts(" orchestration failed\n" as *u8); sys_exit(1); return 1 62}