Integrate the locked TSX SDK and native Profile provider

This commit is contained in:
waozi committed 2026-11-30 00:49:55 -03:00
1 parent b729b8996e
commit 20827fefbf
6 files changed
+107 -32

No files matched your search

+5
View File
@@ -2,6 +2,11 @@
## [Unreleased]
- Share Ziran 52aa4063 and Kryon 7f9c3c48 with TSX application consumers
and native hosts through the ordinary locked package graph.
- Pass declared native dependencies to the SDK when packaging Profile bundles
for Linux and Android.
- Use Kryon's published Android frame readiness, portable audio and asset fixes.
- Pin Ziran f065682d and Kryon 55a24a22 so Profile and native hosts share the final TSX widget graph.
+4 -1
View File
@@ -20,7 +20,10 @@ env = dict(os.environ)
for key in ('DISPLAY', 'WAYLAND_DISPLAY', 'XAUTHORITY', 'DBUS_SESSION_BUS_ADDRESS', 'SESSION_MANAGER',
'GDK_DISPLAY', 'DESKTOP_SESSION', 'XDG_SESSION_ID', 'XDG_SESSION_TYPE', 'XDG_CURRENT_DESKTOP'):
env.pop(key, None)
bun = env.get('BUN') or shutil.which('bun') or str(Path.home() / '.bun/bin/bun')
bun_command = env.get('BUN') or shutil.which('bun') or str(Path.home() / '.bun/bin/bun')
bun = shutil.which(bun_command)
if bun is None:
raise SystemExit(f'Canvas Profile tests require Bun. Set BUN to an executable (tried {bun_command}).')
env.update(EM_NODE_JS=bun, JS_RUNTIME=bun, YUE_DESKTOP_RECOVERY='0',
ZIRAN_JOBS='1', EMCC_CORES='1', CMAKE_BUILD_PARALLEL_LEVEL='1')
# Consumer commands resolve their own manifest and selected toolchain.
+58 -19
View File
@@ -13,7 +13,6 @@ os.sched_setaffinity(0, {min(os.sched_getaffinity(0))})
ROOT = Path(__file__).resolve().parents[1]
WORK = ROOT / 'work/recipe-provider'
ZIRAN = str(ROOT / 'scripts/ziran.sh')
ENV = {k: v for k, v in os.environ.items() if k not in
('DISPLAY', 'WAYLAND_DISPLAY', 'XAUTHORITY', 'DBUS_SESSION_BUS_ADDRESS', 'SESSION_MANAGER')}
ENV.update(MAKEFLAGS='-j1', CMAKE_BUILD_PARALLEL_LEVEL='1', ZIRAN_BUILD_JOBS='1',
@@ -67,19 +66,51 @@ def consume(app, profile, crypto):
headers.mkdir(exist_ok=True)
run(['tar', '-xf', profile / 'headers.tar', '-C', headers])
# Call real native host policy and real Monocypher without keys/accounts.
(app / 'consumer.c').write_text('#include "src/native_host.h"\n#include <stddef.h>\n'
'extern void crypto_wipe(void *, size_t);\n'
'extern void *OQS_SIG_new(const char *); extern void OQS_SIG_free(void *);\n'
'int main(int argc, char **argv) { unsigned char b[8]={1,2,3}; '
'native_host_EntityHostProfileSections(7); native_host_EntityHostEdition(0); '
'crypto_wipe(b, sizeof b); void *sig=OQS_SIG_new("ML-DSA-44"); '
'if (!sig) return 1; OQS_SIG_free(sig); '
'if (argc > 1) { void *bundle=OpenBundle((uint8_t *)argv[1]); if (!bundle) return 2; '
'uint64_t count=BundleAssets(bundle); CloseBundle(bundle); if (!count) return 3; } '
'return b[0] != 0; }\n')
(app / 'consumer.c').write_text('''\
#include "src/native_host.h"
#include <stddef.h>
extern void crypto_wipe(void *, size_t);
extern void *OQS_SIG_new(const char *);
extern void OQS_SIG_free(void *);
int check_bundle(const char *path);
int main(int argc, char **argv) {
unsigned char data[8] = {1, 2, 3};
native_host_EntityHostProfileSections(7);
native_host_EntityHostEdition(0);
crypto_wipe(data, sizeof data);
void *sig = OQS_SIG_new("ML-DSA-44");
if (!sig || data[0]) return 1;
OQS_SIG_free(sig);
if (argc != 2) return 2;
return check_bundle(argv[1]);
}
''')
# The generated native header includes its own Ziran bundle types.
(app / 'bundle.c').write_text('''\
#include "ziran_host.h"
#include <string.h>
int check_bundle(const char *path) {
Bundle *bundle = BundleOpen(path);
if (!bundle) return 3;
int picture = 0, backdrop = 0;
for (size_t i = 0; i < BundleAssetCount(bundle); ++i) {
const char *name = BundleAssetName(bundle, i);
if (!name || BundleAssetSize(bundle, i) < 12) continue;
const unsigned char *data = BundleAssetData(bundle, i);
if (!data || memcmp(data, "RIFF", 4) || memcmp(data + 8, "WEBP", 4)) continue;
picture |= strcmp(name, "assets/entity/pfp.webp") == 0;
backdrop |= strcmp(name, "assets/entity/abstract-jade.webp") == 0;
}
BundleClose(bundle);
return picture && backdrop ? 0 : 4;
}
''')
flags = link_flags(profile / 'link.txt', crypto / 'link.txt')
run(['cc', '-std=c11', '-O2', '-ffunction-sections', '-fdata-sections', '-Wl,--gc-sections', '-I', headers, '-I', headers / 'ziran',
app / 'consumer.c', *flags,
app / 'consumer.c', app / 'bundle.c', *flags,
'-o', app / 'consumer'])
run([app / 'consumer', profile / 'entity.zx'])
@@ -95,6 +126,7 @@ def main():
dirty.add_argument('--toolchain', default='', help='exact published consumer toolchain commit')
args = dirty.parse_args()
allow_dirty = args.dirty
flags = ['--locked'] if args.published else []
for commit in (args.published, args.toolchain):
assert not commit or (len(commit) == 40 and all(c in '0123456789abcdef' for c in commit))
tool_ref = args.toolchain or json.loads((ROOT / 'ziran.lock').read_text())['toolchain']['commit']
@@ -108,8 +140,8 @@ def main():
app.mkdir(exist_ok=True)
(app / 'src').mkdir(exist_ok=True)
(app / 'ziran.toml').write_text('[package]\nname="' + name + '"\n'
'[toolchain]\ngit="https://github.com/ziranlang/ziran.git"\nref="' + tool_ref + '"\n'
'[dependencies.entity]\ngit="https://github.com/waozixyz/entity.git"\nref="' + (args.published or 'master') + '"\n')
'[toolchain]\ngit="https://git.waozi.xyz/ziranlang/ziran.git"\nref="' + tool_ref + '"\n'
'[dependencies.entity]\ngit="https://git.waozi.xyz/waozi/entity.git"\nref="' + (args.published or 'master') + '"\n')
if args.published:
(app / 'ziran.local.toml').unlink(missing_ok=True)
else:
@@ -118,21 +150,26 @@ def main():
f'{json.dumps(name)}={json.dumps(str((ROOT / path).resolve()))}' + '\n'
for name, path in overrides.items()))
run(['ziran', 'lock'], app)
selected = Path(run(['ziran', 'pkg', 'path', 'ziran'], app))
selected = Path(run(['ziran', 'pkg', 'path', 'ziran', *flags], app))
if args.published:
provider = Path(run(['ziran', 'pkg', 'path', 'entity', '--locked'], app))
assert run(['git', 'rev-parse', 'HEAD'], selected) == tool_ref
assert run(['git', 'rev-parse', 'HEAD'], provider) == args.published
assert compiler is None or compiler == selected
compiler = selected
apps.append(app)
def build(app, recipe='native-profile', target='linux-x86_64-gnu', ok=True):
return run([compiler / 'build/bin/ziran', 'pkg', 'artifact', 'entity:' + recipe,
'--platform', target], app, ok)
'--platform', target, *flags], app, ok)
first = descriptor(build(apps[0]))
second = descriptor(build(apps[1]))
(WORK / "attempt.json").write_text(json.dumps({"one": str(first), "two": str(second)}))
dependencies = dict(line.split('\t', 1) for line in (first.parent / 'dependencies.tsv').read_text().splitlines())
crypto = descriptor(dependencies['self:native-crypto'])
assert (first.parent / 'entity.zx').stat().st_size > 1000
for app in apps:
consume(app, first.parent, crypto.parent)
for app, profile in zip(apps, (first, second)):
edge = dict(line.split('\t', 1) for line in (profile.parent / 'dependencies.tsv').read_text().splitlines())
consume(app, profile.parent, descriptor(edge['self:native-crypto']).parent)
print('Linked both external native consumers successfully', flush=True)
if allow_dirty:
assert first != second, 'dirty graph artifacts must remain isolated'
@@ -145,7 +182,9 @@ def main():
assert descriptor(first) == first
(apps[1] / 'ziran.toml').write_text((apps[1] / 'ziran.toml').read_text().replace('fdroid', 'invalid'))
build(apps[1], ok=False)
print(('DIRTY isolation mode: ' if allow_dirty else 'CLEAN reuse mode: ') + 'PASS: linked two external native profile/crypto consumers; shared artifact; edition separation; unsupported target/options rejected')
artifact_behavior = 'isolated dirty artifacts' if allow_dirty else 'shared immutable artifact'
print(f'PASS: two external native profile/crypto consumers, {artifact_behavior}, '
'edition separation, and unsupported target/options rejected')
(WORK / 'adoption.txt').write_text(f'native-profile\t{first}\nnative-crypto\t{crypto}\nfdroid\t{different}\n')
+31 -3
View File
@@ -196,10 +196,31 @@ ProfileMap :: () -> string {
}
return PkgWriteMap(root, dependencies, *graph.packages[provider].manifest)
}
Profile :: () -> bool {
// The generic driver has already built and verified this requirement.
// The package driver writes one request and its verified descriptor per row.
NativeDependencies :: (arguments: *Vec(string)) -> bool {
deps := PkgRead(PkgGetenv("ZIRAN_ARTIFACT_DEPENDENCIES"))
if !deps.valid || !TextHasPrefix(deps.text, "self:native-crypto\t") { return false }
if !deps.valid {
PkgFail("cannot read Entity native-profile dependencies")
return false
}
crypto := false
lines := TextLines(deps.text)
for lines {
at := TextFind(it, "\t")
if at <= 0 || at >= it.count - 1 || !TextHasPrefix(it[at + 1:], "/") || TextFind(it, "\t", at + 1) >= 0 {
PkgFail("invalid Entity native-profile dependency row")
return false
}
if it[0:at] == "self:native-crypto" { crypto = true }
VecPush(arguments.*, "--native-artifact")
VecPush(arguments.*, PkgJoin(it[at + 1:], ""))
}
if !crypto { PkgFail("Entity native-profile requires self:native-crypto") }
return crypto
}
Profile :: () -> bool {
native_flags: Vec(string)
if !NativeDependencies(*native_flags) { return false }
generated := Out("generated")
define := ifx edition == "play" then "GOOGLE_PLAY" else ifx edition == "fdroid" then "FDROID" else "ENTITY_DIRECT"
// Generate Entity as the root module so the public native header/symbol names
@@ -229,6 +250,13 @@ Profile :: () -> bool {
args: Vec(string)
initial: [5]string = .["env", Flag("ZIRAN_PACKAGE_MAP=", module_map), JoinPath(PkgGetenv("ZIRAN_TOOLCHAIN_ROOT"), "build/bin/zi2zx"), "--root", root]
for initial { VecPush(args, it) }
// The SDK packages native artifacts for Linux and Android hosts; web and
// Windows profiles link their declared descriptors through link.txt.
if !web && !windows {
for native_flags { VecPush(args, it) }
VecPush(args, "--native-platform")
VecPush(args, platform)
}
rest: [11]string = .["--define", "KRYON_HOSTED_UI", "--asset-dir", Flag("assets=", JoinPath(assets, "assets")), "--entry", "entity_ui:main", "-o", Out("entity.zx"), JoinPath(root, "src/entity_ui.tsx"), "", ""]
for rest { if it.count > 0 { VecPush(args, it) } }
return PkgRunToStderr(VecSlice(args, 0, args.count), project) == 0 && PkgWrite(Out("link.txt"), LinkText(true))
+7 -7
View File
@@ -101,12 +101,12 @@
"url": "https://github.com/xiph/opus.git"
},
{
"commit": "5ea2f9a3889401a5d94f97d083f5716140343a2a",
"commit": "7f9c3c4811cf921204a4af4128a250ac8a1e3d17",
"dependencies": {"audio": "waozi_xyz_ziranlang_audio_b5c6b56b7117", "avif": "waozi_xyz_ziranlang_avif_6ff696d436b6", "image_codec": "waozi_xyz_ziranlang_image_codec_3017f0d1cc56", "libaom": "src_aomedia_googlesource_com_aom_b141d9c45db2", "libavif": "src_github_com_AOMediaCodec_libavif_1aadfad932c9", "libwebp": "src_github_com_webmproject_libwebp_1844042d1ca7", "sdl3": "src_github_com_libsdl_org_SDL_829a65d769d9", "webp": "waozi_xyz_ziranlang_webp_4b9a61d32460"},
"dependency_refs": {"audio": "b5c6b56b71172c4361ae01e3afdd2118bdac0975", "avif": "6ff696d436b6b4f142eb1e3ecf210de7adfa048f", "image_codec": "3017f0d1cc56975aa29c600a1f55a62e1193cf7b", "libaom": "b141d9c45db236335351c8a4b2a14b3ade27c937", "libavif": "1aadfad932c98c069a1204261b1856f81f3bc199", "libwebp": "1844042d1ca751e62e61df7617dba19c98588339", "sdl3": "829a65d769d935c4852f8159e964312c0957260a", "webp": "4b9a61d32460d481624fe0f83996a7de50327dfe"},
"id": "waozi_xyz_kryonlabs_kryon_5ea2f9a38894",
"id": "waozi_xyz_kryonlabs_kryon_7f9c3c4811cf",
"name": "kryon",
"ref": "5ea2f9a3889401a5d94f97d083f5716140343a2a",
"ref": "7f9c3c4811cf921204a4af4128a250ac8a1e3d17",
"url": "https://git.waozi.xyz/kryonlabs/kryon.git"
},
{
@@ -189,13 +189,13 @@
}
],
"root": {
"dependencies": {"crypto": "waozi_xyz_ziranlang_crypto_b650c1444b99", "curl": "src_github_com_curl_curl_19b299005fbe", "kryon": "waozi_xyz_kryonlabs_kryon_5ea2f9a38894", "mesh_client": "waozi_xyz_ziranlang_mesh_client_90bc9108e4f7", "monocypher": "src_github_com_LoupVaillant_Monocypher_e65d27722a43", "oqs": "waozi_xyz_ziranlang_oqs_22d2ddbdc236", "qrcode": "waozi_xyz_ziranlang_qrcode_2944b2e668e7", "zlib": "src_github_com_madler_zlib_51b7f2abdade"},
"dependency_refs": {"crypto": "b650c1444b99a672d78b5c1a54f7026b345c1dfe", "curl": "19b299005fbe2d895f4ad525cfdae62a2220c3ea", "kryon": "5ea2f9a3889401a5d94f97d083f5716140343a2a", "mesh_client": "90bc9108e4f73d39c4af25f3e8ec681d06a56163", "monocypher": "e65d27722a43e9ed88da1987f3ad5675503c8cad", "oqs": "22d2ddbdc236796953c905a05a2cebf5ab1b4ff3", "qrcode": "2944b2e668e735438d8ce24e47a39be3f5c36af5", "zlib": "51b7f2abdade71cd9bb0e7a373ef2610ec6f9daf"},
"dependencies": {"crypto": "waozi_xyz_ziranlang_crypto_b650c1444b99", "curl": "src_github_com_curl_curl_19b299005fbe", "kryon": "waozi_xyz_kryonlabs_kryon_7f9c3c4811cf", "mesh_client": "waozi_xyz_ziranlang_mesh_client_90bc9108e4f7", "monocypher": "src_github_com_LoupVaillant_Monocypher_e65d27722a43", "oqs": "waozi_xyz_ziranlang_oqs_22d2ddbdc236", "qrcode": "waozi_xyz_ziranlang_qrcode_2944b2e668e7", "zlib": "src_github_com_madler_zlib_51b7f2abdade"},
"dependency_refs": {"crypto": "b650c1444b99a672d78b5c1a54f7026b345c1dfe", "curl": "19b299005fbe2d895f4ad525cfdae62a2220c3ea", "kryon": "7f9c3c4811cf921204a4af4128a250ac8a1e3d17", "mesh_client": "90bc9108e4f73d39c4af25f3e8ec681d06a56163", "monocypher": "e65d27722a43e9ed88da1987f3ad5675503c8cad", "oqs": "22d2ddbdc236796953c905a05a2cebf5ab1b4ff3", "qrcode": "2944b2e668e735438d8ce24e47a39be3f5c36af5", "zlib": "51b7f2abdade71cd9bb0e7a373ef2610ec6f9daf"},
"name": "Entity"
},
"toolchain": {
"commit": "f065682d0dd8def8cb411d1362694d7378f7c172",
"ref": "f065682d0dd8def8cb411d1362694d7378f7c172",
"commit": "52aa406339da1e6d3c064d785f266dc87bdfd57d",
"ref": "52aa406339da1e6d3c064d785f266dc87bdfd57d",
"url": "https://git.waozi.xyz/ziranlang/ziran.git"
}
}
+2 -2
View File
@@ -5,11 +5,11 @@ module_roots = ["src", "tests"]
[toolchain]
git = "https://git.waozi.xyz/ziranlang/ziran.git"
ref = "f065682d0dd8def8cb411d1362694d7378f7c172"
ref = "52aa406339da1e6d3c064d785f266dc87bdfd57d"
[dependencies.kryon]
git = "https://git.waozi.xyz/kryonlabs/kryon.git"
ref = "5ea2f9a3889401a5d94f97d083f5716140343a2a"
ref = "7f9c3c4811cf921204a4af4128a250ac8a1e3d17"
[exports]
canvas_profile_host = "src/canvas_profile_host.zi"