@native-sdk/cli 0.9.4 → 0.10.0
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/README.md +3 -3
- package/build/app.zig +75 -57
- package/build/ts_run.mjs +1 -1
- package/build.zig +20 -2
- package/package.json +11 -10
- package/packages/core/package-lock.json +12 -11
- package/packages/core/package.json +2 -2
- package/packages/core/scripts/compiler_command.mjs +1 -1
- package/packages/core/scripts/run_external_core_compiler.mjs +19 -9
- package/packages/core/scripts/run_external_service_compiler.mjs +17 -8
- package/packages/core/scripts/vendor_service_packages.mjs +121 -8
- package/packages/core/sdk/events.d.ts +33 -4
- package/packages/core/sdk/events.ts +45 -6
- package/packages/core/src/checker.ts +103 -8
- package/packages/core/src/modules.ts +6 -2
- package/packages/core/src/sqlite_cli.ts +22 -2
- package/packages/core/src/typed_ast.ts +4 -2
- package/packages/core/src/types.ts +8 -8
- package/schemas/app.schema.json +446 -0
- package/skill-data/core/SKILL.md +53 -15
- package/skill-data/core/references/project-anatomy.md +6 -6
- package/skill-data/native-ui/SKILL.md +26 -5
- package/skill-data/ts-core/SKILL.md +6 -6
- package/skill-data/ts-services/references/service-surface.md +1 -1
- package/skills/native-sdk/SKILL.md +2 -2
- package/src/app_runner/root.zig +25 -0
- package/src/automation/snapshot.zig +91 -3
- package/src/platform/macos/appkit_host.h +66 -2
- package/src/platform/macos/appkit_host.m +735 -24
- package/src/platform/macos/cef_host.mm +208 -9
- package/src/platform/macos/root.zig +205 -3
- package/src/platform/null_platform.zig +50 -1
- package/src/platform/null_platform_tests.zig +53 -0
- package/src/platform/root.zig +12 -0
- package/src/platform/types.zig +73 -0
- package/src/platform/windows/root.zig +88 -15
- package/src/primitives/app_manifest/tests.zig +19 -0
- package/src/primitives/app_manifest/validation.zig +14 -2
- package/src/primitives/canvas/font_ttf.zig +24 -0
- package/src/primitives/canvas/gpu.zig +5 -0
- package/src/primitives/canvas/reference.zig +41 -16
- package/src/primitives/canvas/reference_tests.zig +63 -0
- package/src/primitives/canvas/render_tests.zig +1 -1
- package/src/primitives/canvas/root.zig +1 -0
- package/src/primitives/canvas/serialization.zig +1 -0
- package/src/primitives/canvas/test_support.zig +1 -0
- package/src/primitives/canvas/text.zig +1 -0
- package/src/primitives/canvas/text_layout.zig +84 -15
- package/src/primitives/canvas/text_layout_hash.zig +3 -1
- package/src/primitives/canvas/text_layout_types.zig +3 -0
- package/src/primitives/canvas/text_metrics.zig +28 -1
- package/src/primitives/canvas/text_tests.zig +61 -6
- package/src/primitives/canvas/ui.zig +9 -0
- package/src/primitives/canvas/ui_markup.zig +29 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +32 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +4 -2
- package/src/primitives/canvas/ui_markup_contract.zig +7 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +21 -0
- package/src/primitives/canvas/ui_markup_tests.zig +6 -0
- package/src/primitives/canvas/ui_markup_view.zig +28 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +32 -3
- package/src/primitives/canvas/ui_schema.zig +9 -0
- package/src/primitives/canvas/ui_schema_tests.zig +5 -3
- package/src/primitives/canvas/ui_tests.zig +4 -2
- package/src/primitives/canvas/widget_render.zig +13 -2
- package/src/primitives/canvas/widget_render_controls.zig +1 -0
- package/src/primitives/canvas/widget_semantics_tests.zig +3 -1
- package/src/root.zig +6 -0
- package/src/runtime/automation_snapshot.zig +3 -0
- package/src/runtime/canvas_fonts.zig +87 -0
- package/src/runtime/core.zig +1 -0
- package/src/runtime/flow.zig +8 -1
- package/src/runtime/native_command_event_tests.zig +58 -0
- package/src/runtime/state.zig +14 -0
- package/src/runtime/system_services.zig +62 -0
- package/src/runtime/ts_ui_app.zig +161 -33
- package/src/runtime/ui_app.zig +33 -1
- package/src/runtime/ui_app_tests.zig +63 -0
- package/src/runtime/validation.zig +87 -1
- package/src/tooling/android.zig +5 -4
- package/src/tooling/buildgraph.zig +24 -8
- package/src/tooling/db.zig +1 -1
- package/src/tooling/doctor.zig +1 -1
- package/src/tooling/ios.zig +5 -4
- package/src/tooling/json_to_zon.zig +136 -0
- package/src/tooling/manifest.zig +199 -35
- package/src/tooling/package.zig +33 -0
- package/src/tooling/raw_manifest.zig +11 -0
- package/src/tooling/root.zig +2 -0
- package/src/tooling/templates.zig +210 -116
- package/src/tooling/ts_core.zig +11 -7
- package/src/tooling/update.zig +576 -0
- package/src/tooling/verbs.zig +7 -6
- package/src/tooling/web_engine.zig +17 -1
- package/src/updater/c_api.zig +123 -0
- package/src/updater/feed.zig +215 -0
- package/src/updater/root.zig +10 -0
|
@@ -158,10 +158,12 @@ pub fn validateTrayPresentation(presentation: platform.TrayPresentation) !void {
|
|
|
158
158
|
try validateTrayTitle(presentation.title);
|
|
159
159
|
if (!std.math.isFinite(presentation.width) or presentation.width < 0) return error.InvalidTrayOptions;
|
|
160
160
|
if (!std.math.isFinite(presentation.icon_opacity) or presentation.icon_opacity < 0 or presentation.icon_opacity > 1) return error.InvalidTrayOptions;
|
|
161
|
+
if (!std.math.isFinite(presentation.font_size) or presentation.font_size < 0 or presentation.font_size > 64) return error.InvalidTrayOptions;
|
|
161
162
|
}
|
|
162
163
|
|
|
163
164
|
pub fn validateTrayMenuItems(items: []const platform.TrayMenuItem) !void {
|
|
164
165
|
if (items.len > platform.max_tray_items) return error.InvalidTrayOptions;
|
|
166
|
+
var fallback_row_count: usize = 0;
|
|
165
167
|
for (items, 0..) |item, index| {
|
|
166
168
|
try validateTrayField(item.label, platform.max_tray_item_label_bytes);
|
|
167
169
|
try validateTrayField(item.command, platform.max_tray_item_command_bytes);
|
|
@@ -170,6 +172,11 @@ pub fn validateTrayMenuItems(items: []const platform.TrayMenuItem) !void {
|
|
|
170
172
|
if (item.role != .command and item.role != .agent and item.command.len > 0) return error.InvalidTrayOptions;
|
|
171
173
|
if (item.detail.len > 0 and item.role != .info and item.role != .hero and item.role != .agent and item.role != .context) return error.InvalidTrayOptions;
|
|
172
174
|
if (item.separator and (item.detail.len > 0 or item.role != .command)) return error.InvalidTrayOptions;
|
|
175
|
+
if ((item.role == .segmented) != (item.segmented != null)) return error.InvalidTrayOptions;
|
|
176
|
+
if ((item.role == .chart) != (item.chart != null)) return error.InvalidTrayOptions;
|
|
177
|
+
if (item.metric != null and item.role != .hero) return error.InvalidTrayOptions;
|
|
178
|
+
if ((item.role == .segmented or item.role == .chart) and item.id != 0) return error.InvalidTrayOptions;
|
|
179
|
+
if ((item.role == .segmented or item.role == .chart) and item.label.len != 0) return error.InvalidTrayOptions;
|
|
173
180
|
if (item.id != 0) {
|
|
174
181
|
for (items[0..index]) |previous| {
|
|
175
182
|
if (previous.id == item.id) return error.InvalidTrayOptions;
|
|
@@ -179,11 +186,65 @@ pub fn validateTrayMenuItems(items: []const platform.TrayMenuItem) !void {
|
|
|
179
186
|
if (item.separator or item.id == 0) return error.InvalidTrayOptions;
|
|
180
187
|
try validateCommandName(item.command);
|
|
181
188
|
}
|
|
182
|
-
if (!item.separator and item.label.len == 0) return error.InvalidTrayOptions;
|
|
189
|
+
if (!item.separator and item.label.len == 0 and item.role != .segmented and item.role != .chart and item.metric == null) return error.InvalidTrayOptions;
|
|
183
190
|
if (item.key.len > 0) {
|
|
184
191
|
if (item.separator or item.command.len == 0) return error.InvalidTrayOptions;
|
|
185
192
|
if (!platform.isValidShortcutBinding(item.key, item.modifiers)) return error.InvalidTrayOptions;
|
|
186
193
|
}
|
|
194
|
+
if (item.segmented) |segmented| {
|
|
195
|
+
try validateTraySegmentedRow(items, index, segmented);
|
|
196
|
+
fallback_row_count += segmented.options.len;
|
|
197
|
+
} else {
|
|
198
|
+
fallback_row_count += 1;
|
|
199
|
+
}
|
|
200
|
+
if (item.metric) |metric| try validateTrayMetricRow(metric);
|
|
201
|
+
if (item.chart) |chart| try validateTrayChartRow(chart);
|
|
202
|
+
}
|
|
203
|
+
if (fallback_row_count > platform.max_tray_items) return error.InvalidTrayOptions;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
fn validateTrayMetricRow(metric: platform.TrayMetricRow) !void {
|
|
207
|
+
try validateTrayField(metric.primary_text, platform.max_tray_item_label_bytes);
|
|
208
|
+
try validateTrayField(metric.secondary_text, platform.max_tray_item_detail_bytes);
|
|
209
|
+
try validateTrayField(metric.accessibility_label, platform.max_tray_chart_text_bytes);
|
|
210
|
+
if (metric.primary_text.len == 0 or metric.accessibility_label.len == 0) return error.InvalidTrayOptions;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
fn validateTraySegmentedRow(items: []const platform.TrayMenuItem, row_index: usize, row: platform.TraySegmentedRow) !void {
|
|
214
|
+
if (row.options.len == 0 or row.options.len > platform.max_tray_segment_options) return error.InvalidTrayOptions;
|
|
215
|
+
var selected_count: usize = 0;
|
|
216
|
+
for (row.options, 0..) |option, option_index| {
|
|
217
|
+
if (option.id == 0) return error.InvalidTrayOptions;
|
|
218
|
+
try validateTrayField(option.label, platform.max_tray_segment_label_bytes);
|
|
219
|
+
try validateTrayField(option.command, platform.max_tray_item_command_bytes);
|
|
220
|
+
if (option.label.len == 0 or option.command.len == 0) return error.InvalidTrayOptions;
|
|
221
|
+
try validateCommandName(option.command);
|
|
222
|
+
if (option.selected) selected_count += 1;
|
|
223
|
+
for (row.options[0..option_index]) |previous| {
|
|
224
|
+
if (previous.id == option.id) return error.InvalidTrayOptions;
|
|
225
|
+
}
|
|
226
|
+
for (items, 0..) |other, other_index| {
|
|
227
|
+
if (other_index == row_index) continue;
|
|
228
|
+
if (other.id == option.id) return error.InvalidTrayOptions;
|
|
229
|
+
if (other.segmented) |other_segmented| {
|
|
230
|
+
for (other_segmented.options) |other_option| {
|
|
231
|
+
if (other_option.id == option.id) return error.InvalidTrayOptions;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (selected_count > 1) return error.InvalidTrayOptions;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
fn validateTrayChartRow(chart: platform.TrayChartRow) !void {
|
|
240
|
+
if (chart.values.len == 0 or chart.values.len > platform.max_tray_chart_values) return error.InvalidTrayOptions;
|
|
241
|
+
if (!std.math.isFinite(chart.min_value) or !std.math.isFinite(chart.max_value) or !(chart.max_value > chart.min_value)) return error.InvalidTrayOptions;
|
|
242
|
+
try validateTrayField(chart.leading_caption, platform.max_tray_chart_text_bytes);
|
|
243
|
+
try validateTrayField(chart.trailing_summary, platform.max_tray_chart_text_bytes);
|
|
244
|
+
try validateTrayField(chart.accessibility_label, platform.max_tray_chart_text_bytes);
|
|
245
|
+
if (chart.accessibility_label.len == 0) return error.InvalidTrayOptions;
|
|
246
|
+
for (chart.values) |value| {
|
|
247
|
+
if (!std.math.isFinite(value) or value < chart.min_value or value > chart.max_value) return error.InvalidTrayOptions;
|
|
187
248
|
}
|
|
188
249
|
}
|
|
189
250
|
|
|
@@ -246,3 +307,28 @@ pub fn validateViewFrame(frame: geometry.RectF) !void {
|
|
|
246
307
|
pub fn isValidWebViewFrame(frame: geometry.RectF) bool {
|
|
247
308
|
return frame.x >= 0 and frame.y >= 0 and frame.width > 0 and frame.height > 0;
|
|
248
309
|
}
|
|
310
|
+
|
|
311
|
+
test "typed rich tray rows validate bounded data and shared option ids" {
|
|
312
|
+
const segments = [_]platform.TraySegmentOption{
|
|
313
|
+
.{ .id = 11, .label = "Day", .command = "range.day", .selected = true },
|
|
314
|
+
.{ .id = 12, .label = "Week", .command = "range.week" },
|
|
315
|
+
};
|
|
316
|
+
const values = [_]f32{ 0.2, 0.5, 1.0 };
|
|
317
|
+
try validateTrayMenuItems(&.{
|
|
318
|
+
.{ .role = .hero, .metric = .{ .primary_text = "2,494 requests", .secondary_text = "Today · production", .accessibility_label = "2,494 requests today in production" } },
|
|
319
|
+
.{ .role = .segmented, .segmented = .{ .options = &segments } },
|
|
320
|
+
.{ .role = .chart, .chart = .{ .values = &values, .min_value = 0, .max_value = 1, .leading_caption = "CPU", .trailing_summary = "42%", .accessibility_label = "CPU history, 42 percent" } },
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
const duplicate_segments = [_]platform.TraySegmentOption{
|
|
324
|
+
.{ .id = 11, .label = "Day", .command = "range.day" },
|
|
325
|
+
.{ .id = 11, .label = "Week", .command = "range.week" },
|
|
326
|
+
};
|
|
327
|
+
try std.testing.expectError(error.InvalidTrayOptions, validateTrayMenuItems(&.{
|
|
328
|
+
.{ .role = .segmented, .segmented = .{ .options = &duplicate_segments } },
|
|
329
|
+
}));
|
|
330
|
+
const out_of_range = [_]f32{1.1};
|
|
331
|
+
try std.testing.expectError(error.InvalidTrayOptions, validateTrayMenuItems(&.{
|
|
332
|
+
.{ .role = .chart, .chart = .{ .values = &out_of_range, .min_value = 0, .max_value = 1, .accessibility_label = "bad" } },
|
|
333
|
+
}));
|
|
334
|
+
}
|
package/src/tooling/android.zig
CHANGED
|
@@ -423,6 +423,7 @@ pub fn buildEmbedLib(allocator: std.mem.Allocator, io: std.Io, app_name: []const
|
|
|
423
423
|
build_file = try buildgraph.ensureGeneratedBuild(allocator, io, ".", .{
|
|
424
424
|
.app_name = app_name,
|
|
425
425
|
.framework_root = framework_root,
|
|
426
|
+
.manifest_name = manifest_tool.defaultPath(io) orelse "app.json",
|
|
426
427
|
});
|
|
427
428
|
try argv.appendSlice(allocator, &.{ "--build-file", build_file.? });
|
|
428
429
|
}
|
|
@@ -655,15 +656,15 @@ pub const DevOptions = struct {
|
|
|
655
656
|
/// directory through an Io the desktop runner supplies, and the embed
|
|
656
657
|
/// host supplies neither — edit + rerun is the loop today.
|
|
657
658
|
pub fn runDev(allocator: std.mem.Allocator, io: std.Io, options: DevOptions) !void {
|
|
658
|
-
|
|
659
|
+
const manifest_path = manifest_tool.defaultPath(io) orelse {
|
|
659
660
|
std.debug.print(
|
|
660
|
-
\\no app.zon here — `native dev --target android` runs inside an app directory
|
|
661
|
+
\\no app.json or app.zon here — `native dev --target android` runs inside an app directory
|
|
661
662
|
\\(or pass one: `native dev path/to/app --target android`). Start one with `native init`.
|
|
662
663
|
\\
|
|
663
664
|
, .{});
|
|
664
665
|
return error.MissingManifest;
|
|
665
|
-
}
|
|
666
|
-
const metadata = try manifest_tool.readMetadata(allocator, io,
|
|
666
|
+
};
|
|
667
|
+
const metadata = try manifest_tool.readMetadata(allocator, io, manifest_path);
|
|
667
668
|
const application_id = try applicationIdAlloc(allocator, metadata.id);
|
|
668
669
|
defer allocator.free(application_id);
|
|
669
670
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! Zero-config build graph: when an app directory carries only app.zon +
|
|
1
|
+
//! Zero-config build graph: when an app directory carries only app.json/app.zon +
|
|
2
2
|
//! src/ (+ assets), the CLI synthesizes a build.zig/build.zig.zon pair into
|
|
3
3
|
//! `<app>/.native/build/` and drives it with `zig build --build-file`. The
|
|
4
4
|
//! generated build.zig is the same ~5-line `addApp` call every ejected app
|
|
@@ -127,6 +127,7 @@ pub const GenerateOptions = struct {
|
|
|
127
127
|
app_name: []const u8,
|
|
128
128
|
/// Absolute path to the framework checkout (resolveFrameworkRoot).
|
|
129
129
|
framework_root: []const u8,
|
|
130
|
+
manifest_name: []const u8 = "app.zon",
|
|
130
131
|
};
|
|
131
132
|
|
|
132
133
|
/// Synthesize (or refresh) `<app>/.native/build/{build.zig,build.zig.zon}`.
|
|
@@ -181,7 +182,7 @@ pub fn ensureGeneratedBuild(allocator: std.mem.Allocator, io: std.Io, app_dir: [
|
|
|
181
182
|
},
|
|
182
183
|
};
|
|
183
184
|
|
|
184
|
-
const build_zig = try
|
|
185
|
+
const build_zig = try renderBuildZigWithManifest(allocator, options.app_name, .generated, options.manifest_name);
|
|
185
186
|
defer allocator.free(build_zig);
|
|
186
187
|
const build_zon = try renderBuildZon(allocator, options.app_name, zon_dependency_path, .generated);
|
|
187
188
|
defer allocator.free(build_zon);
|
|
@@ -197,6 +198,7 @@ pub fn ensureGeneratedBuild(allocator: std.mem.Allocator, io: std.Io, app_dir: [
|
|
|
197
198
|
pub const EjectOptions = struct {
|
|
198
199
|
app_name: []const u8,
|
|
199
200
|
framework_root: []const u8,
|
|
201
|
+
manifest_name: []const u8 = "app.zon",
|
|
200
202
|
};
|
|
201
203
|
|
|
202
204
|
/// Write an owned build.zig/build.zig.zon pair into the app directory.
|
|
@@ -239,9 +241,9 @@ pub fn eject(allocator: std.mem.Allocator, io: std.Io, app_dir: []const u8, opti
|
|
|
239
241
|
},
|
|
240
242
|
};
|
|
241
243
|
|
|
242
|
-
const build_zig = try
|
|
244
|
+
const build_zig = try renderBuildZigWithManifest(allocator, options.app_name, .ejected, options.manifest_name);
|
|
243
245
|
defer allocator.free(build_zig);
|
|
244
|
-
const build_zon = try
|
|
246
|
+
const build_zon = try renderBuildZonWithManifest(allocator, options.app_name, zon_dependency_path, .ejected, options.manifest_name);
|
|
245
247
|
defer allocator.free(build_zon);
|
|
246
248
|
|
|
247
249
|
try dir.writeFile(io, .{ .sub_path = "build.zig", .data = build_zig });
|
|
@@ -257,12 +259,16 @@ const Shape = enum {
|
|
|
257
259
|
};
|
|
258
260
|
|
|
259
261
|
pub fn renderBuildZig(allocator: std.mem.Allocator, app_name: []const u8, shape: Shape) ![]u8 {
|
|
262
|
+
return renderBuildZigWithManifest(allocator, app_name, shape, "app.zon");
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
fn renderBuildZigWithManifest(allocator: std.mem.Allocator, app_name: []const u8, shape: Shape, manifest_name: []const u8) ![]u8 {
|
|
260
266
|
var out: std.ArrayList(u8) = .empty;
|
|
261
267
|
errdefer out.deinit(allocator);
|
|
262
268
|
switch (shape) {
|
|
263
269
|
.generated => try out.appendSlice(allocator,
|
|
264
270
|
\\//! Generated by the `native` CLI — do not edit. This file is
|
|
265
|
-
\\//! re-synthesized from app
|
|
271
|
+
\\//! re-synthesized from the app manifest on every `native dev|build|test`
|
|
266
272
|
\\//! and any change here is overwritten. Run `native eject` to
|
|
267
273
|
\\//! write a build.zig you own into the app directory instead.
|
|
268
274
|
\\
|
|
@@ -291,6 +297,8 @@ pub fn renderBuildZig(allocator: std.mem.Allocator, app_name: []const u8, shape:
|
|
|
291
297
|
);
|
|
292
298
|
try out.appendSlice(allocator, " ");
|
|
293
299
|
try appendZigString(&out, allocator, app_name);
|
|
300
|
+
try out.appendSlice(allocator, ", .manifest = ");
|
|
301
|
+
try appendZigString(&out, allocator, manifest_name);
|
|
294
302
|
switch (shape) {
|
|
295
303
|
.generated => try out.appendSlice(allocator, ", .app_root = \"../..\""),
|
|
296
304
|
.ejected => {},
|
|
@@ -304,6 +312,10 @@ pub fn renderBuildZig(allocator: std.mem.Allocator, app_name: []const u8, shape:
|
|
|
304
312
|
}
|
|
305
313
|
|
|
306
314
|
pub fn renderBuildZon(allocator: std.mem.Allocator, app_name: []const u8, dependency_path: []const u8, shape: Shape) ![]u8 {
|
|
315
|
+
return renderBuildZonWithManifest(allocator, app_name, dependency_path, shape, "app.zon");
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
fn renderBuildZonWithManifest(allocator: std.mem.Allocator, app_name: []const u8, dependency_path: []const u8, shape: Shape, manifest_name: []const u8) ![]u8 {
|
|
307
319
|
const module_name = try templates.normalizeModuleName(allocator, app_name);
|
|
308
320
|
defer allocator.free(module_name);
|
|
309
321
|
|
|
@@ -325,7 +337,11 @@ pub fn renderBuildZon(allocator: std.mem.Allocator, app_name: []const u8, depend
|
|
|
325
337
|
try out.appendSlice(allocator, " } },\n");
|
|
326
338
|
switch (shape) {
|
|
327
339
|
.generated => try out.appendSlice(allocator, " .paths = .{ \"build.zig\", \"build.zig.zon\" },\n"),
|
|
328
|
-
.ejected =>
|
|
340
|
+
.ejected => {
|
|
341
|
+
try out.appendSlice(allocator, " .paths = .{ \"build.zig\", \"build.zig.zon\", \"src\", \"assets\", ");
|
|
342
|
+
try appendZigString(&out, allocator, manifest_name);
|
|
343
|
+
try out.appendSlice(allocator, " },\n");
|
|
344
|
+
},
|
|
329
345
|
}
|
|
330
346
|
try out.appendSlice(allocator, "}\n");
|
|
331
347
|
return out.toOwnedSlice(allocator);
|
|
@@ -354,14 +370,14 @@ test "generated build.zig points addApp two directories up" {
|
|
|
354
370
|
const text = try renderBuildZig(std.testing.allocator, "my-app", .generated);
|
|
355
371
|
defer std.testing.allocator.free(text);
|
|
356
372
|
try std.testing.expect(std.mem.indexOf(u8, text, "Generated by the `native` CLI") != null);
|
|
357
|
-
try std.testing.expect(std.mem.indexOf(u8, text, ".name = \"my-app\", .app_root = \"../..\"") != null);
|
|
373
|
+
try std.testing.expect(std.mem.indexOf(u8, text, ".name = \"my-app\", .manifest = \"app.zon\", .app_root = \"../..\"") != null);
|
|
358
374
|
}
|
|
359
375
|
|
|
360
376
|
test "ejected build.zig is the plain addApp call with an ownership header" {
|
|
361
377
|
const text = try renderBuildZig(std.testing.allocator, "my-app", .ejected);
|
|
362
378
|
defer std.testing.allocator.free(text);
|
|
363
379
|
try std.testing.expect(std.mem.indexOf(u8, text, "native eject") != null);
|
|
364
|
-
try std.testing.expect(std.mem.indexOf(u8, text, ".{ .name = \"my-app\" }") != null);
|
|
380
|
+
try std.testing.expect(std.mem.indexOf(u8, text, ".{ .name = \"my-app\", .manifest = \"app.zon\" }") != null);
|
|
365
381
|
try std.testing.expect(std.mem.indexOf(u8, text, "app_root") == null);
|
|
366
382
|
}
|
|
367
383
|
|
package/src/tooling/db.zig
CHANGED
|
@@ -126,7 +126,7 @@ fn migrationSourceVersion(io: std.Io) !u32 {
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
fn appDbPath(allocator: std.mem.Allocator, io: std.Io, env: *std.process.Environ.Map, buffer: []u8) ![]const u8 {
|
|
129
|
-
const metadata = try manifest_tool.readMetadata(allocator, io,
|
|
129
|
+
const metadata = try manifest_tool.readMetadata(allocator, io, manifest_tool.defaultPath(io) orelse return error.FileNotFound);
|
|
130
130
|
var dir_buffer: [std.Io.Dir.max_path_bytes]u8 = undefined;
|
|
131
131
|
const data_dir = try app_dirs.resolveOne(
|
|
132
132
|
.{ .name = metadata.id },
|
package/src/tooling/doctor.zig
CHANGED
|
@@ -165,7 +165,7 @@ pub fn reportForCurrentHostWithProbe(
|
|
|
165
165
|
} else if (target.os != .macos) {
|
|
166
166
|
try buffers.add("webview-system", .unsupported, "system WebView backend is not wired for this host yet", .{});
|
|
167
167
|
}
|
|
168
|
-
var manifest_engine = web_engine.readManifestConfig(allocator, io, options.manifest_path orelse "app.
|
|
168
|
+
var manifest_engine = web_engine.readManifestConfig(allocator, io, options.manifest_path orelse manifest_tool.defaultPath(io) orelse "app.json") catch web_engine.ManifestConfig{};
|
|
169
169
|
defer manifest_engine.deinit(allocator);
|
|
170
170
|
const resolved_engine = web_engine.resolve(manifest_engine, .{
|
|
171
171
|
.web_engine = options.web_engine_override,
|
package/src/tooling/ios.zig
CHANGED
|
@@ -216,6 +216,7 @@ pub fn buildEmbedLib(allocator: std.mem.Allocator, io: std.Io, app_name: []const
|
|
|
216
216
|
build_file = try buildgraph.ensureGeneratedBuild(allocator, io, ".", .{
|
|
217
217
|
.app_name = app_name,
|
|
218
218
|
.framework_root = framework_root,
|
|
219
|
+
.manifest_name = manifest_tool.defaultPath(io) orelse "app.json",
|
|
219
220
|
});
|
|
220
221
|
try argv.appendSlice(allocator, &.{ "--build-file", build_file.? });
|
|
221
222
|
}
|
|
@@ -262,15 +263,15 @@ pub const DevOptions = struct {
|
|
|
262
263
|
/// directory through an Io the desktop runner supplies, and the embed
|
|
263
264
|
/// host supplies neither — edit + rerun is the loop today.
|
|
264
265
|
pub fn runDev(allocator: std.mem.Allocator, io: std.Io, options: DevOptions) !void {
|
|
265
|
-
|
|
266
|
+
const manifest_path = manifest_tool.defaultPath(io) orelse {
|
|
266
267
|
std.debug.print(
|
|
267
|
-
\\no app.zon here — `native dev --target ios` runs inside an app directory
|
|
268
|
+
\\no app.json or app.zon here — `native dev --target ios` runs inside an app directory
|
|
268
269
|
\\(or pass one: `native dev path/to/app --target ios`). Start one with `native init`.
|
|
269
270
|
\\
|
|
270
271
|
, .{});
|
|
271
272
|
return error.MissingManifest;
|
|
272
|
-
}
|
|
273
|
-
const metadata = try manifest_tool.readMetadata(allocator, io,
|
|
273
|
+
};
|
|
274
|
+
const metadata = try manifest_tool.readMetadata(allocator, io, manifest_path);
|
|
274
275
|
const bundle_id = try bundleIdAlloc(allocator, metadata.id);
|
|
275
276
|
defer allocator.free(bundle_id);
|
|
276
277
|
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
//! Lossless JSON-to-ZON syntax adapter for app manifests. JSON is the
|
|
2
|
+
//! authoring format; generated/ejected Zig build graphs feed this equivalent
|
|
3
|
+
//! module to the existing comptime runner so both syntaxes have one runtime
|
|
4
|
+
//! feature implementation.
|
|
5
|
+
|
|
6
|
+
const std = @import("std");
|
|
7
|
+
|
|
8
|
+
pub fn convertAlloc(allocator: std.mem.Allocator, source: []const u8) ![]u8 {
|
|
9
|
+
var arena = std.heap.ArenaAllocator.init(allocator);
|
|
10
|
+
defer arena.deinit();
|
|
11
|
+
// Keep numeric tokens as authored. Parsing through f64 first can round a
|
|
12
|
+
// valid u64 manifest value before the generated ZON module sees it.
|
|
13
|
+
const root = try std.json.parseFromSliceLeaky(std.json.Value, arena.allocator(), source, .{ .parse_numbers = false });
|
|
14
|
+
if (root != .object) return error.ExpectedObject;
|
|
15
|
+
try validateValue(root);
|
|
16
|
+
|
|
17
|
+
var out = std.Io.Writer.Allocating.init(allocator);
|
|
18
|
+
errdefer out.deinit();
|
|
19
|
+
try writeValue(&out.writer, root, 0);
|
|
20
|
+
try out.writer.writeByte('\n');
|
|
21
|
+
return out.toOwnedSlice();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
pub fn validateSource(allocator: std.mem.Allocator, source: []const u8) !void {
|
|
25
|
+
var arena = std.heap.ArenaAllocator.init(allocator);
|
|
26
|
+
defer arena.deinit();
|
|
27
|
+
const root = try std.json.parseFromSliceLeaky(std.json.Value, arena.allocator(), source, .{ .parse_numbers = false });
|
|
28
|
+
if (root != .object) return error.ExpectedObject;
|
|
29
|
+
try validateValue(root);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
pub fn isJsonPath(path: []const u8) bool {
|
|
33
|
+
return std.ascii.eqlIgnoreCase(std.fs.path.extension(path), ".json");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
fn validateValue(value: std.json.Value) !void {
|
|
37
|
+
switch (value) {
|
|
38
|
+
.null => return error.NullNotAllowed,
|
|
39
|
+
.array => |array| for (array.items) |item| try validateValue(item),
|
|
40
|
+
.object => |object| {
|
|
41
|
+
var iterator = object.iterator();
|
|
42
|
+
while (iterator.next()) |entry| try validateValue(entry.value_ptr.*);
|
|
43
|
+
},
|
|
44
|
+
else => {},
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
fn writeValue(writer: *std.Io.Writer, value: std.json.Value, depth: usize) !void {
|
|
49
|
+
switch (value) {
|
|
50
|
+
.null => return error.NullNotAllowed,
|
|
51
|
+
.bool => |boolean| try writer.writeAll(if (boolean) "true" else "false"),
|
|
52
|
+
.integer => |integer| try writer.print("{d}", .{integer}),
|
|
53
|
+
.float => |float| try writer.print("{d}", .{float}),
|
|
54
|
+
.number_string => |number| try writer.writeAll(number),
|
|
55
|
+
.string => |string| try writer.print("\"{f}\"", .{std.zig.fmtString(string)}),
|
|
56
|
+
.array => |array| {
|
|
57
|
+
if (array.items.len == 0) return writer.writeAll(".{}");
|
|
58
|
+
try writer.writeAll(".{\n");
|
|
59
|
+
for (array.items) |item| {
|
|
60
|
+
try indent(writer, depth + 1);
|
|
61
|
+
try writeValue(writer, item, depth + 1);
|
|
62
|
+
try writer.writeAll(",\n");
|
|
63
|
+
}
|
|
64
|
+
try indent(writer, depth);
|
|
65
|
+
try writer.writeByte('}');
|
|
66
|
+
},
|
|
67
|
+
.object => |object| {
|
|
68
|
+
if (object.count() == 0) return writer.writeAll(".{}");
|
|
69
|
+
try writer.writeAll(".{\n");
|
|
70
|
+
var iterator = object.iterator();
|
|
71
|
+
while (iterator.next()) |entry| {
|
|
72
|
+
// $schema is editor metadata, not an app runtime field.
|
|
73
|
+
if (depth == 0 and std.mem.eql(u8, entry.key_ptr.*, "$schema")) continue;
|
|
74
|
+
try indent(writer, depth + 1);
|
|
75
|
+
try writer.print(".{f} = ", .{std.zig.fmtId(entry.key_ptr.*)});
|
|
76
|
+
try writeValue(writer, entry.value_ptr.*, depth + 1);
|
|
77
|
+
try writer.writeAll(",\n");
|
|
78
|
+
}
|
|
79
|
+
try indent(writer, depth);
|
|
80
|
+
try writer.writeByte('}');
|
|
81
|
+
},
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
fn indent(writer: *std.Io.Writer, depth: usize) !void {
|
|
86
|
+
try writer.splatByteAll(' ', depth * 4);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
test "converts a JSON manifest to a Zig manifest module" {
|
|
90
|
+
const converted = try convertAlloc(std.testing.allocator,
|
|
91
|
+
\\{
|
|
92
|
+
\\ "$schema": "https://schema.native-sdk.dev/app/v1.json",
|
|
93
|
+
\\ "id": "dev.example.app",
|
|
94
|
+
\\ "name": "example",
|
|
95
|
+
\\ "version": "1.0.0",
|
|
96
|
+
\\ "dock_visible": true,
|
|
97
|
+
\\ "windows": [{ "label": "main", "width": 480.5 }]
|
|
98
|
+
\\}
|
|
99
|
+
);
|
|
100
|
+
defer std.testing.allocator.free(converted);
|
|
101
|
+
try std.testing.expect(std.mem.indexOf(u8, converted, "$schema") == null);
|
|
102
|
+
try std.testing.expect(std.mem.indexOf(u8, converted, ".id = \"dev.example.app\"") != null);
|
|
103
|
+
try std.testing.expect(std.mem.indexOf(u8, converted, ".windows = .{") != null);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
test "JSON manifests reject explicit null and recognize extension case-insensitively" {
|
|
107
|
+
try std.testing.expectError(error.NullNotAllowed, convertAlloc(std.testing.allocator,
|
|
108
|
+
\\{ "id": "dev.example.app", "name": "example", "version": "1.0.0", "theme": null }
|
|
109
|
+
));
|
|
110
|
+
try std.testing.expect(isJsonPath("app.json"));
|
|
111
|
+
try std.testing.expect(isJsonPath("config/APP.JSON"));
|
|
112
|
+
try std.testing.expect(!isJsonPath("app.zon"));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
test "JSON-to-ZON conversion preserves numeric tokens exactly" {
|
|
116
|
+
const converted = try convertAlloc(std.testing.allocator,
|
|
117
|
+
\\{
|
|
118
|
+
\\ "assets": { "images": [{ "id": 9007199254740993.0, "path": "assets/cover.png" }] },
|
|
119
|
+
\\ "frontend": { "dev": { "url": "http://127.0.0.1:5173/", "timeout_ms": 1e3 } }
|
|
120
|
+
\\}
|
|
121
|
+
);
|
|
122
|
+
defer std.testing.allocator.free(converted);
|
|
123
|
+
try std.testing.expect(std.mem.indexOf(u8, converted, ".id = 9007199254740993.0") != null);
|
|
124
|
+
try std.testing.expect(std.mem.indexOf(u8, converted, ".timeout_ms = 1e3") != null);
|
|
125
|
+
|
|
126
|
+
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
127
|
+
defer arena.deinit();
|
|
128
|
+
const source_z = try arena.allocator().dupeZ(u8, converted);
|
|
129
|
+
const Parsed = struct {
|
|
130
|
+
assets: struct { images: []const struct { id: u64, path: []const u8 } },
|
|
131
|
+
frontend: struct { dev: struct { url: []const u8, timeout_ms: u32 } },
|
|
132
|
+
};
|
|
133
|
+
const parsed = try std.zon.parse.fromSliceAlloc(Parsed, arena.allocator(), source_z, null, .{});
|
|
134
|
+
try std.testing.expectEqual(@as(u64, 9_007_199_254_740_993), parsed.assets.images[0].id);
|
|
135
|
+
try std.testing.expectEqual(@as(u32, 1000), parsed.frontend.dev.timeout_ms);
|
|
136
|
+
}
|