@native-sdk/cli 0.4.4 → 0.5.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 +371 -5
- package/build/ts_run.mjs +102 -0
- package/build.zig +255 -1
- package/build.zig.zon +1 -0
- package/package.json +19 -10
- package/packages/core/package-lock.json +44 -0
- package/packages/core/package.json +38 -0
- package/packages/core/rt/rt.zig +1579 -0
- package/packages/core/sdk/bytes_text_methods.d.ts +88 -0
- package/packages/core/sdk/core.ts +694 -0
- package/packages/core/sdk/events.ts +137 -0
- package/packages/core/sdk/text.ts +519 -0
- package/packages/core/src/checker.ts +1869 -0
- package/packages/core/src/cli.ts +68 -0
- package/packages/core/src/devhost.ts +291 -0
- package/packages/core/src/devhost_resolver.mjs +22 -0
- package/packages/core/src/diagnostics.ts +417 -0
- package/packages/core/src/emitter.ts +8815 -0
- package/packages/core/src/infer.ts +1515 -0
- package/packages/core/src/modules.ts +173 -0
- package/packages/core/src/ownership.ts +740 -0
- package/packages/core/src/text_polyfill.ts +337 -0
- package/packages/core/src/text_tables.ts +408 -0
- package/packages/core/src/transpile.ts +146 -0
- package/packages/core/src/typed_ast.ts +546 -0
- package/packages/core/src/types.ts +815 -0
- package/skill-data/native-ui/SKILL.md +14 -0
- package/skill-data/ts-core/SKILL.md +493 -0
- package/skill-data/zig/SKILL.md +10 -0
- package/src/app_runner/root.zig +24 -0
- package/src/app_runner/ts_core_main.zig +231 -0
- package/src/platform/windows/webview2_host.cpp +24 -0
- package/src/primitives/app_manifest/comptime_scene.zig +341 -0
- package/src/primitives/app_manifest/root.zig +5 -0
- package/src/primitives/canvas/commands.zig +14 -7
- package/src/primitives/canvas/layout_audit.zig +5 -5
- package/src/primitives/canvas/lazy_tls.zig +73 -0
- package/src/primitives/canvas/render_generic_resources.zig +22 -15
- package/src/primitives/canvas/root.zig +11 -0
- package/src/primitives/canvas/tests.zig +1 -0
- package/src/primitives/canvas/text_atlas.zig +40 -32
- package/src/primitives/canvas/text_layout_cache.zig +29 -22
- package/src/primitives/canvas/text_measure_cache.zig +56 -41
- package/src/primitives/canvas/text_spans.zig +39 -26
- package/src/primitives/canvas/tokens.zig +69 -0
- package/src/primitives/canvas/ui.zig +125 -0
- package/src/primitives/canvas/ui_markup.zig +22 -3
- package/src/primitives/canvas/ui_markup_compiled.zig +97 -7
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +275 -0
- package/src/primitives/canvas/ui_markup_contract.zig +68 -14
- package/src/primitives/canvas/ui_markup_contract_tests.zig +257 -2
- package/src/primitives/canvas/ui_markup_reflect.zig +214 -0
- package/src/primitives/canvas/ui_markup_view.zig +105 -1
- package/src/primitives/canvas/ui_markup_view_tests.zig +336 -0
- package/src/primitives/canvas/ui_schema.zig +8 -0
- package/src/primitives/canvas/ui_schema_tests.zig +5 -4
- package/src/primitives/canvas/widget_builtin_tests.zig +309 -5
- package/src/primitives/canvas/widget_invalidation.zig +14 -7
- package/src/primitives/canvas/widget_layout.zig +138 -2
- package/src/primitives/canvas/widget_metrics.zig +16 -8
- package/src/primitives/canvas/widget_render.zig +25 -15
- package/src/primitives/canvas/widget_render_controls.zig +15 -9
- package/src/primitives/canvas/widget_runtime_tests.zig +44 -0
- package/src/root.zig +7 -0
- package/src/runtime/canvas_frame.zig +57 -36
- package/src/runtime/canvas_images.zig +9 -3
- package/src/runtime/canvas_widget_control_tests.zig +5 -6
- package/src/runtime/canvas_widget_runtime.zig +7 -4
- package/src/runtime/core.zig +16 -0
- package/src/runtime/effects.zig +1525 -133
- package/src/runtime/effects_fetch_tests.zig +42 -0
- package/src/runtime/effects_file_tests.zig +220 -0
- package/src/runtime/effects_host_tests.zig +594 -0
- package/src/runtime/effects_tests.zig +287 -0
- package/src/runtime/root.zig +18 -0
- package/src/runtime/session_replay.zig +7 -1
- package/src/runtime/tests.zig +2 -0
- package/src/runtime/ts_core_host.zig +1505 -0
- package/src/runtime/ts_core_host_tests.zig +1408 -0
- package/src/runtime/ts_ui_app.zig +469 -0
- package/src/runtime/ui_app.zig +189 -38
- package/src/runtime/ui_app_tests.zig +221 -0
- package/src/runtime/ui_app_window_tests.zig +182 -0
- package/src/runtime/view_canvas.zig +24 -17
- package/src/runtime/view_widget_tree.zig +2 -2
- package/src/tooling/codesign.zig +212 -105
- package/src/tooling/doctor.zig +78 -0
- package/src/tooling/manifest.zig +47 -0
- package/src/tooling/package.zig +435 -20
- package/src/tooling/raw_manifest.zig +15 -0
- package/src/tooling/root.zig +1 -0
- package/src/tooling/templates.zig +777 -34
- package/src/tooling/ts_core.zig +1099 -0
- package/src/tooling/verbs.zig +105 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const std = @import("std");
|
|
2
2
|
const junction = @import("junction.zig");
|
|
3
|
+
const ts_core = @import("ts_core.zig");
|
|
3
4
|
|
|
4
5
|
/// The SDK's default app icon, rendered from vector source by
|
|
5
6
|
/// `zig build generate-icon` (tools/generate_app_icon.zig). Embedded so
|
|
@@ -64,11 +65,32 @@ pub const Shape = enum {
|
|
|
64
65
|
full,
|
|
65
66
|
};
|
|
66
67
|
|
|
68
|
+
/// Which core the native-frontend scaffold writes. No language flag and no
|
|
69
|
+
/// persistent config anywhere: the choice leaves NOTHING behind but the
|
|
70
|
+
/// tree itself (src/core.ts vs src/main.zig) - the build graph detects the
|
|
71
|
+
/// core from the tree on every build.
|
|
72
|
+
pub const CoreTemplate = enum {
|
|
73
|
+
/// TypeScript core (src/core.ts) + markup view - the default.
|
|
74
|
+
ts,
|
|
75
|
+
/// Zig core (src/main.zig) + markup view - the same starter app,
|
|
76
|
+
/// authored in Zig.
|
|
77
|
+
zig,
|
|
78
|
+
|
|
79
|
+
pub fn parse(value: []const u8) ?CoreTemplate {
|
|
80
|
+
if (std.mem.eql(u8, value, "ts-core")) return .ts;
|
|
81
|
+
if (std.mem.eql(u8, value, "zig-core")) return .zig;
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
67
86
|
pub const InitOptions = struct {
|
|
68
87
|
app_name: []const u8,
|
|
69
88
|
framework_path: []const u8 = ".",
|
|
70
89
|
frontend: Frontend = .vite,
|
|
71
90
|
shape: Shape = .slim,
|
|
91
|
+
/// Applies to the native frontend only (web frontends have no core
|
|
92
|
+
/// tier to scaffold).
|
|
93
|
+
core: CoreTemplate = .ts,
|
|
72
94
|
};
|
|
73
95
|
|
|
74
96
|
pub fn writeDefaultApp(allocator: std.mem.Allocator, io: std.Io, destination: []const u8, options: InitOptions) !void {
|
|
@@ -86,6 +108,15 @@ pub fn writeDefaultApp(allocator: std.mem.Allocator, io: std.Io, destination: []
|
|
|
86
108
|
try app_dir.createDirPath(io, "assets");
|
|
87
109
|
|
|
88
110
|
if (options.frontend == .native) {
|
|
111
|
+
if (options.core == .ts) {
|
|
112
|
+
if (options.shape == .slim) {
|
|
113
|
+
return writeTsAppSlim(allocator, io, app_dir, names, destination, options.framework_path);
|
|
114
|
+
}
|
|
115
|
+
// build.zig.zon path dependencies must be relative to the app root.
|
|
116
|
+
const dependency_path = try nativeDependencyPath(allocator, io, destination, framework_path);
|
|
117
|
+
defer allocator.free(dependency_path);
|
|
118
|
+
return writeTsApp(allocator, io, app_dir, names, dependency_path, destination, options.framework_path);
|
|
119
|
+
}
|
|
89
120
|
if (options.shape == .slim) {
|
|
90
121
|
return writeNativeAppSlim(allocator, io, app_dir, names);
|
|
91
122
|
}
|
|
@@ -151,6 +182,330 @@ fn slimGitignore() []const u8 {
|
|
|
151
182
|
;
|
|
152
183
|
}
|
|
153
184
|
|
|
185
|
+
/// The TypeScript-core zero-config scaffold - the `native init` default:
|
|
186
|
+
/// core.ts (logic), app.native (view), app.zon (manifest). ZERO Zig in the
|
|
187
|
+
/// tree; the build graph detects src/core.ts, transpiles it, and stages the
|
|
188
|
+
/// generated wiring outside the app on every build.
|
|
189
|
+
///
|
|
190
|
+
/// The tree also carries the EDITOR surface: package.json + tsconfig.json,
|
|
191
|
+
/// so stock editor TypeScript resolves `@native-sdk/core` with full
|
|
192
|
+
/// IntelliSense, plus a materialized node_modules copy of the SDK package
|
|
193
|
+
/// (ts_core.zig owns that contract). None of it is build truth — the tree
|
|
194
|
+
/// detection above keys on src/core.ts alone, and every `native` verb
|
|
195
|
+
/// works with node_modules deleted.
|
|
196
|
+
fn writeTsAppSlim(allocator: std.mem.Allocator, io: std.Io, app_dir: std.Io.Dir, names: TemplateNames, destination: []const u8, sdk_source: []const u8) !void {
|
|
197
|
+
const app_zon = try nativeAppZon(allocator, names);
|
|
198
|
+
defer allocator.free(app_zon);
|
|
199
|
+
const readme_md = try tsSlimReadme(allocator, names);
|
|
200
|
+
defer allocator.free(readme_md);
|
|
201
|
+
|
|
202
|
+
try writeFile(app_dir, io, "src/core.ts", tsCoreStarter());
|
|
203
|
+
try writeFile(app_dir, io, "src/app.native", tsAppMarkup());
|
|
204
|
+
try writeFile(app_dir, io, "app.zon", app_zon);
|
|
205
|
+
try writeFile(app_dir, io, "assets/icon.png", default_icon_png);
|
|
206
|
+
try writeFile(app_dir, io, ".gitignore", tsGitignore());
|
|
207
|
+
try writeFile(app_dir, io, "README.md", readme_md);
|
|
208
|
+
try writeTsEditorSurface(allocator, io, app_dir, names, destination, sdk_source);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/// The `--full` twin: the same TS tree plus an owned build.zig/zon pair
|
|
212
|
+
/// (the plain addApp call - the build graph's tree detection does the
|
|
213
|
+
/// rest) and a CI workflow, for users who want to own the build from day
|
|
214
|
+
/// one — the same full-shape contract as the Zig template.
|
|
215
|
+
fn writeTsApp(allocator: std.mem.Allocator, io: std.Io, app_dir: std.Io.Dir, names: TemplateNames, framework_path: []const u8, destination: []const u8, sdk_source: []const u8) !void {
|
|
216
|
+
const build_zig = try nativeBuildZig(allocator, names);
|
|
217
|
+
defer allocator.free(build_zig);
|
|
218
|
+
const build_zon = try nativeBuildZon(allocator, names, framework_path);
|
|
219
|
+
defer allocator.free(build_zon);
|
|
220
|
+
const app_zon = try nativeAppZon(allocator, names);
|
|
221
|
+
defer allocator.free(app_zon);
|
|
222
|
+
const readme_md = try tsSlimReadme(allocator, names);
|
|
223
|
+
defer allocator.free(readme_md);
|
|
224
|
+
const ci_yaml = try nativeCiYaml(allocator, names, framework_path, .ts);
|
|
225
|
+
defer allocator.free(ci_yaml);
|
|
226
|
+
|
|
227
|
+
try app_dir.createDirPath(io, ".github/workflows");
|
|
228
|
+
try writeFile(app_dir, io, ".github/workflows/ci.yml", ci_yaml);
|
|
229
|
+
try writeFile(app_dir, io, "build.zig", build_zig);
|
|
230
|
+
try writeFile(app_dir, io, "build.zig.zon", build_zon);
|
|
231
|
+
try writeFile(app_dir, io, "src/core.ts", tsCoreStarter());
|
|
232
|
+
try writeFile(app_dir, io, "src/app.native", tsAppMarkup());
|
|
233
|
+
try writeFile(app_dir, io, "app.zon", app_zon);
|
|
234
|
+
try writeFile(app_dir, io, "assets/icon.png", default_icon_png);
|
|
235
|
+
try writeFile(app_dir, io, ".gitignore", tsGitignore());
|
|
236
|
+
try writeFile(app_dir, io, "README.md", readme_md);
|
|
237
|
+
try writeTsEditorSurface(allocator, io, app_dir, names, destination, sdk_source);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/// The editor-and-versioning surface of a TS scaffold: package.json (the
|
|
241
|
+
/// app's name and its `@native-sdk/core` dependency at the SDK's bundled
|
|
242
|
+
/// version), tsconfig.json (the checker's own compiler options, so editor
|
|
243
|
+
/// errors match `native check` reality), and a materialized
|
|
244
|
+
/// node_modules/@native-sdk/core so resolution works BEFORE the package is
|
|
245
|
+
/// published to npm. `sdk_source` is the framework checkout as reachable
|
|
246
|
+
/// from the CLI's cwd (unlike the destination-relative build.zig.zon path).
|
|
247
|
+
fn writeTsEditorSurface(allocator: std.mem.Allocator, io: std.Io, app_dir: std.Io.Dir, names: TemplateNames, destination: []const u8, sdk_source: []const u8) !void {
|
|
248
|
+
const sdk_version = ts_core.bundledSdkVersion(allocator, io, sdk_source) catch |err| {
|
|
249
|
+
std.debug.print("the Native SDK at {s} is missing packages/core/package.json - is the checkout (or npm install) complete?\n", .{sdk_source});
|
|
250
|
+
return err;
|
|
251
|
+
};
|
|
252
|
+
defer allocator.free(sdk_version);
|
|
253
|
+
const package_json = try tsPackageJson(allocator, names, sdk_version);
|
|
254
|
+
defer allocator.free(package_json);
|
|
255
|
+
try writeFile(app_dir, io, "package.json", package_json);
|
|
256
|
+
try writeFile(app_dir, io, "tsconfig.json", tsTsconfig());
|
|
257
|
+
_ = try ts_core.ensureEditorPackage(allocator, io, sdk_source, destination);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/// The app's package.json: name + the pinned `@native-sdk/core` dependency,
|
|
261
|
+
/// nothing else. It exists for editors and versioning only — the `native`
|
|
262
|
+
/// verbs never read it (tree detection keys on src/core.ts; the build
|
|
263
|
+
/// transpiles against the SDK checkout) — and the pin is exact so the
|
|
264
|
+
/// post-publish `npm install` resolves the same content the CLI
|
|
265
|
+
/// materialized.
|
|
266
|
+
fn tsPackageJson(allocator: std.mem.Allocator, names: TemplateNames, sdk_version: []const u8) ![]const u8 {
|
|
267
|
+
var out: std.ArrayList(u8) = .empty;
|
|
268
|
+
errdefer out.deinit(allocator);
|
|
269
|
+
try out.appendSlice(allocator, "{\n \"name\": ");
|
|
270
|
+
try appendJsonString(&out, allocator, names.package_name);
|
|
271
|
+
try out.appendSlice(allocator,
|
|
272
|
+
\\,
|
|
273
|
+
\\ "private": true,
|
|
274
|
+
\\ "description": "Editor and versioning surface only: stock TypeScript tooling resolves @native-sdk/core from here. The native CLI never reads it and builds with node_modules absent.",
|
|
275
|
+
\\ "dependencies": {
|
|
276
|
+
\\ "@native-sdk/core":
|
|
277
|
+
);
|
|
278
|
+
try out.appendSlice(allocator, " ");
|
|
279
|
+
try appendJsonString(&out, allocator, sdk_version);
|
|
280
|
+
try out.appendSlice(allocator,
|
|
281
|
+
\\
|
|
282
|
+
\\ }
|
|
283
|
+
\\}
|
|
284
|
+
\\
|
|
285
|
+
);
|
|
286
|
+
return out.toOwnedSlice(allocator);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/// The editor tsconfig: the same compiler options the @native-sdk/core
|
|
290
|
+
/// checker builds its program with (typed_ast.ts subsetCompilerOptions), so
|
|
291
|
+
/// what the editor flags is what `native check` flags — minus the SDK
|
|
292
|
+
/// `paths` injection: editors resolve `@native-sdk/core` through
|
|
293
|
+
/// node_modules like any package.
|
|
294
|
+
fn tsTsconfig() []const u8 {
|
|
295
|
+
return
|
|
296
|
+
\\{
|
|
297
|
+
\\ // Mirrors the compiler options the @native-sdk/core checker enforces,
|
|
298
|
+
\\ // so editor diagnostics match `native check` reality. @native-sdk/core
|
|
299
|
+
\\ // resolves from node_modules: the native CLI materializes the SDK's
|
|
300
|
+
\\ // copy there (and keeps it fresh) until the package is on npm.
|
|
301
|
+
\\ "compilerOptions": {
|
|
302
|
+
\\ "strict": true,
|
|
303
|
+
\\ "target": "esnext",
|
|
304
|
+
\\ "module": "esnext",
|
|
305
|
+
\\ "moduleResolution": "bundler",
|
|
306
|
+
\\ "lib": ["esnext"],
|
|
307
|
+
\\ "types": [],
|
|
308
|
+
\\ "allowImportingTsExtensions": true,
|
|
309
|
+
\\ "verbatimModuleSyntax": true,
|
|
310
|
+
\\ "exactOptionalPropertyTypes": true,
|
|
311
|
+
\\ "noFallthroughCasesInSwitch": true,
|
|
312
|
+
\\ "isolatedModules": true,
|
|
313
|
+
\\ "noEmit": true,
|
|
314
|
+
\\ "skipLibCheck": true
|
|
315
|
+
\\ },
|
|
316
|
+
\\ "include": ["src/**/*.ts"]
|
|
317
|
+
\\}
|
|
318
|
+
\\
|
|
319
|
+
;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/// TS scaffolds ignore node_modules on top of the slim set: the
|
|
323
|
+
/// @native-sdk/core copy in there is CLI-managed (npm-managed after
|
|
324
|
+
/// publish), never source. `.native/` stays: `native check` stages the
|
|
325
|
+
/// emitted core there for --full trees too.
|
|
326
|
+
fn tsGitignore() []const u8 {
|
|
327
|
+
return
|
|
328
|
+
\\.native/
|
|
329
|
+
\\zig-out/
|
|
330
|
+
\\.zig-cache/
|
|
331
|
+
\\node_modules/
|
|
332
|
+
\\
|
|
333
|
+
;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/// The starter core: a counter with a repeating tick (Sub.timer) and a
|
|
337
|
+
/// timestamp request (Cmd.now) - one of each effect surface, small enough
|
|
338
|
+
/// to read whole.
|
|
339
|
+
fn tsCoreStarter() []const u8 {
|
|
340
|
+
return
|
|
341
|
+
\\// The app core: Model, Msg, update, and the pure helpers they call -
|
|
342
|
+
\\// plain TypeScript in the app-core subset, compiled to native Zig at
|
|
343
|
+
\\// build time (no JS runtime ships in the binary). The view lives in
|
|
344
|
+
\\// app.native and binds this model by its own field names exactly as
|
|
345
|
+
\\// written here (`tickCount` binds as `{tickCount}`).
|
|
346
|
+
\\//
|
|
347
|
+
\\// The loop: edit here -> `native dev --core` for instant logic checks
|
|
348
|
+
\\// under node -> `native dev` to run the real app. `native check`
|
|
349
|
+
\\// verifies this file and the markup together.
|
|
350
|
+
\\
|
|
351
|
+
\\import { Cmd, Sub } from "@native-sdk/core";
|
|
352
|
+
\\
|
|
353
|
+
\\export interface Model {
|
|
354
|
+
\\ readonly count: number;
|
|
355
|
+
\\ readonly ticking: boolean;
|
|
356
|
+
\\ readonly tickCount: number;
|
|
357
|
+
\\ readonly stampedMs: number;
|
|
358
|
+
\\}
|
|
359
|
+
\\
|
|
360
|
+
\\export type Msg =
|
|
361
|
+
\\ | { readonly kind: "increment" }
|
|
362
|
+
\\ | { readonly kind: "decrement" }
|
|
363
|
+
\\ | { readonly kind: "reset" }
|
|
364
|
+
\\ | { readonly kind: "toggle_ticking" }
|
|
365
|
+
\\ | { readonly kind: "stamp" }
|
|
366
|
+
\\ | { readonly kind: "stamped"; readonly at: number }
|
|
367
|
+
\\ | { readonly kind: "tick"; readonly at: number };
|
|
368
|
+
\\
|
|
369
|
+
\\// `tick` and `stamped` are dispatched by the host (timer fires and the
|
|
370
|
+
\\// Cmd.now result), never from markup - this list keeps `native check`'s
|
|
371
|
+
\\// unbound-state lint honest about that.
|
|
372
|
+
\\export const viewUnbound = ["tick", "stamped"] as const;
|
|
373
|
+
\\
|
|
374
|
+
\\export function initialModel(): Model {
|
|
375
|
+
\\ return { count: 0, ticking: false, tickCount: 0, stampedMs: -1 };
|
|
376
|
+
\\}
|
|
377
|
+
\\
|
|
378
|
+
\\// Exported single-model helpers become bindings too: `{total}` in
|
|
379
|
+
\\// app.native reads this.
|
|
380
|
+
\\export function total(model: Model): number {
|
|
381
|
+
\\ return model.count + model.tickCount;
|
|
382
|
+
\\}
|
|
383
|
+
\\
|
|
384
|
+
\\export function update(model: Model, msg: Msg): Model | [Model, Cmd<Msg>] {
|
|
385
|
+
\\ switch (msg.kind) {
|
|
386
|
+
\\ case "increment":
|
|
387
|
+
\\ return { ...model, count: model.count + 1 };
|
|
388
|
+
\\ case "decrement":
|
|
389
|
+
\\ return { ...model, count: model.count - 1 };
|
|
390
|
+
\\ case "reset":
|
|
391
|
+
\\ return { ...model, count: 0, tickCount: 0 };
|
|
392
|
+
\\ case "toggle_ticking":
|
|
393
|
+
\\ return { ...model, ticking: !model.ticking };
|
|
394
|
+
\\ case "stamp":
|
|
395
|
+
\\ // Effects are data: the host performs this after commit and
|
|
396
|
+
\\ // dispatches `stamped` with the time.
|
|
397
|
+
\\ return [model, Cmd.now("stamped")];
|
|
398
|
+
\\ case "stamped":
|
|
399
|
+
\\ return { ...model, stampedMs: msg.at };
|
|
400
|
+
\\ case "tick":
|
|
401
|
+
\\ return { ...model, tickCount: model.tickCount + 1 };
|
|
402
|
+
\\ }
|
|
403
|
+
\\}
|
|
404
|
+
\\
|
|
405
|
+
\\// Recurring effects are declared from the model: while `ticking` holds,
|
|
406
|
+
\\// the host fires `tick` every second; flip it off and the timer stops.
|
|
407
|
+
\\export function subscriptions(model: Model): Sub<Msg> {
|
|
408
|
+
\\ if (!model.ticking) return Sub.none;
|
|
409
|
+
\\ return Sub.timer("tick", 1000, "tick");
|
|
410
|
+
\\}
|
|
411
|
+
\\
|
|
412
|
+
;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
fn tsAppMarkup() []const u8 {
|
|
416
|
+
return
|
|
417
|
+
\\<!-- The whole view: markup over the core's emitted model. Embedded at
|
|
418
|
+
\\ build time and hot-reloaded while `native dev` runs. Fields bind
|
|
419
|
+
\\ by the names core.ts wrote ({tickCount}); exported single-model
|
|
420
|
+
\\ helpers bind too ({total}). Validate with: native check -->
|
|
421
|
+
\\<column gap="12" padding="16">
|
|
422
|
+
\\ <row gap="8" cross="center">
|
|
423
|
+
\\ <text grow="1">Counter</text>
|
|
424
|
+
\\ <button size="sm" variant="ghost" on-press="reset">Reset</button>
|
|
425
|
+
\\ </row>
|
|
426
|
+
\\ <row gap="8" main="center" cross="center" grow="1">
|
|
427
|
+
\\ <button variant="secondary" on-press="decrement">-</button>
|
|
428
|
+
\\ <text>{count}</text>
|
|
429
|
+
\\ <button variant="primary" on-press="increment">+</button>
|
|
430
|
+
\\ </row>
|
|
431
|
+
\\ <row gap="8" cross="center">
|
|
432
|
+
\\ <switch checked="{ticking}" on-toggle="toggle_ticking">Tick every second</switch>
|
|
433
|
+
\\ <text grow="1">ticks {tickCount}</text>
|
|
434
|
+
\\ <button size="sm" on-press="stamp">Stamp</button>
|
|
435
|
+
\\ </row>
|
|
436
|
+
\\ <!-- The empty state is markup, not model surgery: stampedMs starts
|
|
437
|
+
\\ at -1 (never stamped), and the view says what Stamp will do
|
|
438
|
+
\\ instead of printing "-1ms". -->
|
|
439
|
+
\\ <if test="{stampedMs < 0}">
|
|
440
|
+
\\ <status-bar>total: {total} | press Stamp for a timestamp</status-bar>
|
|
441
|
+
\\ </if>
|
|
442
|
+
\\ <else>
|
|
443
|
+
\\ <status-bar>total: {total} | stamped: {stampedMs}ms</status-bar>
|
|
444
|
+
\\ </else>
|
|
445
|
+
\\</column>
|
|
446
|
+
\\
|
|
447
|
+
;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
fn tsSlimReadme(allocator: std.mem.Allocator, names: TemplateNames) ![]const u8 {
|
|
451
|
+
var out: std.ArrayList(u8) = .empty;
|
|
452
|
+
errdefer out.deinit(allocator);
|
|
453
|
+
try out.appendSlice(allocator, "# ");
|
|
454
|
+
try out.appendSlice(allocator, names.display_name);
|
|
455
|
+
try out.appendSlice(allocator,
|
|
456
|
+
\\
|
|
457
|
+
\\
|
|
458
|
+
\\A native app authored in TypeScript and markup: the logic lives in
|
|
459
|
+
\\`src/core.ts` (Model, Msg, update - the app-core subset, compiled to
|
|
460
|
+
\\native code at build time; no JS runtime ships in the binary) and the
|
|
461
|
+
\\view in `src/app.native`. There is no Zig in this tree and nothing to
|
|
462
|
+
\\configure: the build detects `src/core.ts` and wires everything.
|
|
463
|
+
\\
|
|
464
|
+
\\## The loop
|
|
465
|
+
\\
|
|
466
|
+
\\```sh
|
|
467
|
+
\\native dev --core # fastest: run the core's logic under node -
|
|
468
|
+
\\ # dispatch messages as JSON lines, watch the model
|
|
469
|
+
\\ # and effect transcript (not a renderer)
|
|
470
|
+
\\native dev # build and run the real app (markup hot reload)
|
|
471
|
+
\\native check # verify core.ts (subset checker) + markup + app.zon
|
|
472
|
+
\\native build # ReleaseFast binary in zig-out/bin/
|
|
473
|
+
\\native test # the app's test suite
|
|
474
|
+
\\```
|
|
475
|
+
\\
|
|
476
|
+
\\Edit `src/core.ts` for behavior, `src/app.native` for the view, and
|
|
477
|
+
\\`app.zon` for windows/identity/permissions. Markup binds the model's
|
|
478
|
+
\\field names exactly as core.ts wrote them (`tickCount` -> `{tickCount}`),
|
|
479
|
+
\\and exported single-model helpers bind as derived values (`{total}`).
|
|
480
|
+
\\
|
|
481
|
+
\\## Try the core loop
|
|
482
|
+
\\
|
|
483
|
+
\\```sh
|
|
484
|
+
\\printf '%s\n' '{"kind":"increment"}' '{"kind":"toggle_ticking"}' '{"advance":3000}' | native dev --core
|
|
485
|
+
\\```
|
|
486
|
+
\\
|
|
487
|
+
\\## Editor support
|
|
488
|
+
\\
|
|
489
|
+
\\Stock editor TypeScript just works: `package.json` and `tsconfig.json`
|
|
490
|
+
\\are the editor-and-versioning surface (the tsconfig mirrors the checker's
|
|
491
|
+
\\own options, so editor errors match `native check`), and
|
|
492
|
+
\\`node_modules/@native-sdk/core` is a CLI-managed copy of the SDK package
|
|
493
|
+
\\so `@native-sdk/core` resolves with full IntelliSense. Builds never read
|
|
494
|
+
\\any of it — delete node_modules and every `native` verb still works; the
|
|
495
|
+
\\next `native check`/`dev`/`build` puts it back. Running `npm install`
|
|
496
|
+
\\is optional for the same reason: the CLI materializes and refreshes the
|
|
497
|
+
\\package itself, and an install simply lands the identical content once
|
|
498
|
+
\\`@native-sdk/core` is on npm.
|
|
499
|
+
\\
|
|
500
|
+
\\## Requirements
|
|
501
|
+
\\
|
|
502
|
+
\\Node.js 22.15+ (on the 23 line: 23.5+) on PATH (the TypeScript-to-native
|
|
503
|
+
\\transpiler runs at build time; your shipped binary carries none of it).
|
|
504
|
+
\\
|
|
505
|
+
);
|
|
506
|
+
return out.toOwnedSlice(allocator);
|
|
507
|
+
}
|
|
508
|
+
|
|
154
509
|
fn slimNativeReadme(allocator: std.mem.Allocator, names: TemplateNames) ![]const u8 {
|
|
155
510
|
var out: std.ArrayList(u8) = .empty;
|
|
156
511
|
errdefer out.deinit(allocator);
|
|
@@ -205,7 +560,7 @@ fn writeNativeApp(allocator: std.mem.Allocator, io: std.Io, app_dir: std.Io.Dir,
|
|
|
205
560
|
defer allocator.free(app_zon);
|
|
206
561
|
const readme_md = try nativeReadme(allocator, names, framework_path);
|
|
207
562
|
defer allocator.free(readme_md);
|
|
208
|
-
const ci_yaml = try nativeCiYaml(allocator, names, framework_path);
|
|
563
|
+
const ci_yaml = try nativeCiYaml(allocator, names, framework_path, .zig);
|
|
209
564
|
defer allocator.free(ci_yaml);
|
|
210
565
|
|
|
211
566
|
try writeFile(app_dir, io, "build.zig", build_zig);
|
|
@@ -277,9 +632,11 @@ fn nativeMainZig(allocator: std.mem.Allocator, names: TemplateNames) ![]const u8
|
|
|
277
632
|
var out: std.ArrayList(u8) = .empty;
|
|
278
633
|
errdefer out.deinit(allocator);
|
|
279
634
|
try out.appendSlice(allocator,
|
|
280
|
-
\\//!
|
|
281
|
-
\\//!
|
|
282
|
-
\\//!
|
|
635
|
+
\\//! The app core in Zig: `Model`, `Msg`, and `update` - the same
|
|
636
|
+
\\//! counter-with-effects starter the TypeScript template builds. The view
|
|
637
|
+
\\//! lives in `app.native` (embedded into the binary, and watched for hot
|
|
638
|
+
\\//! reload in dev); recurring work and clock reads ride the effects
|
|
639
|
+
\\//! channel, so `update` stays a plain function of model + message.
|
|
283
640
|
\\
|
|
284
641
|
\\const std = @import("std");
|
|
285
642
|
\\const runner = @import("runner");
|
|
@@ -319,17 +676,66 @@ fn nativeMainZig(allocator: std.mem.Allocator, names: TemplateNames) ![]const u8
|
|
|
319
676
|
\\ increment,
|
|
320
677
|
\\ decrement,
|
|
321
678
|
\\ reset,
|
|
679
|
+
\\ toggle_ticking,
|
|
680
|
+
\\ stamp,
|
|
681
|
+
\\ tick: native_sdk.EffectTimer,
|
|
682
|
+
\\
|
|
683
|
+
\\ // `tick` is dispatched by the host (the repeating timer fires),
|
|
684
|
+
\\ // never from markup - this keeps the unbound-state lint honest
|
|
685
|
+
\\ // about that.
|
|
686
|
+
\\ pub const view_unbound = .{"tick"};
|
|
322
687
|
\\};
|
|
323
688
|
\\
|
|
324
689
|
\\pub const Model = struct {
|
|
325
690
|
\\ count: i64 = 0,
|
|
691
|
+
\\ ticking: bool = false,
|
|
692
|
+
\\ tick_count: i64 = 0,
|
|
693
|
+
\\ stamped_ms: i64 = -1,
|
|
694
|
+
\\
|
|
695
|
+
\\ // Public single-model helpers become bindings too: `{total}` in
|
|
696
|
+
\\ // app.native reads this.
|
|
697
|
+
\\ pub fn total(model: *const Model) i64 {
|
|
698
|
+
\\ return model.count + model.tick_count;
|
|
699
|
+
\\ }
|
|
326
700
|
\\};
|
|
327
701
|
\\
|
|
328
|
-
\\pub
|
|
702
|
+
\\pub const Effects = native_sdk.Effects(Msg);
|
|
703
|
+
\\
|
|
704
|
+
\\/// The repeating tick's effects-channel key: starting an active key
|
|
705
|
+
\\/// replaces the timer in place, so toggling never double-registers.
|
|
706
|
+
\\pub const tick_timer_key: u64 = 1;
|
|
707
|
+
\\
|
|
708
|
+
\\pub fn update(model: *Model, msg: Msg, fx: *Effects) void {
|
|
329
709
|
\\ switch (msg) {
|
|
330
710
|
\\ .increment => model.count += 1,
|
|
331
711
|
\\ .decrement => model.count -= 1,
|
|
332
|
-
\\ .reset =>
|
|
712
|
+
\\ .reset => {
|
|
713
|
+
\\ model.count = 0;
|
|
714
|
+
\\ model.tick_count = 0;
|
|
715
|
+
\\ },
|
|
716
|
+
\\ .toggle_ticking => {
|
|
717
|
+
\\ model.ticking = !model.ticking;
|
|
718
|
+
\\ // Recurring effects are timers on the effects channel: while
|
|
719
|
+
\\ // `ticking` holds, the host fires `tick` every second; flip
|
|
720
|
+
\\ // it off and the timer stops.
|
|
721
|
+
\\ if (model.ticking) {
|
|
722
|
+
\\ fx.startTimer(.{
|
|
723
|
+
\\ .key = tick_timer_key,
|
|
724
|
+
\\ .interval_ms = 1000,
|
|
725
|
+
\\ .mode = .repeating,
|
|
726
|
+
\\ .on_fire = Effects.timerMsg(.tick),
|
|
727
|
+
\\ });
|
|
728
|
+
\\ } else {
|
|
729
|
+
\\ fx.cancelTimer(tick_timer_key);
|
|
730
|
+
\\ }
|
|
731
|
+
\\ },
|
|
732
|
+
\\ // The journaled clock read - deterministic under session replay,
|
|
733
|
+
\\ // the Zig equivalent of the TypeScript starter's `Cmd.now`.
|
|
734
|
+
\\ .stamp => model.stamped_ms = fx.wallMs(),
|
|
735
|
+
\\ .tick => |timer| {
|
|
736
|
+
\\ if (timer.outcome != .fired) return;
|
|
737
|
+
\\ model.tick_count += 1;
|
|
738
|
+
\\ },
|
|
333
739
|
\\ }
|
|
334
740
|
\\}
|
|
335
741
|
\\
|
|
@@ -360,7 +766,7 @@ fn nativeMainZig(allocator: std.mem.Allocator, names: TemplateNames) ![]const u8
|
|
|
360
766
|
\\,
|
|
361
767
|
\\ .scene = shell_scene,
|
|
362
768
|
\\ .canvas_label = canvas_label,
|
|
363
|
-
\\ .
|
|
769
|
+
\\ .update_fx = update,
|
|
364
770
|
\\ .markup = .{ .source = app_markup, .watch_path = "src/app.native", .io = init.io },
|
|
365
771
|
\\ });
|
|
366
772
|
\\ defer app_state.destroy();
|
|
@@ -406,9 +812,11 @@ fn nativeMainZig(allocator: std.mem.Allocator, names: TemplateNames) ![]const u8
|
|
|
406
812
|
|
|
407
813
|
fn nativeAppMarkup() []const u8 {
|
|
408
814
|
return
|
|
409
|
-
\\<!-- The whole view
|
|
410
|
-
\\ edit this file while the app runs
|
|
411
|
-
\\
|
|
815
|
+
\\<!-- The whole view: markup over the core's model. Embedded into the
|
|
816
|
+
\\ binary and hot-reloaded in dev: edit this file while the app runs
|
|
817
|
+
\\ and the window updates without losing the count. Fields bind by
|
|
818
|
+
\\ the names main.zig wrote ({tick_count}); public single-model
|
|
819
|
+
\\ helpers bind too ({total}). Validate with: native check -->
|
|
412
820
|
\\<column gap="12" padding="16">
|
|
413
821
|
\\ <row gap="8" cross="center">
|
|
414
822
|
\\ <text grow="1">Counter</text>
|
|
@@ -419,7 +827,12 @@ fn nativeAppMarkup() []const u8 {
|
|
|
419
827
|
\\ <text>{count}</text>
|
|
420
828
|
\\ <button variant="primary" on-press="increment">+</button>
|
|
421
829
|
\\ </row>
|
|
422
|
-
\\ <
|
|
830
|
+
\\ <row gap="8" cross="center">
|
|
831
|
+
\\ <switch checked="{ticking}" on-toggle="toggle_ticking">Tick every second</switch>
|
|
832
|
+
\\ <text grow="1">ticks {tick_count}</text>
|
|
833
|
+
\\ <button size="sm" on-press="stamp">Stamp</button>
|
|
834
|
+
\\ </row>
|
|
835
|
+
\\ <status-bar>total: {total} | stamped: {stamped_ms}ms</status-bar>
|
|
423
836
|
\\</column>
|
|
424
837
|
\\
|
|
425
838
|
;
|
|
@@ -440,6 +853,7 @@ fn nativeTestsZig(allocator: std.mem.Allocator, names: TemplateNames) ![]const u
|
|
|
440
853
|
\\const AppUi = main.AppUi;
|
|
441
854
|
\\const Model = main.Model;
|
|
442
855
|
\\const Msg = main.Msg;
|
|
856
|
+
\\const Effects = main.Effects;
|
|
443
857
|
\\
|
|
444
858
|
\\const AppMarkup = canvas.MarkupView(Model, Msg);
|
|
445
859
|
\\
|
|
@@ -481,37 +895,106 @@ fn nativeTestsZig(allocator: std.mem.Allocator, names: TemplateNames) ![]const u
|
|
|
481
895
|
\\ defer arena_state.deinit();
|
|
482
896
|
\\ const arena = arena_state.allocator();
|
|
483
897
|
\\
|
|
898
|
+
\\ // A real effects channel in fake-executor mode: requests are
|
|
899
|
+
\\ // recorded for assertions instead of touching the OS.
|
|
900
|
+
\\ var fx = Effects.init(testing.allocator);
|
|
901
|
+
\\ defer fx.deinit();
|
|
902
|
+
\\ fx.executor = .fake;
|
|
903
|
+
\\
|
|
484
904
|
\\ var model = main.initialModel();
|
|
485
905
|
\\
|
|
486
906
|
\\ var tree = try buildTree(arena, &model);
|
|
487
907
|
\\ _ = try expectByText(tree.root, .text, "0");
|
|
488
|
-
\\ _ = try expectByText(tree.root, .status_bar, "
|
|
908
|
+
\\ _ = try expectByText(tree.root, .status_bar, "total: 0 | stamped: -1ms");
|
|
489
909
|
\\
|
|
490
910
|
\\ // Click "+": the count increments and the view rebuilds with the
|
|
491
911
|
\\ // new value, keeping widget ids stable.
|
|
492
912
|
\\ const plus = try expectByText(tree.root, .button, "+");
|
|
493
|
-
\\ main.update(&model, tree.msgForPointer(plus.id, .up)
|
|
913
|
+
\\ main.update(&model, tree.msgForPointer(plus.id, .up).?, &fx);
|
|
494
914
|
\\ try testing.expectEqual(@as(i64, 1), model.count);
|
|
495
915
|
\\
|
|
496
916
|
\\ tree = try buildTree(arena, &model);
|
|
497
917
|
\\ _ = try expectByText(tree.root, .text, "1");
|
|
498
|
-
\\ _ = try expectByText(tree.root, .status_bar, "
|
|
918
|
+
\\ _ = try expectByText(tree.root, .status_bar, "total: 1 | stamped: -1ms");
|
|
499
919
|
\\ try testing.expectEqual(plus.id, (try expectByText(tree.root, .button, "+")).id);
|
|
500
920
|
\\
|
|
501
921
|
\\ // Click "-" twice: the count goes negative.
|
|
502
922
|
\\ const minus = try expectByText(tree.root, .button, "-");
|
|
503
|
-
\\ main.update(&model, tree.msgForPointer(minus.id, .up)
|
|
504
|
-
\\ main.update(&model, tree.msgForPointer(minus.id, .up)
|
|
923
|
+
\\ main.update(&model, tree.msgForPointer(minus.id, .up).?, &fx);
|
|
924
|
+
\\ main.update(&model, tree.msgForPointer(minus.id, .up).?, &fx);
|
|
505
925
|
\\ try testing.expectEqual(@as(i64, -1), model.count);
|
|
506
926
|
\\
|
|
507
|
-
\\ // Click "Reset": back to zero.
|
|
927
|
+
\\ // Click "Reset": the count and the tick tally both go back to zero.
|
|
508
928
|
\\ tree = try buildTree(arena, &model);
|
|
509
929
|
\\ const reset = try expectByText(tree.root, .button, "Reset");
|
|
510
|
-
\\ main.update(&model, tree.msgForPointer(reset.id, .up)
|
|
930
|
+
\\ main.update(&model, tree.msgForPointer(reset.id, .up).?, &fx);
|
|
511
931
|
\\ try testing.expectEqual(@as(i64, 0), model.count);
|
|
512
932
|
\\
|
|
513
933
|
\\ tree = try buildTree(arena, &model);
|
|
514
|
-
\\ _ = try expectByText(tree.root, .status_bar, "
|
|
934
|
+
\\ _ = try expectByText(tree.root, .status_bar, "total: 0 | stamped: -1ms");
|
|
935
|
+
\\}
|
|
936
|
+
\\
|
|
937
|
+
\\test "the ticking switch drives the repeating timer through the effects channel" {
|
|
938
|
+
\\ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
939
|
+
\\ defer arena_state.deinit();
|
|
940
|
+
\\ const arena = arena_state.allocator();
|
|
941
|
+
\\
|
|
942
|
+
\\ var fx = Effects.init(testing.allocator);
|
|
943
|
+
\\ defer fx.deinit();
|
|
944
|
+
\\ fx.executor = .fake;
|
|
945
|
+
\\
|
|
946
|
+
\\ var model = main.initialModel();
|
|
947
|
+
\\ var tree = try buildTree(arena, &model);
|
|
948
|
+
\\
|
|
949
|
+
\\ // Flip the switch on: the model tracks it and one repeating 1s
|
|
950
|
+
\\ // timer is registered on the effects channel.
|
|
951
|
+
\\ const ticker = try expectByText(tree.root, .switch_control, "Tick every second");
|
|
952
|
+
\\ main.update(&model, tree.msgForPointer(ticker.id, .up).?, &fx);
|
|
953
|
+
\\ try testing.expect(model.ticking);
|
|
954
|
+
\\ try testing.expectEqual(@as(usize, 1), fx.pendingTimerCount());
|
|
955
|
+
\\ const request = fx.pendingTimerAt(0).?;
|
|
956
|
+
\\ try testing.expectEqual(main.tick_timer_key, request.key);
|
|
957
|
+
\\ try testing.expectEqual(@as(u64, 1000), request.interval_ms);
|
|
958
|
+
\\
|
|
959
|
+
\\ // Each timer fire arrives as an ordinary `tick` Msg through the
|
|
960
|
+
\\ // same update path as a click.
|
|
961
|
+
\\ main.update(&model, .{ .tick = .{ .key = main.tick_timer_key } }, &fx);
|
|
962
|
+
\\ main.update(&model, .{ .tick = .{ .key = main.tick_timer_key } }, &fx);
|
|
963
|
+
\\ try testing.expectEqual(@as(i64, 2), model.tick_count);
|
|
964
|
+
\\
|
|
965
|
+
\\ tree = try buildTree(arena, &model);
|
|
966
|
+
\\ _ = try expectByText(tree.root, .text, "ticks 2");
|
|
967
|
+
\\ _ = try expectByText(tree.root, .status_bar, "total: 2 | stamped: -1ms");
|
|
968
|
+
\\
|
|
969
|
+
\\ // Flip it off: the timer is cancelled, nothing left armed.
|
|
970
|
+
\\ main.update(&model, tree.msgForPointer(ticker.id, .up).?, &fx);
|
|
971
|
+
\\ try testing.expect(!model.ticking);
|
|
972
|
+
\\ try testing.expectEqual(@as(usize, 0), fx.pendingTimerCount());
|
|
973
|
+
\\}
|
|
974
|
+
\\
|
|
975
|
+
\\test "stamp reads the journaled wall clock" {
|
|
976
|
+
\\ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
977
|
+
\\ defer arena_state.deinit();
|
|
978
|
+
\\ const arena = arena_state.allocator();
|
|
979
|
+
\\
|
|
980
|
+
\\ var fx = Effects.init(testing.allocator);
|
|
981
|
+
\\ defer fx.deinit();
|
|
982
|
+
\\ fx.executor = .fake;
|
|
983
|
+
\\ // Swap the clock seam for a hand-cranked one: `fx.wallMs()`
|
|
984
|
+
\\ // becomes deterministic, exactly like session replay.
|
|
985
|
+
\\ var test_clock = native_sdk.TestClock{};
|
|
986
|
+
\\ test_clock.setWallMs(4200);
|
|
987
|
+
\\ fx.clock = test_clock.clock();
|
|
988
|
+
\\
|
|
989
|
+
\\ var model = main.initialModel();
|
|
990
|
+
\\ var tree = try buildTree(arena, &model);
|
|
991
|
+
\\
|
|
992
|
+
\\ const stamp = try expectByText(tree.root, .button, "Stamp");
|
|
993
|
+
\\ main.update(&model, tree.msgForPointer(stamp.id, .up).?, &fx);
|
|
994
|
+
\\ try testing.expectEqual(@as(i64, 4200), model.stamped_ms);
|
|
995
|
+
\\
|
|
996
|
+
\\ tree = try buildTree(arena, &model);
|
|
997
|
+
\\ _ = try expectByText(tree.root, .status_bar, "total: 0 | stamped: 4200ms");
|
|
515
998
|
\\}
|
|
516
999
|
\\
|
|
517
1000
|
\\test "the view lays out through the canvas engine" {
|
|
@@ -665,8 +1148,26 @@ fn nativeReadme(allocator: std.mem.Allocator, names: TemplateNames, framework_pa
|
|
|
665
1148
|
/// GitHub Actions workflow for a native-rendered app: a null-platform
|
|
666
1149
|
/// logic-test job plus a Linux Xvfb automation smoke job that launches the
|
|
667
1150
|
/// real binary and asserts on the accessibility snapshot. The generated
|
|
668
|
-
/// file belongs to the user, like everything init writes.
|
|
669
|
-
|
|
1151
|
+
/// file belongs to the user, like everything init writes. A TypeScript
|
|
1152
|
+
/// core adds the node tier to both jobs: setup-node plus one `npm ci` in
|
|
1153
|
+
/// the fetched SDK's packages/core, because the @native-sdk/core
|
|
1154
|
+
/// transpiler runs under node at build time and needs its own installed
|
|
1155
|
+
/// dependency there — the same install `native build`'s teaching names.
|
|
1156
|
+
fn nativeCiYaml(allocator: std.mem.Allocator, names: TemplateNames, framework_path: []const u8, core: CoreTemplate) ![]const u8 {
|
|
1157
|
+
const node_setup =
|
|
1158
|
+
\\ - uses: actions/setup-node@v4
|
|
1159
|
+
\\ with:
|
|
1160
|
+
\\ node-version: 22
|
|
1161
|
+
\\
|
|
1162
|
+
;
|
|
1163
|
+
const transpiler_install =
|
|
1164
|
+
\\ - name: Install the core transpiler dependency
|
|
1165
|
+
\\ # src/core.ts compiles to native code at build time: the
|
|
1166
|
+
\\ # @native-sdk/core transpiler runs under node from the SDK
|
|
1167
|
+
\\ # dependency and needs its dependency installed there once.
|
|
1168
|
+
\\ run: npm ci --prefix "$NATIVE_SDK_PATH/packages/core"
|
|
1169
|
+
\\
|
|
1170
|
+
;
|
|
670
1171
|
var out: std.ArrayList(u8) = .empty;
|
|
671
1172
|
errdefer out.deinit(allocator);
|
|
672
1173
|
try out.appendSlice(allocator,
|
|
@@ -701,11 +1202,19 @@ fn nativeCiYaml(allocator: std.mem.Allocator, names: TemplateNames, framework_pa
|
|
|
701
1202
|
\\ - uses: mlugg/setup-zig@v2
|
|
702
1203
|
\\ with:
|
|
703
1204
|
\\ version: 0.16.0
|
|
1205
|
+
\\
|
|
1206
|
+
);
|
|
1207
|
+
if (core == .ts) try out.appendSlice(allocator, node_setup);
|
|
1208
|
+
try out.appendSlice(allocator,
|
|
704
1209
|
\\ - name: Fetch native-sdk
|
|
705
1210
|
\\ run: |
|
|
706
1211
|
\\ if [ ! -f "$NATIVE_SDK_PATH/build.zig" ]; then
|
|
707
1212
|
\\ git clone --depth 1 https://github.com/vercel-labs/native.git "$NATIVE_SDK_PATH"
|
|
708
1213
|
\\ fi
|
|
1214
|
+
\\
|
|
1215
|
+
);
|
|
1216
|
+
if (core == .ts) try out.appendSlice(allocator, transpiler_install);
|
|
1217
|
+
try out.appendSlice(allocator,
|
|
709
1218
|
\\ - run: zig build test -Dplatform=null
|
|
710
1219
|
\\
|
|
711
1220
|
\\ smoke:
|
|
@@ -716,6 +1225,10 @@ fn nativeCiYaml(allocator: std.mem.Allocator, names: TemplateNames, framework_pa
|
|
|
716
1225
|
\\ - uses: mlugg/setup-zig@v2
|
|
717
1226
|
\\ with:
|
|
718
1227
|
\\ version: 0.16.0
|
|
1228
|
+
\\
|
|
1229
|
+
);
|
|
1230
|
+
if (core == .ts) try out.appendSlice(allocator, node_setup);
|
|
1231
|
+
try out.appendSlice(allocator,
|
|
719
1232
|
\\ - name: Install GTK and Xvfb
|
|
720
1233
|
\\ # No WebKitGTK dev package: this app declares no web use, so its
|
|
721
1234
|
\\ # Linux host compiles without the embedded web layer and never
|
|
@@ -727,6 +1240,10 @@ fn nativeCiYaml(allocator: std.mem.Allocator, names: TemplateNames, framework_pa
|
|
|
727
1240
|
\\ if [ ! -f "$NATIVE_SDK_PATH/build.zig" ]; then
|
|
728
1241
|
\\ git clone --depth 1 https://github.com/vercel-labs/native.git "$NATIVE_SDK_PATH"
|
|
729
1242
|
\\ fi
|
|
1243
|
+
\\
|
|
1244
|
+
);
|
|
1245
|
+
if (core == .ts) try out.appendSlice(allocator, transpiler_install);
|
|
1246
|
+
try out.appendSlice(allocator,
|
|
730
1247
|
\\ - name: Build the Native SDK CLI
|
|
731
1248
|
\\ run: cd "$NATIVE_SDK_PATH" && zig build
|
|
732
1249
|
\\ - name: Build and drive the app headless
|
|
@@ -743,7 +1260,7 @@ fn nativeCiYaml(allocator: std.mem.Allocator, names: TemplateNames, framework_pa
|
|
|
743
1260
|
\\ pid=$!
|
|
744
1261
|
\\ trap 'kill "$pid" >/dev/null 2>&1 || true' EXIT
|
|
745
1262
|
\\ "$cli" automate wait
|
|
746
|
-
\\ "$cli" automate assert 'gpu_nonblank=true' 'role=button name="Reset"' '
|
|
1263
|
+
\\ "$cli" automate assert 'gpu_nonblank=true' 'role=button name="Reset"' 'total: 0'
|
|
747
1264
|
\\ "$cli" automate screenshot main-canvas
|
|
748
1265
|
\\ test -s .zig-cache/native-sdk-automation/screenshot-main-canvas.png
|
|
749
1266
|
\\
|
|
@@ -879,7 +1396,14 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
879
1396
|
\\
|
|
880
1397
|
\\pub fn build(b: *std.Build) void {
|
|
881
1398
|
\\ const target = nativeSdkTarget(b);
|
|
882
|
-
\\
|
|
1399
|
+
\\ // -Doptimize is registered by hand (not the std helper) so the
|
|
1400
|
+
\\ // graph can tell "unset" from "explicit": run/dev default to
|
|
1401
|
+
\\ // Debug for the edit loop, while `zig build package` wraps its own
|
|
1402
|
+
\\ // release-shaped exe — the same split `native dev`/`native build`
|
|
1403
|
+
\\ // apply. An explicit -Doptimize (or --release) pins both roles.
|
|
1404
|
+
\\ const optimize_request = b.option(std.builtin.OptimizeMode, "optimize", "Prioritize performance, safety, or binary size");
|
|
1405
|
+
\\ const optimize = optimizeMode(b, optimize_request, .Debug);
|
|
1406
|
+
\\ const package_optimize = optimizeMode(b, optimize_request, .ReleaseFast);
|
|
883
1407
|
\\ const platform_option = b.option(PlatformOption, "platform", "Desktop backend: auto, null, macos, linux, windows") orelse .auto;
|
|
884
1408
|
\\ const trace_option = b.option(TraceOption, "trace", "Trace output: off, events, runtime, all") orelse .events;
|
|
885
1409
|
\\ const debug_overlay = b.option(bool, "debug-overlay", "Enable debug overlay output") orelse false;
|
|
@@ -891,7 +1415,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
891
1415
|
\\ const cef_auto_install_override = b.option(bool, "cef-auto-install", "Override app.zon CEF auto-install setting");
|
|
892
1416
|
\\ const package_target = b.option(PackageTarget, "package-target", "Package target: macos, windows, linux") orelse .macos;
|
|
893
1417
|
\\ const native_sdk_path = b.option([]const u8, "native-sdk-path", "Path to the Native SDK framework checkout") orelse default_native_sdk_path;
|
|
894
|
-
\\ const
|
|
1418
|
+
\\ const package_optimize_name = @tagName(package_optimize);
|
|
895
1419
|
\\ const selected_platform: PlatformOption = switch (platform_option) {
|
|
896
1420
|
\\ .auto => if (target.result.os.tag == .macos) .macos else if (target.result.os.tag == .linux) .linux else if (target.result.os.tag == .windows) .windows else .@"null",
|
|
897
1421
|
\\ else => platform_option,
|
|
@@ -943,6 +1467,14 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
943
1467
|
\\ .name = app_exe_name,
|
|
944
1468
|
\\ .root_module = app_mod,
|
|
945
1469
|
\\ });
|
|
1470
|
+
\\ // Windows subsystem posture (mirrors the Native SDK build graph):
|
|
1471
|
+
\\ // release-shaped exes are GUI-subsystem so the app never flashes a
|
|
1472
|
+
\\ // console behind its window; Debug keeps the console for dev logs.
|
|
1473
|
+
\\ // Redirected logging still works on GUI exes - only console
|
|
1474
|
+
\\ // AUTO-allocation is subsystem-gated.
|
|
1475
|
+
\\ if (target.result.os.tag == .windows and optimize != .Debug) {
|
|
1476
|
+
\\ exe.subsystem = .windows;
|
|
1477
|
+
\\ }
|
|
946
1478
|
\\ linkPlatform(b, target, app_mod, exe, selected_platform, web_engine, web_layer, native_sdk_path, cef_dir, cef_auto_install);
|
|
947
1479
|
\\ b.installArtifact(exe);
|
|
948
1480
|
\\
|
|
@@ -970,6 +1502,33 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
970
1502
|
\\ const dev_step = b.step("dev", "Run the frontend dev server and native shell");
|
|
971
1503
|
\\ dev_step.dependOn(&dev.step);
|
|
972
1504
|
\\
|
|
1505
|
+
\\ // `zig build package` wraps its own exe: release-shaped by default
|
|
1506
|
+
\\ // (ReleaseFast, GUI subsystem on Windows) so the packaged artifact
|
|
1507
|
+
\\ // is never a Debug console binary just because the dev loop
|
|
1508
|
+
\\ // defaults to Debug. When -Doptimize/--release pinned one mode for
|
|
1509
|
+
\\ // everything, the roles agree and the dev exe is reused as-is.
|
|
1510
|
+
\\ const package_exe = if (package_optimize == optimize) exe else pkg: {
|
|
1511
|
+
\\ const package_sdk_mod = nativeSdkModule(b, target, package_optimize, native_sdk_path);
|
|
1512
|
+
\\ const package_runner_mod = localModule(b, target, package_optimize, "src/runner.zig");
|
|
1513
|
+
\\ package_runner_mod.addImport("native_sdk", package_sdk_mod);
|
|
1514
|
+
\\ package_runner_mod.addImport("build_options", options_mod);
|
|
1515
|
+
\\ package_runner_mod.addImport("app_manifest_zon", b.createModule(.{ .root_source_file = b.path("app.zon") }));
|
|
1516
|
+
\\ const package_app_mod = localModule(b, target, package_optimize, "src/main.zig");
|
|
1517
|
+
\\ package_app_mod.addImport("native_sdk", package_sdk_mod);
|
|
1518
|
+
\\ package_app_mod.addImport("runner", package_runner_mod);
|
|
1519
|
+
\\ const built = b.addExecutable(.{
|
|
1520
|
+
\\ .name = app_exe_name,
|
|
1521
|
+
\\ .root_module = package_app_mod,
|
|
1522
|
+
\\ });
|
|
1523
|
+
\\ // Same subsystem posture as the dev exe above, keyed on this
|
|
1524
|
+
\\ // exe's own mode: release-shaped Windows exes are GUI-subsystem.
|
|
1525
|
+
\\ if (target.result.os.tag == .windows and package_optimize != .Debug) {
|
|
1526
|
+
\\ built.subsystem = .windows;
|
|
1527
|
+
\\ }
|
|
1528
|
+
\\ linkPlatform(b, target, package_app_mod, built, selected_platform, web_engine, web_layer, native_sdk_path, cef_dir, cef_auto_install);
|
|
1529
|
+
\\ break :pkg built;
|
|
1530
|
+
\\ };
|
|
1531
|
+
\\
|
|
973
1532
|
\\ const package = b.addSystemCommand(&.{
|
|
974
1533
|
\\ "native",
|
|
975
1534
|
\\ "package",
|
|
@@ -983,9 +1542,9 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
983
1542
|
try out.appendSlice(allocator,
|
|
984
1543
|
\\,
|
|
985
1544
|
\\ "--optimize",
|
|
986
|
-
\\
|
|
1545
|
+
\\ package_optimize_name,
|
|
987
1546
|
\\ "--output",
|
|
988
|
-
\\ b.fmt("zig-out/package/{s}-0.1.0-{s}-{s}{s}", .{ app_exe_name, @tagName(package_target),
|
|
1547
|
+
\\ b.fmt("zig-out/package/{s}-0.1.0-{s}-{s}{s}", .{ app_exe_name, @tagName(package_target), package_optimize_name, packageSuffix(package_target) }),
|
|
989
1548
|
\\ "--binary",
|
|
990
1549
|
\\ });
|
|
991
1550
|
\\ // The CLI resolves SDK-owned package inputs (the vendored WebView2
|
|
@@ -993,7 +1552,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
993
1552
|
\\ // belong to a different checkout than the one this build compiled
|
|
994
1553
|
\\ // against, so hand the same root over explicitly.
|
|
995
1554
|
\\ package.setEnvironmentVariable("NATIVE_SDK_PATH", b.pathFromRoot(native_sdk_path));
|
|
996
|
-
\\ package.addFileArg(
|
|
1555
|
+
\\ package.addFileArg(package_exe.getEmittedBin());
|
|
997
1556
|
\\ package.addArgs(&.{ "--web-engine", @tagName(web_engine), "--cef-dir", cef_dir });
|
|
998
1557
|
\\ // Forward the RESOLVED web-layer decision, never the raw inputs:
|
|
999
1558
|
\\ // this graph already decided web vs native-only for the exe it is
|
|
@@ -1003,7 +1562,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
1003
1562
|
\\ // exe/package agreement structural.
|
|
1004
1563
|
\\ package.addArgs(&.{ "--web-layer", if (web_layer) "include" else "exclude" });
|
|
1005
1564
|
\\ if (cef_auto_install) package.addArg("--cef-auto-install");
|
|
1006
|
-
\\ package.step.dependOn(&
|
|
1565
|
+
\\ package.step.dependOn(&package_exe.step);
|
|
1007
1566
|
\\ package.step.dependOn(&frontend_build.step);
|
|
1008
1567
|
\\ const package_step = b.step("package", "Create a local package artifact");
|
|
1009
1568
|
\\ package_step.dependOn(&package.step);
|
|
@@ -1013,6 +1572,21 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
|
|
|
1013
1572
|
\\ test_step.dependOn(&b.addRunArtifact(tests).step);
|
|
1014
1573
|
\\}
|
|
1015
1574
|
\\
|
|
1575
|
+
\\// Resolve the optimize mode for one exe role (mirrors the Native SDK
|
|
1576
|
+
\\// build graph): an explicit -Doptimize wins for every role, --release
|
|
1577
|
+
\\// resolves through zig's release_mode, and only when neither was
|
|
1578
|
+
\\// passed does the role keep its own default — Debug for the dev loop,
|
|
1579
|
+
\\// ReleaseFast for the exe `zig build package` wraps.
|
|
1580
|
+
\\fn optimizeMode(b: *std.Build, requested: ?std.builtin.OptimizeMode, default_mode: std.builtin.OptimizeMode) std.builtin.OptimizeMode {
|
|
1581
|
+
\\ if (requested) |mode| return mode;
|
|
1582
|
+
\\ return switch (b.release_mode) {
|
|
1583
|
+
\\ .off => default_mode,
|
|
1584
|
+
\\ .any, .fast => .ReleaseFast,
|
|
1585
|
+
\\ .safe => .ReleaseSafe,
|
|
1586
|
+
\\ .small => .ReleaseSmall,
|
|
1587
|
+
\\ };
|
|
1588
|
+
\\}
|
|
1589
|
+
\\
|
|
1016
1590
|
\\fn nativeSdkTarget(b: *std.Build) std.Build.ResolvedTarget {
|
|
1017
1591
|
\\ const target = b.standardTargetOptions(.{});
|
|
1018
1592
|
\\ if (target.result.os.tag != .macos) return target;
|
|
@@ -3040,6 +3614,29 @@ test "writeDefaultApp emits Vite project files" {
|
|
|
3040
3614
|
// stub define and webkitgtk-6.0 is not linked when native-only.
|
|
3041
3615
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "\"-DNATIVE_SDK_ALLOW_WEBKITGTK_STUB\"") != null);
|
|
3042
3616
|
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "if (!web_layer) return;") != null);
|
|
3617
|
+
// Release-shaped Windows exes must be GUI-subsystem (same posture as
|
|
3618
|
+
// the SDK build graph) so packaged scaffold apps never flash a console.
|
|
3619
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "if (target.result.os.tag == .windows and optimize != .Debug) {") != null);
|
|
3620
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "exe.subsystem = .windows;") != null);
|
|
3621
|
+
// The package step wraps its own release-shaped exe: Debug stays the
|
|
3622
|
+
// run/dev default, but `zig build package` must never ship a Debug
|
|
3623
|
+
// (console-subsystem) binary unless the user pinned the mode
|
|
3624
|
+
// explicitly. The --optimize arg and the artifact name follow the
|
|
3625
|
+
// package exe's actual mode, and the exe carries its own
|
|
3626
|
+
// subsystem-posture check keyed on that mode.
|
|
3627
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "const optimize_request = b.option(std.builtin.OptimizeMode, \"optimize\"") != null);
|
|
3628
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "const optimize = optimizeMode(b, optimize_request, .Debug);") != null);
|
|
3629
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "const package_optimize = optimizeMode(b, optimize_request, .ReleaseFast);") != null);
|
|
3630
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "const package_exe = if (package_optimize == optimize) exe else pkg: {") != null);
|
|
3631
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "if (target.result.os.tag == .windows and package_optimize != .Debug) {") != null);
|
|
3632
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "built.subsystem = .windows;") != null);
|
|
3633
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "package.addFileArg(package_exe.getEmittedBin());") != null);
|
|
3634
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "package.step.dependOn(&package_exe.step);") != null);
|
|
3635
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "package_optimize_name,") != null);
|
|
3636
|
+
// No stale wiring: the package step must not reference the dev exe
|
|
3637
|
+
// or the old single-mode name.
|
|
3638
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "package.addFileArg(exe.getEmittedBin());") == null);
|
|
3639
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "standardOptimizeOption") == null);
|
|
3043
3640
|
try std.testing.expect(std.mem.indexOf(u8, main_zig_text, "frontend/dist") != null);
|
|
3044
3641
|
try std.testing.expect(std.mem.indexOf(u8, main_zig_text, "127.0.0.1:5173") != null);
|
|
3045
3642
|
try std.testing.expect(std.mem.indexOf(u8, runner_zig_text, "@import(\"app_manifest_zon\")") != null);
|
|
@@ -3101,14 +3698,113 @@ test "writeDefaultApp emits frontend-specific Next paths" {
|
|
|
3101
3698
|
try std.testing.expect(std.mem.indexOf(u8, tsconfig_text, "\"@/*\": [\"./app/*\"]") != null);
|
|
3102
3699
|
}
|
|
3103
3700
|
|
|
3104
|
-
test "writeDefaultApp emits
|
|
3105
|
-
const destination = ".zig-cache/test-
|
|
3701
|
+
test "writeDefaultApp emits the TS-core scaffold by default: three files of truth, zero Zig" {
|
|
3702
|
+
const destination = ".zig-cache/test-ts-slim-template";
|
|
3106
3703
|
try writeDefaultApp(std.testing.allocator, std.testing.io, destination, .{ .app_name = "My App", .framework_path = ".", .frontend = .native });
|
|
3107
3704
|
|
|
3705
|
+
const core_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "src/core.ts");
|
|
3706
|
+
defer std.testing.allocator.free(core_text);
|
|
3707
|
+
const markup_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "src/app.native");
|
|
3708
|
+
defer std.testing.allocator.free(markup_text);
|
|
3709
|
+
const ts_app_zon = try readTestFile(std.testing.allocator, std.testing.io, destination, "app.zon");
|
|
3710
|
+
defer std.testing.allocator.free(ts_app_zon);
|
|
3711
|
+
const ts_readme = try readTestFile(std.testing.allocator, std.testing.io, destination, "README.md");
|
|
3712
|
+
defer std.testing.allocator.free(ts_readme);
|
|
3713
|
+
|
|
3714
|
+
// ZERO Zig in the tree, no build files: the build graph detects
|
|
3715
|
+
// src/core.ts and stages the wiring outside the app. Zero-config
|
|
3716
|
+
// parity with the slim Zig scaffold: no CI workflow either — the
|
|
3717
|
+
// full shape owns that surface.
|
|
3718
|
+
try std.testing.expectError(error.FileNotFound, readTestFile(std.testing.allocator, std.testing.io, destination, "src/main.zig"));
|
|
3719
|
+
try std.testing.expectError(error.FileNotFound, readTestFile(std.testing.allocator, std.testing.io, destination, "build.zig"));
|
|
3720
|
+
try std.testing.expectError(error.FileNotFound, readTestFile(std.testing.allocator, std.testing.io, destination, ".github/workflows/ci.yml"));
|
|
3721
|
+
|
|
3722
|
+
// The starter uses one Cmd and one Sub, declares the lint opt-out, and
|
|
3723
|
+
// exports a bindable helper.
|
|
3724
|
+
try std.testing.expect(std.mem.indexOf(u8, core_text, "Cmd.now(") != null);
|
|
3725
|
+
try std.testing.expect(std.mem.indexOf(u8, core_text, "Sub.timer(") != null);
|
|
3726
|
+
try std.testing.expect(std.mem.indexOf(u8, core_text, "export const viewUnbound") != null);
|
|
3727
|
+
try std.testing.expect(std.mem.indexOf(u8, core_text, "export function total(") != null);
|
|
3728
|
+
// The markup binds the model's own TS field names and the helper.
|
|
3729
|
+
try std.testing.expect(std.mem.indexOf(u8, markup_text, "{tickCount}") != null);
|
|
3730
|
+
try std.testing.expect(std.mem.indexOf(u8, markup_text, "{total}") != null);
|
|
3731
|
+
try std.testing.expect(std.mem.indexOf(u8, ts_app_zon, "gpu_surface") != null);
|
|
3732
|
+
// The README teaches the loop, node-first.
|
|
3733
|
+
try std.testing.expect(std.mem.indexOf(u8, ts_readme, "native dev --core") != null);
|
|
3734
|
+
try std.testing.expect(std.mem.indexOf(u8, ts_readme, "native check") != null);
|
|
3735
|
+
|
|
3736
|
+
// The editor surface: package.json pins @native-sdk/core at the SDK's
|
|
3737
|
+
// bundled version, tsconfig.json mirrors the checker's options, and
|
|
3738
|
+
// node_modules carries the materialized SDK package so stock tsc
|
|
3739
|
+
// resolves both entry points before the npm publish exists.
|
|
3740
|
+
const package_json = try readTestFile(std.testing.allocator, std.testing.io, destination, "package.json");
|
|
3741
|
+
defer std.testing.allocator.free(package_json);
|
|
3742
|
+
try std.testing.expect(std.mem.indexOf(u8, package_json, "\"name\": \"my-app\"") != null);
|
|
3743
|
+
try std.testing.expect(std.mem.indexOf(u8, package_json, "\"private\": true") != null);
|
|
3744
|
+
const bundled_version = try ts_core.bundledSdkVersion(std.testing.allocator, std.testing.io, ".");
|
|
3745
|
+
defer std.testing.allocator.free(bundled_version);
|
|
3746
|
+
const pinned = try std.fmt.allocPrint(std.testing.allocator, "\"@native-sdk/core\": \"{s}\"", .{bundled_version});
|
|
3747
|
+
defer std.testing.allocator.free(pinned);
|
|
3748
|
+
try std.testing.expect(std.mem.indexOf(u8, package_json, pinned) != null);
|
|
3749
|
+
|
|
3750
|
+
const tsconfig = try readTestFile(std.testing.allocator, std.testing.io, destination, "tsconfig.json");
|
|
3751
|
+
defer std.testing.allocator.free(tsconfig);
|
|
3752
|
+
try std.testing.expect(std.mem.indexOf(u8, tsconfig, "\"strict\": true") != null);
|
|
3753
|
+
try std.testing.expect(std.mem.indexOf(u8, tsconfig, "\"moduleResolution\": \"bundler\"") != null);
|
|
3754
|
+
try std.testing.expect(std.mem.indexOf(u8, tsconfig, "\"noEmit\": true") != null);
|
|
3755
|
+
try std.testing.expect(std.mem.indexOf(u8, tsconfig, "\"exactOptionalPropertyTypes\": true") != null);
|
|
3756
|
+
|
|
3757
|
+
const editor_manifest = try readTestFile(std.testing.allocator, std.testing.io, destination, "node_modules/@native-sdk/core/package.json");
|
|
3758
|
+
defer std.testing.allocator.free(editor_manifest);
|
|
3759
|
+
try std.testing.expect(std.mem.indexOf(u8, editor_manifest, "\"@native-sdk/core\"") != null);
|
|
3760
|
+
const editor_core = try readTestFile(std.testing.allocator, std.testing.io, destination, "node_modules/@native-sdk/core/sdk/core.ts");
|
|
3761
|
+
defer std.testing.allocator.free(editor_core);
|
|
3762
|
+
try std.testing.expect(editor_core.len > 0);
|
|
3763
|
+
const editor_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "node_modules/@native-sdk/core/sdk/text.ts");
|
|
3764
|
+
defer std.testing.allocator.free(editor_text);
|
|
3765
|
+
try std.testing.expect(editor_text.len > 0);
|
|
3766
|
+
const editor_events = try readTestFile(std.testing.allocator, std.testing.io, destination, "node_modules/@native-sdk/core/sdk/events.ts");
|
|
3767
|
+
defer std.testing.allocator.free(editor_events);
|
|
3768
|
+
try std.testing.expect(editor_events.len > 0);
|
|
3769
|
+
|
|
3770
|
+
// node_modules is generated surface: ignored, never source.
|
|
3771
|
+
const ts_gitignore = try readTestFile(std.testing.allocator, std.testing.io, destination, ".gitignore");
|
|
3772
|
+
defer std.testing.allocator.free(ts_gitignore);
|
|
3773
|
+
try std.testing.expect(std.mem.indexOf(u8, ts_gitignore, "node_modules/") != null);
|
|
3774
|
+
try std.testing.expect(std.mem.indexOf(u8, ts_gitignore, ".native/") != null);
|
|
3775
|
+
}
|
|
3776
|
+
|
|
3777
|
+
test "writeDefaultApp --full ts-core carries the same editor surface" {
|
|
3778
|
+
const destination = ".zig-cache/test-ts-full-template";
|
|
3779
|
+
try writeDefaultApp(std.testing.allocator, std.testing.io, destination, .{ .app_name = "My App", .framework_path = ".", .frontend = .native, .shape = .full });
|
|
3780
|
+
|
|
3781
|
+
const build_zig_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "build.zig");
|
|
3782
|
+
defer std.testing.allocator.free(build_zig_text);
|
|
3783
|
+
try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "native_sdk.addApp") != null);
|
|
3784
|
+
const package_json = try readTestFile(std.testing.allocator, std.testing.io, destination, "package.json");
|
|
3785
|
+
defer std.testing.allocator.free(package_json);
|
|
3786
|
+
try std.testing.expect(std.mem.indexOf(u8, package_json, "\"@native-sdk/core\"") != null);
|
|
3787
|
+
const tsconfig = try readTestFile(std.testing.allocator, std.testing.io, destination, "tsconfig.json");
|
|
3788
|
+
defer std.testing.allocator.free(tsconfig);
|
|
3789
|
+
try std.testing.expect(std.mem.indexOf(u8, tsconfig, "\"moduleResolution\": \"bundler\"") != null);
|
|
3790
|
+
const editor_core = try readTestFile(std.testing.allocator, std.testing.io, destination, "node_modules/@native-sdk/core/sdk/core.ts");
|
|
3791
|
+
defer std.testing.allocator.free(editor_core);
|
|
3792
|
+
try std.testing.expect(editor_core.len > 0);
|
|
3793
|
+
const gitignore_text = try readTestFile(std.testing.allocator, std.testing.io, destination, ".gitignore");
|
|
3794
|
+
defer std.testing.allocator.free(gitignore_text);
|
|
3795
|
+
try std.testing.expect(std.mem.indexOf(u8, gitignore_text, "node_modules/") != null);
|
|
3796
|
+
}
|
|
3797
|
+
|
|
3798
|
+
test "writeDefaultApp --template zig-core emits the slim Zig scaffold at ts-core parity" {
|
|
3799
|
+
const destination = ".zig-cache/test-native-slim-template";
|
|
3800
|
+
try writeDefaultApp(std.testing.allocator, std.testing.io, destination, .{ .app_name = "My App", .framework_path = ".", .frontend = .native, .core = .zig });
|
|
3801
|
+
|
|
3108
3802
|
const app_zon_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "app.zon");
|
|
3109
3803
|
defer std.testing.allocator.free(app_zon_text);
|
|
3110
3804
|
const main_zig_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "src/main.zig");
|
|
3111
3805
|
defer std.testing.allocator.free(main_zig_text);
|
|
3806
|
+
const markup_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "src/app.native");
|
|
3807
|
+
defer std.testing.allocator.free(markup_text);
|
|
3112
3808
|
const gitignore_text = try readTestFile(std.testing.allocator, std.testing.io, destination, ".gitignore");
|
|
3113
3809
|
defer std.testing.allocator.free(gitignore_text);
|
|
3114
3810
|
const readme_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "README.md");
|
|
@@ -3116,14 +3812,34 @@ test "writeDefaultApp emits a slim native scaffold by default" {
|
|
|
3116
3812
|
const icon = try readTestFile(std.testing.allocator, std.testing.io, destination, "assets/icon.png");
|
|
3117
3813
|
defer std.testing.allocator.free(icon);
|
|
3118
3814
|
|
|
3119
|
-
// Zero-config: no build files, no editor config, no CI workflow
|
|
3815
|
+
// Zero-config: no build files, no editor config, no CI workflow — and
|
|
3816
|
+
// none of the TS scaffold's editor surface: a Zig app carries no
|
|
3817
|
+
// package.json/tsconfig/node_modules (zero residue; the tree is the
|
|
3818
|
+
// only language marker).
|
|
3120
3819
|
try std.testing.expectError(error.FileNotFound, readTestFile(std.testing.allocator, std.testing.io, destination, "build.zig"));
|
|
3121
3820
|
try std.testing.expectError(error.FileNotFound, readTestFile(std.testing.allocator, std.testing.io, destination, "build.zig.zon"));
|
|
3122
3821
|
try std.testing.expectError(error.FileNotFound, readTestFile(std.testing.allocator, std.testing.io, destination, ".vscode/settings.json"));
|
|
3123
3822
|
try std.testing.expectError(error.FileNotFound, readTestFile(std.testing.allocator, std.testing.io, destination, ".github/workflows/ci.yml"));
|
|
3823
|
+
try std.testing.expectError(error.FileNotFound, readTestFile(std.testing.allocator, std.testing.io, destination, "package.json"));
|
|
3824
|
+
try std.testing.expectError(error.FileNotFound, readTestFile(std.testing.allocator, std.testing.io, destination, "tsconfig.json"));
|
|
3825
|
+
try std.testing.expectError(error.FileNotFound, readTestFile(std.testing.allocator, std.testing.io, destination, "node_modules/@native-sdk/core/package.json"));
|
|
3124
3826
|
|
|
3125
3827
|
try std.testing.expect(std.mem.indexOf(u8, app_zon_text, "gpu_surface") != null);
|
|
3126
3828
|
try std.testing.expect(std.mem.indexOf(u8, main_zig_text, "native_sdk.UiApp(Model, Msg)") != null);
|
|
3829
|
+
// Feature parity with the ts-core starter: the same counter app with a
|
|
3830
|
+
// repeating fx timer (the Sub.timer equivalent), a journaled clock
|
|
3831
|
+
// read (the Cmd.now equivalent), the lint opt-out for the host-fired
|
|
3832
|
+
// arm, and a bindable single-model helper.
|
|
3833
|
+
try std.testing.expect(std.mem.indexOf(u8, main_zig_text, "fx.startTimer(") != null);
|
|
3834
|
+
try std.testing.expect(std.mem.indexOf(u8, main_zig_text, "fx.wallMs()") != null);
|
|
3835
|
+
try std.testing.expect(std.mem.indexOf(u8, main_zig_text, ".update_fx = update,") != null);
|
|
3836
|
+
try std.testing.expect(std.mem.indexOf(u8, main_zig_text, "pub const view_unbound = .{\"tick\"};") != null);
|
|
3837
|
+
try std.testing.expect(std.mem.indexOf(u8, main_zig_text, "pub fn total(") != null);
|
|
3838
|
+
// The markup is the ts starter's view over the Zig core's own field
|
|
3839
|
+
// names, bound exactly as main.zig wrote them.
|
|
3840
|
+
try std.testing.expect(std.mem.indexOf(u8, markup_text, "{tick_count}") != null);
|
|
3841
|
+
try std.testing.expect(std.mem.indexOf(u8, markup_text, "{total}") != null);
|
|
3842
|
+
try std.testing.expect(std.mem.indexOf(u8, markup_text, "on-toggle=\"toggle_ticking\"") != null);
|
|
3127
3843
|
// The generated + derived state is ignored wholesale.
|
|
3128
3844
|
try std.testing.expect(std.mem.indexOf(u8, gitignore_text, ".native/") != null);
|
|
3129
3845
|
try std.testing.expect(std.mem.indexOf(u8, gitignore_text, "zig-out/") != null);
|
|
@@ -3138,7 +3854,7 @@ test "writeDefaultApp emits a slim native scaffold by default" {
|
|
|
3138
3854
|
|
|
3139
3855
|
test "writeDefaultApp emits native project files" {
|
|
3140
3856
|
const destination = ".zig-cache/test-native-init-template";
|
|
3141
|
-
try writeDefaultApp(std.testing.allocator, std.testing.io, destination, .{ .app_name = "My App", .framework_path = ".", .frontend = .native, .shape = .full });
|
|
3857
|
+
try writeDefaultApp(std.testing.allocator, std.testing.io, destination, .{ .app_name = "My App", .framework_path = ".", .frontend = .native, .shape = .full, .core = .zig });
|
|
3142
3858
|
|
|
3143
3859
|
const app_zon_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "app.zon");
|
|
3144
3860
|
defer std.testing.allocator.free(app_zon_text);
|
|
@@ -3182,9 +3898,36 @@ test "writeDefaultApp emits native project files" {
|
|
|
3182
3898
|
try std.testing.expect(std.mem.indexOf(u8, readme_text, "hot") != null or std.mem.indexOf(u8, readme_text, "Hot") != null);
|
|
3183
3899
|
}
|
|
3184
3900
|
|
|
3901
|
+
test "writeDefaultApp --full ts-core emits a CI workflow with the node tier" {
|
|
3902
|
+
const destination = ".zig-cache/test-ts-ci-template";
|
|
3903
|
+
try writeDefaultApp(std.testing.allocator, std.testing.io, destination, .{ .app_name = "My App", .framework_path = ".", .frontend = .native, .shape = .full });
|
|
3904
|
+
|
|
3905
|
+
const ci_yaml_text = try readTestFile(std.testing.allocator, std.testing.io, destination, ".github/workflows/ci.yml");
|
|
3906
|
+
defer std.testing.allocator.free(ci_yaml_text);
|
|
3907
|
+
|
|
3908
|
+
try expectBasicYaml(ci_yaml_text);
|
|
3909
|
+
// The Zig full template's structure: logic tests plus the Linux
|
|
3910
|
+
// automation smoke, no WebKitGTK for a native-rendered app.
|
|
3911
|
+
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, " test:") != null);
|
|
3912
|
+
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, " smoke:") != null);
|
|
3913
|
+
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "mlugg/setup-zig@v2") != null);
|
|
3914
|
+
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "zig build test -Dplatform=null") != null);
|
|
3915
|
+
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "libgtk-4-dev xvfb") != null);
|
|
3916
|
+
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "libwebkitgtk-6.0-dev") == null);
|
|
3917
|
+
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "xvfb-run -a ./zig-out/bin/my-app &") != null);
|
|
3918
|
+
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "git clone --depth 1 https://github.com/vercel-labs/native.git \"$NATIVE_SDK_PATH\"") != null);
|
|
3919
|
+
// Plus the node tier the TS build needs: node on PATH and the
|
|
3920
|
+
// transpiler's own install inside the fetched SDK's packages/core,
|
|
3921
|
+
// in BOTH jobs (each builds the app, so each transpiles the core).
|
|
3922
|
+
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "actions/setup-node@v4") != null);
|
|
3923
|
+
const npm_ci = "npm ci --prefix \"$NATIVE_SDK_PATH/packages/core\"";
|
|
3924
|
+
const first = std.mem.indexOf(u8, ci_yaml_text, npm_ci).?;
|
|
3925
|
+
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text[first + npm_ci.len ..], npm_ci) != null);
|
|
3926
|
+
}
|
|
3927
|
+
|
|
3185
3928
|
test "writeDefaultApp emits a CI workflow for native apps" {
|
|
3186
3929
|
const destination = ".zig-cache/test-native-ci-template";
|
|
3187
|
-
try writeDefaultApp(std.testing.allocator, std.testing.io, destination, .{ .app_name = "My App", .framework_path = ".", .frontend = .native, .shape = .full });
|
|
3930
|
+
try writeDefaultApp(std.testing.allocator, std.testing.io, destination, .{ .app_name = "My App", .framework_path = ".", .frontend = .native, .shape = .full, .core = .zig });
|
|
3188
3931
|
|
|
3189
3932
|
const ci_yaml_text = try readTestFile(std.testing.allocator, std.testing.io, destination, ".github/workflows/ci.yml");
|
|
3190
3933
|
defer std.testing.allocator.free(ci_yaml_text);
|
|
@@ -3206,7 +3949,7 @@ test "writeDefaultApp emits a CI workflow for native apps" {
|
|
|
3206
3949
|
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "zig build -Dplatform=linux -Dweb-engine=system -Dautomation=true") != null);
|
|
3207
3950
|
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "xvfb-run -a ./zig-out/bin/my-app &") != null);
|
|
3208
3951
|
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "automate wait") != null);
|
|
3209
|
-
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "automate assert 'gpu_nonblank=true' 'role=button name=\"Reset\"' '
|
|
3952
|
+
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "automate assert 'gpu_nonblank=true' 'role=button name=\"Reset\"' 'total: 0'") != null);
|
|
3210
3953
|
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "automate screenshot main-canvas") != null);
|
|
3211
3954
|
try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "test -s .zig-cache/native-sdk-automation/screenshot-main-canvas.png") != null);
|
|
3212
3955
|
// The framework fetch step reuses the build.zig.zon dependency path.
|