Expose the native widget surface through ordinary typed TSX components and enforce application composition at generic export and entry boundaries. Migrate maintained screens, scaffolds, gallery publication and editor transport through the common checked IR path. Preserve native logic, retained component state, input and platform hosts; remove the pixmap application route. Local validation: complete make push-check passed with published Ziran dc3ecf0a, including docs, public source/saved surface, private-display desktop input, native host links and Canvas input parity. Fresh CLI/player/desktop library installed and byte-verified. The full migration matrix records remaining owning suites, published consumer pins, platform runs and Alpha benchmarks; this is a source milestone, not completion of the full campaign.
106 lines
4.9 KiB
Python
106 lines
4.9 KiB
Python
"""Build an application's own host and reject hosts outside its project."""
|
|
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import tempfile
|
|
|
|
from toolchain import ZIRAN, ZIRAN_ROOT, pinned, kryon_only
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def run(arguments, project, success=True, makeflags=None, env_updates=None):
|
|
environment = os.environ.copy()
|
|
for name in ("DISPLAY", "WAYLAND_DISPLAY", "XAUTHORITY", "DBUS_SESSION_BUS_ADDRESS", "ZIRAN_PAR_THREADS"):
|
|
environment.pop(name, None)
|
|
if makeflags is not None:
|
|
environment['MAKEFLAGS'] = makeflags
|
|
if env_updates:
|
|
environment.update(env_updates)
|
|
result = subprocess.run(arguments, cwd=project, env=environment,
|
|
capture_output=True, text=True)
|
|
if success:
|
|
assert result.returncode == 0, (result.stdout, result.stderr)
|
|
else:
|
|
assert result.returncode != 0, (result.stdout, result.stderr)
|
|
return result
|
|
|
|
|
|
def main():
|
|
with tempfile.TemporaryDirectory(prefix="kryon-project-host-") as temporary:
|
|
project = Path(temporary) / "project"
|
|
(project / "src").mkdir(parents=True)
|
|
(project / "ziran.toml").write_text(pinned(
|
|
'[package]\nname = "host_probe"\ntool = "kryon"\n'
|
|
'entry = "src/app.tsx"\nmodule_roots = ["src"]\n'
|
|
'bridge_modules = ["app"]\n\n'
|
|
'[toolchain]\ngit = "https://github.com/ziranlang/ziran.git"\n'
|
|
'ref = "master"\n\n'
|
|
'[dependencies.kryon]\ngit = "https://github.com/kryonlabs/kryon.git"\n'
|
|
'ref = "master"\n\n'
|
|
'[tool.kryon]\ndefault_profile = "tui"\n\n'
|
|
'[tool.kryon.profiles.tui]\nbackend = "terminal"\n'
|
|
'host = "src/runner.zi"\n'
|
|
))
|
|
(project / "ziran.local.toml").write_text(kryon_only(
|
|
f'[overrides]\nkryon = "{ROOT}"\nziran = "{ZIRAN_ROOT}"\n'
|
|
))
|
|
(project / "src/app.tsx").write_text('''import { Rectangle } from "kryon/geometry";
|
|
import { Session } from "kryon/session";
|
|
|
|
export function Frame(session: Session, viewport: Rectangle): s32 { return s32(99); }
|
|
''')
|
|
(project / "src/runner.zi").write_text(
|
|
'#import "std/byte_text_linux"\n'
|
|
'#program_export\nmain :: (argc: s32, argv: **u8) -> s32 {\n'
|
|
' if argc != 2 { return 1 }\n'
|
|
' if TextFromCString(argv[1]) != "--probe" { return 2 }\n'
|
|
' print("custom host\\n")\n return 0\n}\n'
|
|
)
|
|
run([str(ZIRAN), "lock"], project)
|
|
run([str(ZIRAN), "build"], project)
|
|
# Harmony and other hosts pass their driver through nested make.
|
|
# The profile must still use its resolved absolute toolchain path.
|
|
run([str(ZIRAN), "build"], project, makeflags=" -- ZIRAN=ziran")
|
|
run([str(ZIRAN), "check"], project)
|
|
result = run([str(project / "build/host_probe-tui"), "--probe"], project)
|
|
assert result.stdout == "custom host\n", result.stdout
|
|
|
|
# The package tool first saves IR. Native capability selection must
|
|
# survive that route without making portable bundles require pthreads.
|
|
(project / "src/raster.zi").write_text(
|
|
'#import "kryon/pixmap"\n'
|
|
'pixels: [81920]u32;\n'
|
|
'#program_export\nmain :: () -> s32 {\n'
|
|
' if !PixmapBeginInto(cast(u32)0, 320, 256, pixels[:]) { return 1 }\n'
|
|
' print("workers %\\n", PixmapWorkerCount())\n'
|
|
' PixmapEndInto(); PixmapCloseWorkers(); return 0\n}\n'
|
|
)
|
|
with (project / "ziran.toml").open('a') as manifest:
|
|
manifest.write(
|
|
'\n[tool.kryon.profiles.raster]\nbackend = "terminal"\nhost = "src/raster.zi"\n'
|
|
'\n[tool.kryon.profiles.portable]\nbackend = "desktop"\ncodegen = "zx"\nhost = "src/raster.zi"\n'
|
|
)
|
|
run([str(ZIRAN), "tool", "kryon", "build", "raster"], project)
|
|
for count in (1, None, 8):
|
|
result = run([str(project / "build/host_probe-raster")], project,
|
|
env_updates={'ZIRAN_PAR_THREADS': str(count)} if count else None)
|
|
assert result.stdout == f"workers {count or 4}\n", result.stdout
|
|
run([str(ZIRAN), "tool", "kryon", "build", "portable"], project)
|
|
result = run([str(ZIRAN), "run", str(project / "build/host_probe-portable.zx")], project)
|
|
assert result.stdout.splitlines()[0] == "workers 1", result.stdout
|
|
|
|
outside = Path(temporary) / "outside.zi"
|
|
outside.write_text((project / "src/runner.zi").read_text())
|
|
(project / "src/escape.zi").symlink_to(outside)
|
|
manifest = project / "ziran.toml"
|
|
manifest.write_text(manifest.read_text().replace("src/runner.zi", "src/escape.zi"))
|
|
result = run([str(ZIRAN), "build"], project, success=False)
|
|
assert "host must stay inside the project" in result.stderr, result.stderr
|
|
print("Project-owned host build, execution, and path containment passed")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|