@native-sdk/cli 0.7.2 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/app.zig +265 -65
- package/build/ts_run.mjs +6 -8
- package/build.zig +292 -349
- package/package.json +13 -11
- package/packages/core/compile-surface/core.ts +559 -0
- package/packages/core/package-lock.json +375 -12
- package/packages/core/package.json +9 -6
- package/packages/core/scripts/compiler_typecheck.mjs +58 -0
- package/packages/core/scripts/gen_case_tables.mjs +130 -0
- package/packages/core/scripts/gen_declarations.mjs +97 -0
- package/packages/core/scripts/run_external_core_compiler.mjs +108 -0
- package/packages/core/scripts/stage_external_core.mjs +148 -0
- package/packages/core/sdk/core.d.ts +363 -0
- package/packages/core/sdk/events.d.ts +65 -0
- package/packages/core/sdk/text.d.ts +51 -0
- package/packages/core/src/checker.ts +3 -3
- package/packages/core/src/cli.ts +40 -38
- package/packages/core/src/contract.ts +749 -0
- package/packages/core/src/devhost.ts +4 -3
- package/packages/core/src/diagnostics.ts +5 -7
- package/packages/core/src/{transpile.ts → frontend.ts} +38 -50
- package/packages/core/src/infer.ts +1 -1
- package/packages/core/src/typed_ast.ts +16 -15
- package/packages/core/src/wyhash.ts +79 -0
- package/skill-data/native-ui/SKILL.md +3 -2
- package/skill-data/ts-core/SKILL.md +29 -29
- package/src/platform/macos/appkit_host.h +4 -4
- package/src/platform/macos/appkit_host.m +24 -4
- package/src/platform/macos/cef_host.mm +22 -6
- package/src/platform/macos/root.zig +2 -2
- package/src/primitives/canvas/markdown.zig +2010 -57
- package/src/primitives/canvas/markdown_hostile_tests.zig +40 -0
- package/src/primitives/canvas/markdown_tests.zig +778 -3
- package/src/primitives/canvas/ui_markup.zig +9 -1
- package/src/primitives/canvas/ui_markup_compiled.zig +29 -0
- package/src/primitives/canvas/ui_markup_contract.zig +11 -0
- package/src/primitives/canvas/ui_markup_view.zig +20 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +13 -1
- package/src/primitives/canvas/ui_schema.zig +3 -0
- package/src/primitives/canvas/ui_schema_tests.zig +4 -3
- package/src/primitives/canvas/widget_layout.zig +26 -3
- package/src/primitives/canvas/widget_metrics.zig +21 -3
- package/src/primitives/canvas/widget_render.zig +6 -1
- package/src/runtime/effects.zig +9 -0
- package/src/runtime/effects_fetch_tests.zig +21 -0
- package/src/runtime/ts_core_host.zig +38 -38
- package/src/runtime/ts_ui_app.zig +12 -12
- package/src/tooling/manifest.zig +32 -0
- package/src/tooling/raw_manifest.zig +4 -0
- package/src/tooling/templates.zig +25 -20
- package/src/tooling/ts_core.zig +55 -34
- package/src/tooling/verbs.zig +1 -1
- package/tools/corewire/core_abi.zig +169 -0
- package/tools/corewire/emit.zig +2418 -0
- package/tools/corewire/emit_facade.zig +3984 -0
- package/tools/corewire/emit_profile.zig +501 -0
- package/tools/corewire/main.zig +561 -0
- package/tools/corewire/shim_rt.zig +632 -0
- package/tools/corewire/sidecar.zig +2507 -0
- package/packages/core/rt/rt.zig +0 -1986
- package/packages/core/src/emitter.ts +0 -11898
package/build/app.zig
CHANGED
|
@@ -54,9 +54,10 @@ pub const AppOptions = struct {
|
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
/// Which core the app tree carries. No flag and no config anywhere: the
|
|
57
|
-
/// tree IS the truth — `src/core.ts` is a TypeScript core (
|
|
58
|
-
/// build time, run through generated wiring),
|
|
59
|
-
/// and both at once is a teaching error
|
|
57
|
+
/// tree IS the truth — `src/core.ts` is a TypeScript core (compiled to
|
|
58
|
+
/// native code at build time, run through generated wiring),
|
|
59
|
+
/// `src/main.zig` a Zig one, and both at once is a teaching error
|
|
60
|
+
/// naming the two files.
|
|
60
61
|
const CoreTree = enum { zig, ts, both, neither };
|
|
61
62
|
|
|
62
63
|
fn detectCoreTree(b: *std.Build, app_root: []const u8) CoreTree {
|
|
@@ -73,15 +74,39 @@ fn appFileExists(b: *std.Build, app_root: []const u8, sub_path: []const u8) bool
|
|
|
73
74
|
return true;
|
|
74
75
|
}
|
|
75
76
|
|
|
77
|
+
/// How a TypeScript core compiles: through the external core compiler,
|
|
78
|
+
/// always. The frontend checks the core and emits its contract sidecar,
|
|
79
|
+
/// corewire projects the compile entry and profile, the exact-pinned
|
|
80
|
+
/// external toolchain builds the archive, and the app links corewire's
|
|
81
|
+
/// generated mirror over it. `.core_compiler` in app.zon (and the
|
|
82
|
+
/// `-Dcore-compiler` flag) accept only "external" — the value exists so
|
|
83
|
+
/// a stated choice stays stateable; the removed transpiled lane's
|
|
84
|
+
/// spelling is refused with a teaching (see resolveCoreCompiler).
|
|
85
|
+
const core_compiler_teaching =
|
|
86
|
+
"\ncore_compiler = \"transpiler\" names the removed TS-to-Zig transpiled lane (v0.7.0" ++
|
|
87
|
+
" removed it): a TypeScript core compiles through the external core compiler now, and" ++
|
|
88
|
+
" that is the default.\nDelete the setting (or spell it \"external\").\n";
|
|
89
|
+
|
|
76
90
|
/// The staged TypeScript-core wiring: one generated directory holding the
|
|
77
|
-
///
|
|
78
|
-
/// SDK's generated-wiring entry (ts_core_main.zig
|
|
79
|
-
///
|
|
91
|
+
/// core module (the generated mirror with its staged shim runtime), the
|
|
92
|
+
/// app's markup, and the SDK's generated-wiring entry (ts_core_main.zig
|
|
93
|
+
/// as main.zig) — plus the compiled-core archive the app module links
|
|
94
|
+
/// behind the mirror. Built once per app build and shared by the exe
|
|
95
|
+
/// and test modules.
|
|
80
96
|
const TsCoreStage = struct {
|
|
81
97
|
main_root: std.Build.LazyPath,
|
|
98
|
+
/// The compiled-core archive: the app module links it (with libc,
|
|
99
|
+
/// for the toolchain's runtime) beside the staged mirror.
|
|
100
|
+
archive: std.Build.LazyPath,
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/// The frontend's own sources — the staleness set of every build step
|
|
104
|
+
/// that runs it (a frontend edit re-checks every core).
|
|
105
|
+
const frontend_sources = [_][]const u8{
|
|
106
|
+
"checker.ts", "cli.ts", "contract.ts", "diagnostics.ts", "frontend.ts", "infer.ts", "modules.ts", "ownership.ts", "typed_ast.ts", "types.ts", "wyhash.ts",
|
|
82
107
|
};
|
|
83
108
|
|
|
84
|
-
/// Whether the
|
|
109
|
+
/// Whether the frontend's TypeScript compiler (@typescript/old, the
|
|
85
110
|
/// exactly pinned npm alias of the real `typescript` package) RESOLVES
|
|
86
111
|
/// from the SDK's packages/core, by node's ancestor node_modules walk —
|
|
87
112
|
/// at the SDK's exactly pinned VERSION. The same semantics the CLI gates
|
|
@@ -99,17 +124,13 @@ const TsCoreStage = struct {
|
|
|
99
124
|
/// (nested under the package on global prefixes, hoisted to the project
|
|
100
125
|
/// root on local ones, pnpm's sibling node_modules).
|
|
101
126
|
///
|
|
102
|
-
///
|
|
103
|
-
///
|
|
104
|
-
///
|
|
105
|
-
/// alias's version as seen FROM
|
|
106
|
-
/// can only FALSE-REJECT healthy trees
|
|
107
|
-
///
|
|
108
|
-
///
|
|
109
|
-
/// runtime loads from packages/core; a consumer's own shadowing wrapper
|
|
110
|
-
/// must not sway the verdict either. The wrapper stays a DECLARED
|
|
111
|
-
/// dependency in both manifests — it is just not what validation vouches
|
|
112
|
-
/// for (see the twin's doc comment).
|
|
127
|
+
/// A stray `@typescript/typescript6` compat wrapper in a consumer tree
|
|
128
|
+
/// (a former dependency of this package, or the consumer's own) is
|
|
129
|
+
/// deliberately NOT probed: nothing imports it at run time, and holding
|
|
130
|
+
/// the alias's version as seen FROM a wrapper's origin against the pin
|
|
131
|
+
/// can only FALSE-REJECT healthy trees — a consumer's hoisted conflicting
|
|
132
|
+
/// `@typescript/old` wins the walk from there while the copy runtime
|
|
133
|
+
/// actually loads sits correctly pinned under packages/core.
|
|
113
134
|
///
|
|
114
135
|
/// Resolvable means the alias's manifest AND its entrypoint are present
|
|
115
136
|
/// (see tsAliasedCompilerVersion for node's error shape and the
|
|
@@ -217,6 +238,29 @@ fn tsParseQuotedManifestValue(manifest_json: []const u8, comptime key: []const u
|
|
|
217
238
|
return suffix;
|
|
218
239
|
}
|
|
219
240
|
|
|
241
|
+
/// The external core compiler's entry module (scriptc's dist/main.js),
|
|
242
|
+
/// resolved by node's ancestor node_modules walk from the SDK's
|
|
243
|
+
/// packages/core — the same origin the frontend toolchain resolves from
|
|
244
|
+
/// (tsAliasedCompilerVersion's walk, kept in lockstep). Repo checkouts
|
|
245
|
+
/// install it there with `npm ci`; the npm-installed CLI carries the
|
|
246
|
+
/// compiler as a regular dependency, nested under the package on global
|
|
247
|
+
/// prefixes and hoisted to the project root on local ones.
|
|
248
|
+
fn tsExternalCompilerJs(b: *std.Build, dep: *std.Build.Dependency) ?[]const u8 {
|
|
249
|
+
const io = b.graph.io;
|
|
250
|
+
const sdk_root = tsSdkRoot(b.allocator, io, dep);
|
|
251
|
+
var dir: []const u8 = b.pathJoin(&.{ sdk_root, "packages", "core" });
|
|
252
|
+
while (true) {
|
|
253
|
+
if (!std.mem.eql(u8, std.fs.path.basename(dir), "node_modules")) {
|
|
254
|
+
const candidate = b.pathJoin(&.{ dir, "node_modules", "scriptc", "dist", "main.js" });
|
|
255
|
+
found: {
|
|
256
|
+
std.Io.Dir.cwd().access(io, candidate, .{}) catch break :found;
|
|
257
|
+
return candidate;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
dir = std.fs.path.dirname(dir) orelse return null;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
220
264
|
/// The SDK dependency's real root, resolved the way both the toolchain
|
|
221
265
|
/// check and its teaching name it.
|
|
222
266
|
fn tsSdkRoot(allocator: std.mem.Allocator, io: std.Io, dep: *std.Build.Dependency) []const u8 {
|
|
@@ -224,15 +268,19 @@ fn tsSdkRoot(allocator: std.mem.Allocator, io: std.Io, dep: *std.Build.Dependenc
|
|
|
224
268
|
return std.Io.Dir.cwd().realPathFileAlloc(io, raw_root, allocator) catch raw_root;
|
|
225
269
|
}
|
|
226
270
|
|
|
227
|
-
|
|
271
|
+
/// The TS-core preflight — the markup view, node, and the frontend
|
|
272
|
+
/// toolchain gate — returning the resolved node program. The frontend
|
|
273
|
+
/// (the subset checker and the contract-sidecar emitter) runs under
|
|
274
|
+
/// node; the compile itself is the external toolchain's.
|
|
275
|
+
fn tsCorePreflight(b: *std.Build, dep: *std.Build.Dependency, app_root: []const u8) []const u8 {
|
|
228
276
|
if (!appFileExists(b, app_root, "src/app.native")) {
|
|
229
277
|
@panic("\nthis app has a TypeScript core (src/core.ts) but no view: TS apps render markup," ++
|
|
230
|
-
" so add src/app.native (the whole view tier binds the core's
|
|
278
|
+
" so add src/app.native (the whole view tier binds the core's model)\n");
|
|
231
279
|
}
|
|
232
280
|
const node = b.findProgram(&.{"node"}, &.{}) catch {
|
|
233
|
-
@panic("\nbuilding a TypeScript app core needs node on PATH (the @native-sdk/core
|
|
234
|
-
" build time; the binary
|
|
235
|
-
" — https://nodejs.org or `brew install node` — and re-run.\n");
|
|
281
|
+
@panic("\nbuilding a TypeScript app core needs node on PATH (the @native-sdk/core frontend checks the" ++
|
|
282
|
+
" core at build time; the binary you ship carries no JS runtime).\nInstall Node.js 22.15+ (on the 23" ++
|
|
283
|
+
" line: 23.5+) — https://nodejs.org or `brew install node` — and re-run.\n");
|
|
236
284
|
};
|
|
237
285
|
switch (tsToolchainResolution(b, dep)) {
|
|
238
286
|
.resolved => {},
|
|
@@ -246,7 +294,7 @@ fn tsCoreStage(b: *std.Build, dep: *std.Build.Dependency, app_root: []const u8)
|
|
|
246
294
|
const sdk_root = tsSdkRoot(dep.builder.allocator, dep.builder.graph.io, dep);
|
|
247
295
|
std.debug.print(
|
|
248
296
|
\\
|
|
249
|
-
\\error: the @native-sdk/core
|
|
297
|
+
\\error: the @native-sdk/core frontend cannot resolve its TypeScript toolchain
|
|
250
298
|
\\(its compiler, @typescript/old). On a repo checkout, install it once with:
|
|
251
299
|
\\ cd {s}/packages/core && npm ci --include=dev
|
|
252
300
|
\\(An npm-installed @native-sdk/cli carries the toolchain automatically; if it
|
|
@@ -264,7 +312,7 @@ fn tsCoreStage(b: *std.Build, dep: *std.Build.Dependency, app_root: []const u8)
|
|
|
264
312
|
// to move.
|
|
265
313
|
std.debug.print(
|
|
266
314
|
\\
|
|
267
|
-
\\error: the @native-sdk/core
|
|
315
|
+
\\error: the @native-sdk/core frontend's TypeScript compiler resolves at the
|
|
268
316
|
\\wrong version: @typescript/old resolves to typescript {s}, but the SDK pins
|
|
269
317
|
\\npm:typescript@{s}. Another package in this tree pins a conflicting
|
|
270
318
|
\\@typescript/old - align it with the SDK's pin (or remove it) and reinstall,
|
|
@@ -275,43 +323,164 @@ fn tsCoreStage(b: *std.Build, dep: *std.Build.Dependency, app_root: []const u8)
|
|
|
275
323
|
std.process.exit(1);
|
|
276
324
|
},
|
|
277
325
|
}
|
|
326
|
+
return node;
|
|
327
|
+
}
|
|
278
328
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
//
|
|
294
|
-
//
|
|
295
|
-
//
|
|
296
|
-
//
|
|
297
|
-
//
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
329
|
+
/// The TypeScript-core compile lane: the frontend checks the core and
|
|
330
|
+
/// emits its contract sidecar, corewire projects the generated compile
|
|
331
|
+
/// entry and library-mode profile, the stager assembles the compile
|
|
332
|
+
/// tree (author sources with the mechanical staging transforms, the
|
|
333
|
+
/// staged SDK modules, the static compile surface), the exact-pinned
|
|
334
|
+
/// external toolchain builds the archive AND co-emits the archive's own
|
|
335
|
+
/// contract sidecar, and corewire generates the mirror module from THAT
|
|
336
|
+
/// document — so the boot identity fence always pairs the mirror with
|
|
337
|
+
/// its own compile. The staged module directory carries core.zig (the
|
|
338
|
+
/// mirror) + its staged runtime + app.native + main.zig, so the
|
|
339
|
+
/// generated wiring imports one fixed shape.
|
|
340
|
+
fn tsCoreStage(b: *std.Build, dep: *std.Build.Dependency, app_root: []const u8, app_name: []const u8) TsCoreStage {
|
|
341
|
+
const node = tsCorePreflight(b, dep, app_root);
|
|
342
|
+
|
|
343
|
+
// The frontend, in check-only mode: the subset checker and the
|
|
344
|
+
// contract sidecar, no emission. Every check-time teaching gates the
|
|
345
|
+
// compile here — the checker's NS diagnostics stream to stderr
|
|
346
|
+
// verbatim; nothing wraps them. The frontend runs through
|
|
347
|
+
// build/ts_run.mjs, not as `node cli.ts`: on the npm-installed
|
|
348
|
+
// layout the frontend's .ts sources live inside node_modules, where
|
|
349
|
+
// node refuses its builtin type stripping — the runner strips those
|
|
350
|
+
// modules with the frontend's own installed TypeScript and is a
|
|
351
|
+
// pass-through on a repo checkout. The frontend reads its own
|
|
352
|
+
// sources, the SDK modules, and the core's WHOLE import graph at
|
|
353
|
+
// run time; declare them all so an edit to ANY module of a
|
|
354
|
+
// multi-file core re-checks it (every .ts under src/ is a superset
|
|
355
|
+
// of the reachable imports: over-approximation only re-runs the
|
|
356
|
+
// check, never misses a stale input).
|
|
357
|
+
const check = b.addSystemCommand(&.{node});
|
|
358
|
+
check.addFileArg(dep.path("build/ts_run.mjs"));
|
|
359
|
+
check.addFileArg(dep.path("packages/core/src/cli.ts"));
|
|
360
|
+
check.addFileArg(b.path(appPath(b, app_root, "src/core.ts")));
|
|
361
|
+
check.addArg("--contract");
|
|
362
|
+
const contract = check.addOutputFileArg("core.contract.json");
|
|
363
|
+
// The document's entry spelling is app-relative (the sidecar/facade
|
|
364
|
+
// contract carries no machine paths).
|
|
365
|
+
check.addArgs(&.{ "--contract-entry", "src/core.ts" });
|
|
366
|
+
addTsDirInputs(b, dep.builder, check, "packages/core/sdk");
|
|
367
|
+
addAppTsDirInputs(b, check, appPath(b, app_root, "src"));
|
|
368
|
+
for (frontend_sources) |source| {
|
|
369
|
+
check.addFileInput(dep.path(b.fmt("packages/core/src/{s}", .{source})));
|
|
305
370
|
}
|
|
306
371
|
|
|
307
|
-
//
|
|
308
|
-
//
|
|
372
|
+
// corewire, compiled from the SDK dependency for the build host: one
|
|
373
|
+
// invocation projects the generated compile entry and its profile,
|
|
374
|
+
// so the profile's entry spelling and the facade file can never skew.
|
|
375
|
+
const corewire_exe = corewireExe(b, dep);
|
|
376
|
+
const project = b.addRunArtifact(corewire_exe);
|
|
377
|
+
project.addArg("--sidecar");
|
|
378
|
+
project.addFileArg(contract);
|
|
379
|
+
project.addArg("--facade");
|
|
380
|
+
const facade = project.addOutputFileArg("core_facade.ts");
|
|
381
|
+
project.addArg("--profile");
|
|
382
|
+
const profile = project.addOutputFileArg("core_profile.json");
|
|
383
|
+
|
|
384
|
+
// The compile stage: author sources + staged SDK + static surface +
|
|
385
|
+
// generated entry/profile, one scratch tree.
|
|
386
|
+
const stage_run = b.addSystemCommand(&.{node});
|
|
387
|
+
stage_run.addFileArg(dep.path("packages/core/scripts/stage_external_core.mjs"));
|
|
388
|
+
stage_run.addArg("--src");
|
|
389
|
+
stage_run.addDirectoryArg(b.path(appPath(b, app_root, "src")));
|
|
390
|
+
stage_run.addArg("--sdk");
|
|
391
|
+
stage_run.addDirectoryArg(dep.path("packages/core/sdk"));
|
|
392
|
+
stage_run.addArg("--static");
|
|
393
|
+
stage_run.addFileArg(dep.path("packages/core/compile-surface/core.ts"));
|
|
394
|
+
stage_run.addArg("--facade");
|
|
395
|
+
stage_run.addFileArg(facade);
|
|
396
|
+
stage_run.addArg("--profile");
|
|
397
|
+
stage_run.addFileArg(profile);
|
|
398
|
+
stage_run.addArg("--out");
|
|
399
|
+
const stage_dir = stage_run.addOutputDirectoryArg("stage");
|
|
400
|
+
|
|
401
|
+
// The external compile itself: driver-verified against the SDK's
|
|
402
|
+
// exact pin, archive normalized, the co-emitted sidecar captured.
|
|
403
|
+
const symbol_name = externalCoreSymbolName(b, app_name);
|
|
404
|
+
const compile = b.addSystemCommand(&.{node});
|
|
405
|
+
compile.addFileArg(dep.path("packages/core/scripts/run_external_core_compiler.mjs"));
|
|
406
|
+
compile.addArg("--stage");
|
|
407
|
+
compile.addDirectoryArg(stage_dir);
|
|
408
|
+
compile.addArgs(&.{ "--name", symbol_name });
|
|
409
|
+
compile.addArg("--manifest");
|
|
410
|
+
compile.addFileArg(dep.path("packages/core/package.json"));
|
|
411
|
+
compile.addArg("--out-archive");
|
|
412
|
+
const archive = compile.addOutputFileArg(b.fmt("lib{s}.a", .{symbol_name}));
|
|
413
|
+
compile.addArg("--out-sidecar");
|
|
414
|
+
const compiled_sidecar = compile.addOutputFileArg("core.contract.json");
|
|
415
|
+
if (b.graph.environ_map.get("NATIVE_SDK_CORE_COMPILER")) |override| {
|
|
416
|
+
// The development override: point at any toolchain command; the
|
|
417
|
+
// driver still refuses a release other than the SDK's pin.
|
|
418
|
+
compile.addArgs(&.{ "--compiler", override });
|
|
419
|
+
} else {
|
|
420
|
+
const compiler_js = tsExternalCompilerJs(b, dep) orelse {
|
|
421
|
+
const sdk_root = tsSdkRoot(dep.builder.allocator, dep.builder.graph.io, dep);
|
|
422
|
+
std.debug.print(
|
|
423
|
+
\\
|
|
424
|
+
\\error: the external core compiler is not installed (TypeScript cores compile
|
|
425
|
+
\\through it). It ships as an exact-pinned dependency of the SDK's packages/core
|
|
426
|
+
\\— install it once with:
|
|
427
|
+
\\ cd {s}/packages/core && npm ci
|
|
428
|
+
\\(or point NATIVE_SDK_CORE_COMPILER at the pinned release's command; an
|
|
429
|
+
\\npm-installed @native-sdk/cli carries the compiler automatically — if it is
|
|
430
|
+
\\missing there, the install is broken: reinstall @native-sdk/cli).
|
|
431
|
+
\\
|
|
432
|
+
\\
|
|
433
|
+
, .{sdk_root});
|
|
434
|
+
std.process.exit(1);
|
|
435
|
+
};
|
|
436
|
+
compile.addArg("--compiler-js");
|
|
437
|
+
compile.addFileArg(.{ .cwd_relative = compiler_js });
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// The mirror, generated from the archive's OWN co-emitted contract.
|
|
441
|
+
const mirror = b.addRunArtifact(corewire_exe);
|
|
442
|
+
mirror.addArg("--sidecar");
|
|
443
|
+
mirror.addFileArg(compiled_sidecar);
|
|
444
|
+
mirror.addArg("--out");
|
|
445
|
+
const shim = mirror.addOutputFileArg("core_shim.zig");
|
|
446
|
+
|
|
447
|
+
// The staged module directory: the mirror is the app's core.zig,
|
|
448
|
+
// and it imports its staged shim runtime relatively.
|
|
309
449
|
const staged = b.addWriteFiles();
|
|
310
|
-
_ = staged.addCopyFile(
|
|
311
|
-
_ = staged.addCopyFile(dep.path("
|
|
450
|
+
_ = staged.addCopyFile(shim, "core.zig");
|
|
451
|
+
_ = staged.addCopyFile(dep.path("tools/corewire/shim_rt.zig"), "shim_rt.zig");
|
|
452
|
+
_ = staged.addCopyFile(dep.path("tools/corewire/core_abi.zig"), "core_abi.zig");
|
|
312
453
|
_ = staged.addCopyFile(b.path(appPath(b, app_root, "src/app.native")), "app.native");
|
|
313
454
|
const main_root = staged.addCopyFile(dep.path("src/app_runner/ts_core_main.zig"), "main.zig");
|
|
314
|
-
return .{ .main_root = main_root };
|
|
455
|
+
return .{ .main_root = main_root, .archive = archive };
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/// corewire (the contract-sidecar shim generator), compiled from the SDK
|
|
459
|
+
/// dependency's sources for the build host.
|
|
460
|
+
fn corewireExe(b: *std.Build, dep: *std.Build.Dependency) *std.Build.Step.Compile {
|
|
461
|
+
const mod = b.createModule(.{
|
|
462
|
+
.root_source_file = dep.path("tools/corewire/main.zig"),
|
|
463
|
+
.target = b.graph.host,
|
|
464
|
+
.optimize = .Debug,
|
|
465
|
+
});
|
|
466
|
+
return b.addExecutable(.{
|
|
467
|
+
.name = "corewire",
|
|
468
|
+
.root_module = mod,
|
|
469
|
+
.use_llvm = useLlvmWorkaround(b.graph.host),
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/// The archive's symbol-safe stem (`<app>_core` with every non-identifier
|
|
474
|
+
/// byte folded to '_'), the -o name the external compile builds under.
|
|
475
|
+
fn externalCoreSymbolName(b: *std.Build, app_name: []const u8) []const u8 {
|
|
476
|
+
const stem = b.fmt("{s}_core", .{app_name});
|
|
477
|
+
const sanitized = b.dupe(stem);
|
|
478
|
+
for (sanitized) |*char| {
|
|
479
|
+
const ok = (char.* >= 'a' and char.* <= 'z') or (char.* >= 'A' and char.* <= 'Z') or
|
|
480
|
+
(char.* >= '0' and char.* <= '9') or char.* == '_';
|
|
481
|
+
if (!ok) char.* = '_';
|
|
482
|
+
}
|
|
483
|
+
return sanitized;
|
|
315
484
|
}
|
|
316
485
|
|
|
317
486
|
/// Declare every .ts file in an SDK-relative directory as a file input of
|
|
@@ -502,18 +671,37 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
|
|
|
502
671
|
" src/main.zig,\nor keep src/main.zig and delete src/core.ts. (Other Zig files under" ++
|
|
503
672
|
" src/ are fine either way.)\n");
|
|
504
673
|
}
|
|
505
|
-
const
|
|
674
|
+
const app_config = appManifestBuildConfig(b, app_options.app_root);
|
|
675
|
+
// The core-compiler setting names the one lane there is; the flag
|
|
676
|
+
// overrides app.zon's `.core_compiler` and both exist so a stated
|
|
677
|
+
// choice stays stateable (and so the removed lane's spelling teaches
|
|
678
|
+
// instead of failing opaquely).
|
|
679
|
+
if (b.option([]const u8, "core-compiler", "How a TypeScript core compiles: external (the default and only lane)")) |flag| {
|
|
680
|
+
if (std.mem.eql(u8, flag, "transpiler")) @panic(core_compiler_teaching);
|
|
681
|
+
if (!std.mem.eql(u8, flag, "external")) @panic("\n-Dcore-compiler must be \"external\" (the default and only lane)\n");
|
|
682
|
+
if (core_tree != .ts) {
|
|
683
|
+
@panic("\n-Dcore-compiler applies to TypeScript cores (src/core.ts) only; this app has" ++
|
|
684
|
+
" a Zig core.\nDrop the flag or port the core to TypeScript.\n");
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
// Mobile targets are taught BEFORE lane selection: TypeScript cores
|
|
688
|
+
// are desktop-only until the external core toolchain grows mobile
|
|
689
|
+
// targets; Zig/markup cores stay fully supported on mobile.
|
|
690
|
+
if (core_tree == .ts and (target.result.os.tag == .ios or target.result.abi.isAndroid())) {
|
|
691
|
+
@panic("\nTypeScript app cores are desktop-only today: the external core compiler does not" ++
|
|
692
|
+
" target mobile yet.\nBuild for a desktop target, or port the core to a Zig" ++
|
|
693
|
+
" `mobileOptions` app — Zig and markup cores are fully supported on mobile.\n");
|
|
694
|
+
}
|
|
695
|
+
const ts_stage: ?TsCoreStage = if (core_tree == .ts)
|
|
696
|
+
tsCoreStage(b, dep, app_options.app_root, app_options.name)
|
|
697
|
+
else
|
|
698
|
+
null;
|
|
506
699
|
|
|
507
700
|
// Mobile targets get the embed static library as a `lib` step: the
|
|
508
701
|
// artifact the toolkit-owned iOS host (and any hand-written shim)
|
|
509
702
|
// links, so `native dev|package --target ios` works against every
|
|
510
703
|
// standard app build — generated graph or ejected — with nothing but
|
|
511
704
|
// `-Dtarget`. Desktop targets keep the step absent.
|
|
512
|
-
if (ts_stage != null and (target.result.os.tag == .ios or target.result.abi.isAndroid())) {
|
|
513
|
-
@panic("\nTypeScript app cores build desktop apps today; the mobile embed library for TS" ++
|
|
514
|
-
" cores lands with the mobile host tier.\nBuild for a desktop target, or port the core" ++
|
|
515
|
-
" to a Zig `mobileOptions` app for mobile.\n");
|
|
516
|
-
}
|
|
517
705
|
if (target.result.os.tag == .ios or target.result.abi.isAndroid()) {
|
|
518
706
|
addMobileLibWithTarget(b, dep, target, optimize, .{
|
|
519
707
|
.name = app_options.name,
|
|
@@ -542,7 +730,6 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
|
|
|
542
730
|
if (selected_platform == .windows and target.result.os.tag != .windows) {
|
|
543
731
|
@panic("-Dplatform=windows requires a Windows target");
|
|
544
732
|
}
|
|
545
|
-
const app_config = appManifestBuildConfig(b, app_options.app_root);
|
|
546
733
|
const web_engine = web_engine_override orelse app_config.web_engine;
|
|
547
734
|
const cef_dir = cef_dir_override orelse defaultCefDir(selected_platform, app_config.cef_dir);
|
|
548
735
|
const cef_auto_install = cef_auto_install_override orelse app_config.cef_auto_install;
|
|
@@ -789,8 +976,8 @@ fn appModule(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.Resolv
|
|
|
789
976
|
|
|
790
977
|
const app_mod = if (ts_stage) |stage|
|
|
791
978
|
// TypeScript core: the app module roots at the staged generated
|
|
792
|
-
// wiring (ts_core_main.zig beside the
|
|
793
|
-
//
|
|
979
|
+
// wiring (ts_core_main.zig beside the mirror core.zig, its shim
|
|
980
|
+
// runtime, and the app's markup).
|
|
794
981
|
b.createModule(.{
|
|
795
982
|
.root_source_file = stage.main_root,
|
|
796
983
|
.target = target,
|
|
@@ -804,6 +991,12 @@ fn appModule(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.Resolv
|
|
|
804
991
|
// The wiring derives scene/identity/security from app.zon itself.
|
|
805
992
|
app_mod.addImport("app_manifest_zon", manifest_mod);
|
|
806
993
|
}
|
|
994
|
+
if (ts_stage) |stage| {
|
|
995
|
+
// The compiled-core archive links behind the staged mirror; the
|
|
996
|
+
// toolchain's runtime needs libc.
|
|
997
|
+
app_mod.link_libc = true;
|
|
998
|
+
app_mod.addObjectFile(stage.archive);
|
|
999
|
+
}
|
|
807
1000
|
return app_mod;
|
|
808
1001
|
}
|
|
809
1002
|
|
|
@@ -1206,6 +1399,7 @@ const InferenceManifest = struct {
|
|
|
1206
1399
|
capabilities: []const []const u8 = &.{},
|
|
1207
1400
|
web_engine: []const u8 = "system",
|
|
1208
1401
|
webview_layer: []const u8 = "auto",
|
|
1402
|
+
core_compiler: []const u8 = "external",
|
|
1209
1403
|
cef: struct {
|
|
1210
1404
|
dir: []const u8 = "third_party/cef/macos",
|
|
1211
1405
|
auto_install: bool = false,
|
|
@@ -1246,6 +1440,12 @@ fn appManifestBuildConfig(b: *std.Build, app_root: []const u8) AppManifestBuildC
|
|
|
1246
1440
|
const source_z = b.allocator.dupeZ(u8, source) catch return fallback;
|
|
1247
1441
|
@setEvalBranchQuota(2000);
|
|
1248
1442
|
const raw = std.zon.parse.fromSliceAlloc(InferenceManifest, b.allocator, source_z, null, .{ .ignore_unknown_fields = true }) catch return fallback;
|
|
1443
|
+
// `.core_compiler` names the one lane there is; validated here so
|
|
1444
|
+
// the removed transpiled lane's spelling teaches at configure time.
|
|
1445
|
+
if (!std.mem.eql(u8, raw.core_compiler, "external")) {
|
|
1446
|
+
if (std.mem.eql(u8, raw.core_compiler, "transpiler")) @panic(core_compiler_teaching);
|
|
1447
|
+
@panic("\napp.zon .core_compiler must be \"external\" (the default and only lane)\n");
|
|
1448
|
+
}
|
|
1249
1449
|
return .{
|
|
1250
1450
|
.web_engine = web_layer_contract.parseWebEngine(raw.web_engine) orelse .system,
|
|
1251
1451
|
.cef_dir = raw.cef.dir,
|
package/build/ts_run.mjs
CHANGED
|
@@ -61,15 +61,13 @@ if (typeof module.registerHooks !== 'function') {
|
|
|
61
61
|
load(url, context, nextLoad) {
|
|
62
62
|
if (url.startsWith('file:') && url.endsWith('.ts')) {
|
|
63
63
|
const filePath = fileURLToPath(url);
|
|
64
|
-
// The
|
|
64
|
+
// The frontend's own pinned compiler, resolved from the target
|
|
65
65
|
// module's location (packages/core/node_modules after the taught
|
|
66
|
-
// `npm ci`, or the dependency npm installed beside the CLI)
|
|
67
|
-
//
|
|
68
|
-
//
|
|
69
|
-
//
|
|
70
|
-
//
|
|
71
|
-
// over our exact pin; resolving from the target finds our own
|
|
72
|
-
// nested/hoisted pin first (same reasoning as typed_ast.ts).
|
|
66
|
+
// `npm ci`, or the dependency npm installed beside the CLI):
|
|
67
|
+
// resolving from the target finds our own nested/hoisted exact
|
|
68
|
+
// pin first, so a consumer tree's conflicting hoisted typescript
|
|
69
|
+
// never wins nearest-wins over it (same reasoning as
|
|
70
|
+
// typed_ast.ts).
|
|
73
71
|
if (ts === null) {
|
|
74
72
|
try {
|
|
75
73
|
ts = createRequire(targetPath)('@typescript/old');
|