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 / rust-i64-export
| 1 | #!/usr/bin/env python3 |
| 2 | """Transparent host dispatch; Rust S2 export computation and hashing run in seeded native Omega (spec/universal/translation-s2-v1.md). |
| 3 | Usage: rust-i64-export [NAME] < unit.omsb > unit.rs (NAME rules are checked natively).""" |
| 4 | from pathlib import Path |
| 5 | import hashlib,json,subprocess,sys |
| 6 | root=Path(__file__).resolve().parents[2] |
| 7 | NAME='rust-i64-export' |
| 8 | PIN='191b776ef98821597c3e30655da6d680a9b66edbc9ceaca3c39c61ea6df098e9' |
| 9 | CLOSURE={'src/source-aware/vendor/sha256.om','src/source-aware/core-v3.om','src/adapters/rust-i64-export.om'} |
| 10 | name=sys.argv[1].encode() if len(sys.argv)==2 else b'' |
| 11 | if len(sys.argv)>2 or (len(sys.argv)==2 and not 1<=len(name)<=255): |
| 12 | print('RUST_EXPORT_BAD_COMMAND: use rust-i64-export [NAME] with the envelope on stdin',file=sys.stderr);raise SystemExit(64) |
| 13 | try: |
| 14 | build=root/'build/S2';m=json.loads((build/'build.json').read_text());exe=build/NAME;a=m['artifacts'][NAME] |
| 15 | if a['compiler_sha256']!=PIN:raise ValueError('compiler identity') |
| 16 | if set(a['inputs'])!=CLOSURE:raise ValueError('source closure') |
| 17 | for rel,digest in a['inputs'].items(): |
| 18 | if hashlib.sha256((root/rel).read_bytes()).hexdigest()!=digest:raise ValueError('changed source '+rel) |
| 19 | if hashlib.sha256(exe.read_bytes()).hexdigest()!=a['binary_sha256']:raise ValueError('changed artifact') |
| 20 | except (OSError,ValueError,KeyError,TypeError) as exc: |
| 21 | print('RUST_EXPORT_STALE_OR_MISSING_BUILD: '+str(exc),file=sys.stderr);raise SystemExit(78) |
| 22 | # Frame: one name-length byte (0 = default calc), the name bytes, then stdin to EOF. |
| 23 | r=subprocess.run([str(exe)],input=bytes([len(name)])+name+sys.stdin.buffer.read(),stdout=subprocess.PIPE) |
| 24 | if r.returncode==0:sys.stdout.buffer.write(r.stdout);sys.stdout.buffer.flush() |
| 25 | raise SystemExit(r.returncode) |