Build browser bundles with the current Wasm execution tier

This commit is contained in:
waozi committed 2026-11-26 22:03:20 -03:00
1 parent 4421be7c9e
commit e786fea5ca
2 files changed
+19 -22

No files matched your search

+2
View File
@@ -2,6 +2,8 @@
## [Unreleased]
- Build browser bundles with the current Ziran WebAssembly execution tier and verify their Wasm lowering before publication.
- Share the Kryon revision that fixes GPU seams in rounded fills.
- Replace profile picture tabs with expandable Profile, Shovey, Jungle, Wurm and Inner Breeze collections in one scroll area. Keep locked collections visible, remember app unlocks locally and sync them with the account.
+17 -22
View File
@@ -1,10 +1,10 @@
#!/usr/bin/env python3
"""Link a browser app with the same Entity account provider as native hosts.
Bundles given with --linked, and the bundles embedded in them, run as
compiled code in the page rather than on the portable VM: Ziran writes each
program as C (zi2zx native-c) and the page links it, registered under the
identity of those exact bundle bytes. Any other bundle still runs on the VM.
The Emscripten runtime compiles verified ZX programs to WebAssembly when
they are opened, including embedded bundles. Bundles given with --linked
also have their Wasm lowering checked during the build, so unsupported
programs fail before the page is published.
"""
import argparse
import importlib.util
@@ -12,7 +12,6 @@ import os
from pathlib import Path
import shutil
import subprocess
import sys
def main():
@@ -24,7 +23,7 @@ def main():
parser.add_argument('--entry', default='runtime:main', help='project MODULE:FUNCTION entry')
parser.add_argument('--source', default='src/web/runtime.zi')
parser.add_argument('--linked', type=Path, action='append', default=[],
help='a bundle the page runs as compiled code')
help='a bundle whose WebAssembly lowering the build must verify')
parser.add_argument('--canvas-app', help='compile --source as an AppContext canvas app (MODULE:Main)')
args = parser.parse_args()
project = Path.cwd()
@@ -125,22 +124,18 @@ def main():
'-DOQS_USE_OPENSSL=OFF', '-DOQS_DIST_BUILD=OFF', '-DOQS_OPT_TARGET=generic',
'-DOQS_MINIMAL_BUILD=SIG_ml_dsa_44;KEM_ml_kem_768'], check=True, env=env)
subprocess.run(['cmake', '--build', str(oqs), '--target', 'oqs', '-j2'], check=True, env=env)
linked = []
# Current Ziran installs its WebAssembly provider in Emscripten's
# libziran. It compiles each exact bundle at instantiation; the removed
# native-c/linked-zx route must not bypass that runtime and its host ABI.
if args.linked:
programs, objects = work / 'linked', work / 'linked-objects'
for folder in (programs, objects):
if folder.exists():
shutil.rmtree(folder)
zi2zx = os.environ.get('ZI2ZX') or str(toolchain / 'build/bin/zi2zx')
subprocess.run([zi2zx, 'native-c', '--embedded', '-o', str(programs),
*[str(bundle.resolve()) for bundle in args.linked]], check=True, env=env)
emnm = str(Path(emcc).with_name('emnm')) if '/' in emcc else 'emnm'
compiled = subprocess.run([sys.executable, str(toolchain / 'scripts/linked-zx.py'), str(programs),
'--output', str(objects), '--cc', emcc, '--nm', emnm,
'--cflags=-O2 -ffunction-sections -fdata-sections'],
check=True, env=env, capture_output=True, text=True)
sys.stderr.write(compiled.stderr)
linked = compiled.stdout.split()
programs = work / 'linked'
if programs.exists():
shutil.rmtree(programs)
programs.mkdir(parents=True)
zx2wasm = os.environ.get('ZX2WASM') or str(toolchain / 'build/bin/zx2wasm')
for index, bundle in enumerate(args.linked):
subprocess.run([zx2wasm, '-o', str(programs / f'{index}.wasm'),
str(bundle.resolve())], check=True, env=env)
# Package the game separately so large bundles do not inflate the Wasm file.
# Emscripten does not allow --embed-file and --preload-file in one invocation.
packager = Path(shutil.which(emcc) or emcc).resolve().parent / 'tools/file_packager'
@@ -154,7 +149,7 @@ def main():
subprocess.run([emcc, '-O2', '-ffunction-sections', '-fdata-sections',
'-I' + str(toolchain / 'include'), '-iquote', str(generated),
*[item for path in generated.rglob('*') if path.is_dir() for item in ('-iquote', str(path))],
*map(str, generated.rglob('*.c')), *linked, str(runtime),
*map(str, generated.rglob('*.c')), str(runtime),
'-I' + str(package('monocypher') / 'src'), str(package('monocypher') / 'src/monocypher.c'),
str(package('monocypher') / 'src/optional/monocypher-ed25519.c'), str(oqs / 'lib/liboqs.a'),
'--js-library', str(toolchain / 'web/ziran_web.js'), '-lidbfs.js',