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