interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / tools / adapters / build-zig-u64.py

38 lines · 3189 bytes Raw Blame History
1#!/usr/bin/env python3
2"""Host build orchestration only; all Zig importer/exporter computation is seeded Omega (#740)."""
3from pathlib import Path
4import hashlib,json,os,struct,subprocess,tempfile
5ROOT=Path(__file__).resolve().parents[2]
6build=ROOT/'build/L740'
7for p in [ROOT/'build',build]:
8 if p.is_symlink():raise SystemExit('ZIG_ADAPTER_UNSAFE_BUILD_PATH')
9VENDOR='src/source-aware/vendor/sha256.om'
10CODEC='src/source-aware/core-v2.om'
11if not (ROOT/CODEC).is_file():raise SystemExit('ZIG_ADAPTER_MISSING_CODEC_V2: '+CODEC+' (owned by the #621 v2 codec lane) is not in this tree')
12build.mkdir(parents=True,exist_ok=True)
13# Same source-only #621 construction path and pinned compiler as the C importer, the C exporter and the v2 codec.
14subprocess.run(['bash','tools/source-aware/build'],cwd=ROOT,check=True,timeout=600,stdout=subprocess.PIPE)
15compiler=ROOT/'build/L574/toolchain/build/bootstrap/omc'
16verifier=ROOT/'build/L574/toolchain/tools/verify-elf.sh'
17expected='191b776ef98821597c3e30655da6d680a9b66edbc9ceaca3c39c61ea6df098e9'
18assert compiler.is_file() and hashlib.sha256(compiler.read_bytes()).hexdigest()==expected,'ZIG_ADAPTER_COMPILER_PIN_MISMATCH'
19subprocess.run(['sha256sum','-c','tools/source-aware/imports.sha256'],cwd=ROOT,check=True,stdout=subprocess.PIPE)
20ARTIFACTS={'zig-import':[VENDOR,'src/adapters/zig-u64-import.om'],
21 'zig-export':[VENDOR,CODEC,'src/adapters/zig-u64-export.om']}
22report={'schema':'omega.zig-u64.build.v1','profile':'spec/universal/zig-u64-v1.md','compiler_sha256':expected,'seed_source_archive':'0fc7d8662cb799e7c206b17c18ea4c3ec2b8fea9','birth_seed':'29b12760',
23 'compiler_choice':'bridge-seed omc 191b776e: the pinned compiler of the reviewed C importer and the #621 v1/v2 codec; vendor SHA256 and core-v2.om decode compile unchanged under it; neither adapter needs argv',
24 'artifacts':{},'host_orchestration':'Python process/filesystem only; no Zig/C/Python parser or compute fallback in native artifacts'}
25with tempfile.TemporaryDirectory(prefix='.zig-build-',dir=build) as temp:
26 t=Path(temp)
27 for name,parts in ARTIFACTS.items():
28 program=b'\n'.join((ROOT/p).read_bytes() for p in parts)+b'\n'
29 result=subprocess.run([str(compiler)],input=program,capture_output=True,timeout=120)
30 if result.returncode:raise SystemExit(f'ZIG_ADAPTER_COMPILE_FAILED {name} rc={result.returncode}: '+result.stderr.decode(errors='replace'))
31 binary=result.stdout
32 assert len(binary)>64 and binary[:4]==b'\x7fELF' and struct.unpack_from('<HH',binary,16)==(2,183),'ZIG_ADAPTER_NOT_AARCH64_EXEC'
33 (t/(name+'.om')).write_bytes(program);(t/name).write_bytes(binary);(t/name).chmod(0o700)
34 subprocess.run(['sh',str(verifier),str(t/name)],check=True)
35 report['artifacts'][name]={'inputs':{p:hashlib.sha256((ROOT/p).read_bytes()).hexdigest() for p in parts},'combined_source_sha256':hashlib.sha256(program).hexdigest(),'binary_sha256':hashlib.sha256(binary).hexdigest()}
36 (t/'build.json').write_text(json.dumps(report,indent=2)+'\n')
37 for name in [*ARTIFACTS,*(n+'.om' for n in ARTIFACTS),'build.json']:os.replace(t/name,build/name)
38for name in ARTIFACTS:print(build/name)