@native-sdk/cli 0.9.5 → 0.10.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.
Files changed (49) hide show
  1. package/build/app.zig +7 -0
  2. package/build/ts_run.mjs +1 -1
  3. package/build.zig +30 -5
  4. package/package.json +10 -10
  5. package/packages/core/package-lock.json +12 -11
  6. package/packages/core/package.json +2 -2
  7. package/packages/core/scripts/compiler_command.mjs +1 -1
  8. package/schemas/app.schema.json +12 -1
  9. package/skill-data/core/references/web-engines-packaging-debugging.md +2 -1
  10. package/skill-data/ts-services/references/service-surface.md +1 -1
  11. package/src/app_runner/root.zig +25 -0
  12. package/src/platform/macos/appkit_host.h +25 -0
  13. package/src/platform/macos/appkit_host.m +537 -15
  14. package/src/platform/macos/cef_host.mm +17 -0
  15. package/src/platform/macos/root.zig +95 -0
  16. package/src/platform/root.zig +3 -0
  17. package/src/platform/types.zig +15 -0
  18. package/src/primitives/app_manifest/tests.zig +19 -0
  19. package/src/primitives/app_manifest/validation.zig +14 -2
  20. package/src/primitives/canvas/font_ttf.zig +24 -0
  21. package/src/primitives/canvas/gpu.zig +5 -0
  22. package/src/primitives/canvas/reference.zig +4 -1
  23. package/src/primitives/canvas/render_tests.zig +1 -1
  24. package/src/primitives/canvas/root.zig +1 -0
  25. package/src/primitives/canvas/serialization.zig +1 -0
  26. package/src/primitives/canvas/test_support.zig +1 -0
  27. package/src/primitives/canvas/text.zig +1 -0
  28. package/src/primitives/canvas/text_layout.zig +84 -15
  29. package/src/primitives/canvas/text_layout_hash.zig +3 -1
  30. package/src/primitives/canvas/text_layout_types.zig +3 -0
  31. package/src/primitives/canvas/text_metrics.zig +28 -1
  32. package/src/primitives/canvas/text_tests.zig +61 -6
  33. package/src/primitives/canvas/widget_render.zig +6 -0
  34. package/src/primitives/canvas/widget_render_controls.zig +1 -0
  35. package/src/root.zig +2 -0
  36. package/src/runtime/canvas_fonts.zig +87 -0
  37. package/src/runtime/core.zig +1 -0
  38. package/src/runtime/flow.zig +7 -0
  39. package/src/runtime/native_command_event_tests.zig +58 -0
  40. package/src/tooling/codesign.zig +125 -74
  41. package/src/tooling/manifest.zig +79 -2
  42. package/src/tooling/package.zig +118 -1
  43. package/src/tooling/raw_manifest.zig +7 -0
  44. package/src/tooling/root.zig +1 -0
  45. package/src/tooling/templates.zig +45 -0
  46. package/src/tooling/update.zig +576 -0
  47. package/src/updater/c_api.zig +123 -0
  48. package/src/updater/feed.zig +215 -0
  49. package/src/updater/root.zig +10 -0
@@ -13,14 +13,13 @@ pub const CodesignArgs = struct {
13
13
  identity: []const u8 = "-",
14
14
  entitlements: ?[]const u8 = null,
15
15
  hardened_runtime: bool = false,
16
+ secure_timestamp: bool = false,
16
17
  deep: bool = true,
17
18
  };
18
19
 
19
20
  pub const NotarizeArgs = struct {
20
- app_path: []const u8,
21
- team_id: []const u8,
22
- apple_id: ?[]const u8 = null,
23
- password_keychain_item: ?[]const u8 = null,
21
+ artifact_path: []const u8,
22
+ keychain_profile: []const u8,
24
23
  };
25
24
 
26
25
  // Every command in this pipeline is built as an ARGV ARRAY, never as a
@@ -29,7 +28,7 @@ pub const NotarizeArgs = struct {
29
28
  // replaced split `My App.app` into two arguments, codesign signed
30
29
  // nothing, and the failure never surfaced.
31
30
 
32
- pub const sign_argv_capacity = 10;
31
+ pub const sign_argv_capacity = 11;
33
32
 
34
33
  pub fn signArgv(buffer: *[sign_argv_capacity][]const u8, args: CodesignArgs) []const []const u8 {
35
34
  var len: usize = 0;
@@ -51,6 +50,10 @@ pub fn signArgv(buffer: *[sign_argv_capacity][]const u8, args: CodesignArgs) []c
51
50
  buffer[len] = "runtime";
52
51
  len += 1;
53
52
  }
53
+ if (args.secure_timestamp) {
54
+ buffer[len] = "--timestamp";
55
+ len += 1;
56
+ }
54
57
  if (args.entitlements) |ent| {
55
58
  buffer[len] = "--entitlements";
56
59
  len += 1;
@@ -67,6 +70,11 @@ pub fn verifyArgv(buffer: *[6][]const u8, app_path: []const u8) []const []const
67
70
  return buffer;
68
71
  }
69
72
 
73
+ pub fn verifyArtifactArgv(buffer: *[5][]const u8, artifact_path: []const u8) []const []const u8 {
74
+ buffer.* = .{ "codesign", "--verify", "--strict", "--verbose=2", artifact_path };
75
+ return buffer;
76
+ }
77
+
70
78
  pub fn zipArgv(buffer: *[6][]const u8, app_path: []const u8, zip_path: []const u8) []const []const u8 {
71
79
  buffer.* = .{ "ditto", "-c", "-k", "--keepParent", app_path, zip_path };
72
80
  return buffer;
@@ -77,37 +85,18 @@ pub fn stapleArgv(buffer: *[4][]const u8, app_path: []const u8) []const []const
77
85
  return buffer;
78
86
  }
79
87
 
80
- pub const notarize_submit_argv_capacity = 11;
88
+ pub fn stapleValidateArgv(buffer: *[4][]const u8, app_path: []const u8) []const []const u8 {
89
+ buffer.* = .{ "xcrun", "stapler", "validate", app_path };
90
+ return buffer;
91
+ }
81
92
 
82
- pub fn notarizeSubmitArgv(buffer: *[notarize_submit_argv_capacity][]const u8, zip_path: []const u8, password_value: ?[]const u8, args: NotarizeArgs) []const []const u8 {
83
- var len: usize = 0;
84
- buffer[len] = "xcrun";
85
- len += 1;
86
- buffer[len] = "notarytool";
87
- len += 1;
88
- buffer[len] = "submit";
89
- len += 1;
90
- buffer[len] = zip_path;
91
- len += 1;
92
- buffer[len] = "--team-id";
93
- len += 1;
94
- buffer[len] = args.team_id;
95
- len += 1;
96
- if (args.apple_id) |apple_id| {
97
- buffer[len] = "--apple-id";
98
- len += 1;
99
- buffer[len] = apple_id;
100
- len += 1;
101
- }
102
- if (password_value) |value| {
103
- buffer[len] = "--password";
104
- len += 1;
105
- buffer[len] = value;
106
- len += 1;
107
- }
108
- buffer[len] = "--wait";
109
- len += 1;
110
- return buffer[0..len];
93
+ pub fn notarizeSubmitArgv(buffer: *[9][]const u8, artifact_path: []const u8, keychain_profile: []const u8) []const []const u8 {
94
+ buffer.* = .{
95
+ "xcrun", "notarytool", "submit",
96
+ artifact_path, "--keychain-profile", keychain_profile,
97
+ "--wait", "--output-format", "json",
98
+ };
99
+ return buffer;
111
100
  }
112
101
 
113
102
  pub fn signAdHoc(allocator: std.mem.Allocator, io: std.Io, app_path: []const u8) !SignResult {
@@ -120,10 +109,20 @@ pub fn signIdentity(allocator: std.mem.Allocator, io: std.Io, app_path: []const
120
109
  .identity = identity,
121
110
  .entitlements = entitlements,
122
111
  .hardened_runtime = true,
112
+ .secure_timestamp = true,
123
113
  .deep = true,
124
114
  });
125
115
  }
126
116
 
117
+ pub fn signIdentityArtifact(allocator: std.mem.Allocator, io: std.Io, artifact_path: []const u8, identity: []const u8) !SignResult {
118
+ return runSign(allocator, io, .{
119
+ .app_path = artifact_path,
120
+ .identity = identity,
121
+ .secure_timestamp = true,
122
+ .deep = false,
123
+ });
124
+ }
125
+
127
126
  /// `codesign --verify --deep --strict` over the signed bundle: the same
128
127
  /// check Gatekeeper and an Apple silicon launch effectively run, so a
129
128
  /// signature that only LOOKS applied (stale seal, unsigned nested code)
@@ -133,37 +132,58 @@ pub fn verify(allocator: std.mem.Allocator, io: std.Io, app_path: []const u8) !S
133
132
  return runTool(allocator, io, verifyArgv(&buffer, app_path));
134
133
  }
135
134
 
136
- pub fn notarize(allocator: std.mem.Allocator, io: std.Io, args: NotarizeArgs) !SignResult {
137
- const zip_path = try std.fmt.allocPrint(allocator, "{s}.zip", .{args.app_path});
135
+ pub fn verifyArtifact(allocator: std.mem.Allocator, io: std.Io, artifact_path: []const u8) !SignResult {
136
+ var buffer: [5][]const u8 = undefined;
137
+ return runTool(allocator, io, verifyArtifactArgv(&buffer, artifact_path));
138
+ }
139
+
140
+ pub fn notarizeApp(allocator: std.mem.Allocator, io: std.Io, args: NotarizeArgs) !SignResult {
141
+ const zip_path = try std.fmt.allocPrint(allocator, "{s}.notarize.zip", .{args.artifact_path});
138
142
  defer allocator.free(zip_path);
143
+ defer std.Io.Dir.cwd().deleteFile(io, zip_path) catch {};
139
144
 
140
- {
141
- var zip_buffer: [6][]const u8 = undefined;
142
- const zip_result = try runTool(allocator, io, zipArgv(&zip_buffer, args.app_path, zip_path));
143
- if (!zip_result.ok) return failedStep(allocator, "ditto (zip for notarization)", zip_result);
144
- allocator.free(zip_result.message);
145
- }
145
+ var zip_buffer: [6][]const u8 = undefined;
146
+ const zip_result = try runTool(allocator, io, zipArgv(&zip_buffer, args.artifact_path, zip_path));
147
+ if (!zip_result.ok) return failedStep(allocator, "ditto (zip for notarization)", zip_result);
148
+ allocator.free(zip_result.message);
146
149
 
147
- {
148
- const password_value: ?[]const u8 = if (args.password_keychain_item) |item|
149
- try std.fmt.allocPrint(allocator, "@keychain:{s}", .{item})
150
- else
151
- null;
152
- defer if (password_value) |value| allocator.free(value);
153
- var submit_buffer: [notarize_submit_argv_capacity][]const u8 = undefined;
154
- const submit_result = try runTool(allocator, io, notarizeSubmitArgv(&submit_buffer, zip_path, password_value, args));
155
- if (!submit_result.ok) return failedStep(allocator, "notarytool submit", submit_result);
156
- allocator.free(submit_result.message);
157
- }
150
+ return notarizeArtifact(allocator, io, .{
151
+ .artifact_path = args.artifact_path,
152
+ .keychain_profile = args.keychain_profile,
153
+ }, zip_path);
154
+ }
158
155
 
159
- {
160
- var staple_buffer: [4][]const u8 = undefined;
161
- const staple_result = try runTool(allocator, io, stapleArgv(&staple_buffer, args.app_path));
162
- if (!staple_result.ok) return failedStep(allocator, "stapler staple", staple_result);
163
- allocator.free(staple_result.message);
164
- }
156
+ pub fn notarizeArtifact(allocator: std.mem.Allocator, io: std.Io, args: NotarizeArgs, submission_path: ?[]const u8) !SignResult {
157
+ var submit_buffer: [9][]const u8 = undefined;
158
+ const submit_result = try runTool(allocator, io, notarizeSubmitArgv(&submit_buffer, submission_path orelse args.artifact_path, args.keychain_profile));
159
+ if (!submit_result.ok) return failedStep(allocator, "notarytool submit", submit_result);
160
+ if (!notarizationAccepted(allocator, submit_result.message)) return failedStep(allocator, "notarytool returned a non-accepted status", submit_result);
161
+ allocator.free(submit_result.message);
165
162
 
166
- return .{ .ok = true, .message = try allocator.dupe(u8, "notarization complete") };
163
+ var staple_buffer: [4][]const u8 = undefined;
164
+ const staple_result = try runTool(allocator, io, stapleArgv(&staple_buffer, args.artifact_path));
165
+ if (!staple_result.ok) return failedStep(allocator, "stapler staple", staple_result);
166
+ allocator.free(staple_result.message);
167
+
168
+ var validate_buffer: [4][]const u8 = undefined;
169
+ const validate_result = try runTool(allocator, io, stapleValidateArgv(&validate_buffer, args.artifact_path));
170
+ if (!validate_result.ok) return failedStep(allocator, "stapler validate", validate_result);
171
+ allocator.free(validate_result.message);
172
+
173
+ return .{ .ok = true, .message = try allocator.dupe(u8, "notarization accepted, stapled, and validated") };
174
+ }
175
+
176
+ fn notarizationAccepted(allocator: std.mem.Allocator, output: []const u8) bool {
177
+ const start = std.mem.indexOfScalar(u8, output, '{') orelse return false;
178
+ const end = std.mem.lastIndexOfScalar(u8, output, '}') orelse return false;
179
+ if (end < start) return false;
180
+ var parsed = std.json.parseFromSlice(std.json.Value, allocator, output[start .. end + 1], .{}) catch return false;
181
+ defer parsed.deinit();
182
+ const status = switch (parsed.value) {
183
+ .object => |object| object.get("status") orelse return false,
184
+ else => return false,
185
+ };
186
+ return status == .string and std.mem.eql(u8, status.string, "Accepted");
167
187
  }
168
188
 
169
189
  fn failedStep(allocator: std.mem.Allocator, step: []const u8, result: SignResult) !SignResult {
@@ -215,13 +235,30 @@ test "identity sign argv includes runtime and entitlements as single arguments"
215
235
  .identity = "Developer ID Application: Test Person (ABCD1234)",
216
236
  .entitlements = "assets dir/native-sdk.entitlements",
217
237
  .hardened_runtime = true,
238
+ .secure_timestamp = true,
239
+ });
240
+ const expected = [_][]const u8{
241
+ "codesign", "--sign",
242
+ "Developer ID Application: Test Person (ABCD1234)", "--force",
243
+ "--deep", "--options",
244
+ "runtime", "--timestamp",
245
+ "--entitlements", "assets dir/native-sdk.entitlements",
246
+ "/tmp/My Demo App.app",
247
+ };
248
+ try expectArgv(&expected, argv);
249
+ }
250
+
251
+ test "distribution artifact sign argv requests a secure timestamp without app-only options" {
252
+ var buffer: [sign_argv_capacity][]const u8 = undefined;
253
+ const argv = signArgv(&buffer, .{
254
+ .app_path = "/tmp/My Demo App.dmg",
255
+ .identity = "Developer ID Application: Test Person (ABCD1234)",
256
+ .secure_timestamp = true,
257
+ .deep = false,
218
258
  });
219
259
  const expected = [_][]const u8{
220
- "codesign", "--sign",
221
- "Developer ID Application: Test Person (ABCD1234)", "--force",
222
- "--deep", "--options",
223
- "runtime", "--entitlements",
224
- "assets dir/native-sdk.entitlements", "/tmp/My Demo App.app",
260
+ "codesign", "--sign", "Developer ID Application: Test Person (ABCD1234)",
261
+ "--force", "--timestamp", "/tmp/My Demo App.dmg",
225
262
  };
226
263
  try expectArgv(&expected, argv);
227
264
  }
@@ -233,14 +270,17 @@ test "verify argv runs the strict deep check on the bundle path" {
233
270
  try expectArgv(&expected, argv);
234
271
  }
235
272
 
236
- test "notarize submit argv includes team id, keychain password, and wait" {
237
- var buffer: [notarize_submit_argv_capacity][]const u8 = undefined;
238
- const argv = notarizeSubmitArgv(&buffer, "/tmp/My Demo App.app.zip", "@keychain:AC_PASSWORD", .{
239
- .app_path = "/tmp/My Demo App.app",
240
- .team_id = "ABCD1234",
241
- .apple_id = "dev@example.com",
242
- });
243
- const expected = [_][]const u8{ "xcrun", "notarytool", "submit", "/tmp/My Demo App.app.zip", "--team-id", "ABCD1234", "--apple-id", "dev@example.com", "--password", "@keychain:AC_PASSWORD", "--wait" };
273
+ test "artifact verify argv runs the strict check without bundle recursion" {
274
+ var buffer: [5][]const u8 = undefined;
275
+ const argv = verifyArtifactArgv(&buffer, "/tmp/My Demo App.dmg");
276
+ const expected = [_][]const u8{ "codesign", "--verify", "--strict", "--verbose=2", "/tmp/My Demo App.dmg" };
277
+ try expectArgv(&expected, argv);
278
+ }
279
+
280
+ test "notarize submit argv uses a keychain profile, waits, and requests JSON" {
281
+ var buffer: [9][]const u8 = undefined;
282
+ const argv = notarizeSubmitArgv(&buffer, "/tmp/My Demo App.dmg", "vercel-release");
283
+ const expected = [_][]const u8{ "xcrun", "notarytool", "submit", "/tmp/My Demo App.dmg", "--keychain-profile", "vercel-release", "--wait", "--output-format", "json" };
244
284
  try expectArgv(&expected, argv);
245
285
  }
246
286
 
@@ -250,12 +290,23 @@ test "staple and zip argv carry spaced paths as single arguments" {
250
290
  const staple_expected = [_][]const u8{ "xcrun", "stapler", "staple", "/tmp/My Demo App.app" };
251
291
  try expectArgv(&staple_expected, staple);
252
292
 
293
+ var validate_buffer: [4][]const u8 = undefined;
294
+ const validate = stapleValidateArgv(&validate_buffer, "/tmp/My Demo App.app");
295
+ const validate_expected = [_][]const u8{ "xcrun", "stapler", "validate", "/tmp/My Demo App.app" };
296
+ try expectArgv(&validate_expected, validate);
297
+
253
298
  var zip_buffer: [6][]const u8 = undefined;
254
299
  const zip = zipArgv(&zip_buffer, "/tmp/My Demo App.app", "/tmp/My Demo App.app.zip");
255
300
  const zip_expected = [_][]const u8{ "ditto", "-c", "-k", "--keepParent", "/tmp/My Demo App.app", "/tmp/My Demo App.app.zip" };
256
301
  try expectArgv(&zip_expected, zip);
257
302
  }
258
303
 
304
+ test "notarization accepts only an explicit Accepted JSON status" {
305
+ try std.testing.expect(notarizationAccepted(std.testing.allocator, "{\"id\":\"123\",\"status\":\"Accepted\"}\n"));
306
+ try std.testing.expect(!notarizationAccepted(std.testing.allocator, "{\"id\":\"123\",\"status\":\"Invalid\"}\n"));
307
+ try std.testing.expect(!notarizationAccepted(std.testing.allocator, "not JSON"));
308
+ }
309
+
259
310
  test "a failing tool surfaces its own output, not a silent success" {
260
311
  if (@import("builtin").os.tag == .windows) return error.SkipZigTest;
261
312
  // `false` exits 1 with no output: the result must be a failure.
@@ -63,6 +63,7 @@ pub const Metadata = struct {
63
63
  shortcuts: []const ShortcutMetadata = &.{},
64
64
  file_associations: []const FileAssociationMetadata = &.{},
65
65
  url_schemes: []const UrlSchemeMetadata = &.{},
66
+ updates: UpdateMetadata = .{},
66
67
  dmg: DmgMetadata = .{},
67
68
 
68
69
  pub fn displayName(self: Metadata) []const u8 {
@@ -209,6 +210,8 @@ pub const Metadata = struct {
209
210
  allocator.free(scheme.role);
210
211
  }
211
212
  if (self.url_schemes.len > 0) allocator.free(self.url_schemes);
213
+ if (self.updates.feed_url) |value| allocator.free(value);
214
+ if (self.updates.public_key) |value| allocator.free(value);
212
215
  if (self.dmg.volume_name) |value| allocator.free(value);
213
216
  if (self.dmg.background) |value| allocator.free(value);
214
217
  for (self.dmg.items) |item| {
@@ -416,6 +419,16 @@ pub const DmgMetadata = struct {
416
419
  items: []const DmgItemMetadata = &.{},
417
420
  };
418
421
 
422
+ pub const UpdateMetadata = struct {
423
+ feed_url: ?[]const u8 = null,
424
+ public_key: ?[]const u8 = null,
425
+ check_on_start: bool = false,
426
+
427
+ pub fn enabled(self: UpdateMetadata) bool {
428
+ return self.feed_url != null;
429
+ }
430
+ };
431
+
419
432
  pub const FrontendDevMetadata = struct {
420
433
  url: []const u8,
421
434
  command: []const []const u8 = &.{},
@@ -462,6 +475,7 @@ const RawMenuItem = raw_manifest.RawMenuItem;
462
475
  const RawShortcut = raw_manifest.RawShortcut;
463
476
  const RawFileAssociation = raw_manifest.RawFileAssociation;
464
477
  const RawUrlScheme = raw_manifest.RawUrlScheme;
478
+ const RawUpdates = raw_manifest.RawUpdates;
465
479
  const RawDmg = raw_manifest.RawDmg;
466
480
  const RawDmgItem = raw_manifest.RawDmgItem;
467
481
 
@@ -563,6 +577,7 @@ pub fn validateFile(allocator: std.mem.Allocator, io: std.Io, path: []const u8)
563
577
  defer allocator.free(file_associations);
564
578
  const url_schemes = parseUrlSchemes(allocator, metadata.url_schemes) catch return .{ .ok = false, .message = "app manifest URL schemes are invalid" };
565
579
  defer allocator.free(url_schemes);
580
+ const updates = convertUpdates(metadata.updates) catch return .{ .ok = false, .message = "app manifest updates are invalid - updates require an HTTPS feed_url and a base64 Ed25519 public_key; check_on_start requires both" };
566
581
  // General manifest validation owns only values the app explicitly
567
582
  // declared. Archive-time fallbacks (notably display_name as the volume
568
583
  // name) are validated when a macOS archive is actually requested, so an
@@ -572,6 +587,10 @@ pub fn validateFile(allocator: std.mem.Allocator, io: std.Io, path: []const u8)
572
587
  return .{ .ok = false, .message = dmg_message };
573
588
  }
574
589
  const manifest_web_engine = parseWebEngine(metadata.web_engine) catch return .{ .ok = false, .message = "app manifest web engine is invalid" };
590
+ if (metadata.updates.enabled() and manifest_web_engine == .chromium) return .{
591
+ .ok = false,
592
+ .message = "native updates currently require web_engine = \"system\" on macOS; the Chromium host does not yet provide the updater UI/install lifecycle",
593
+ };
575
594
  const manifest_webview_layer = parseWebViewLayer(metadata.webview_layer) catch return .{ .ok = false, .message = "app manifest webview_layer is invalid - expected \"auto\", \"include\", or \"exclude\"" };
576
595
  if (!std.mem.eql(u8, metadata.core_compiler, "external")) {
577
596
  if (std.mem.eql(u8, metadata.core_compiler, "transpiler")) {
@@ -601,6 +620,7 @@ pub fn validateFile(allocator: std.mem.Allocator, io: std.Io, path: []const u8)
601
620
  .shortcuts = shortcuts,
602
621
  .file_associations = file_associations,
603
622
  .url_schemes = url_schemes,
623
+ .updates = updates,
604
624
  .cef = .{ .dir = metadata.cef.dir, .auto_install = metadata.cef.auto_install },
605
625
  .webview_layer = manifest_webview_layer,
606
626
  .package = .{ .web_engine = manifest_web_engine },
@@ -712,10 +732,28 @@ fn metadataFromRaw(allocator: std.mem.Allocator, raw: RawManifest) !Metadata {
712
732
  .shortcuts = try convertRawShortcuts(allocator, raw.shortcuts),
713
733
  .file_associations = try convertRawFileAssociations(allocator, raw.file_associations),
714
734
  .url_schemes = try convertRawUrlSchemes(allocator, raw.url_schemes),
735
+ .updates = try duplicateRawUpdates(allocator, raw.updates),
715
736
  .dmg = try convertRawDmg(allocator, raw.dmg),
716
737
  };
717
738
  }
718
739
 
740
+ fn duplicateRawUpdates(allocator: std.mem.Allocator, raw: RawUpdates) !UpdateMetadata {
741
+ return .{
742
+ .feed_url = try duplicateOptionalString(allocator, raw.feed_url),
743
+ .public_key = try duplicateOptionalString(allocator, raw.public_key),
744
+ .check_on_start = raw.check_on_start,
745
+ };
746
+ }
747
+
748
+ fn convertUpdates(updates: UpdateMetadata) !app_manifest.UpdateConfig {
749
+ if (updates.feed_url == null and updates.public_key == null and !updates.check_on_start) return .{};
750
+ const feed_url = updates.feed_url orelse return error.InvalidUpdates;
751
+ const public_key = updates.public_key orelse return error.InvalidUpdates;
752
+ if (!std.mem.startsWith(u8, feed_url, "https://")) return error.InvalidUpdates;
753
+ if (public_key.len == 0) return error.InvalidUpdates;
754
+ return .{ .feed_url = feed_url, .public_key = public_key, .check_on_start = updates.check_on_start };
755
+ }
756
+
719
757
  fn duplicateRawServicePackages(allocator: std.mem.Allocator, packages: []const raw_manifest.RawServicePackage) ![]const ServicePackageMetadata {
720
758
  if (packages.len == 0) return &.{};
721
759
  const out = try allocator.alloc(ServicePackageMetadata, packages.len);
@@ -2434,8 +2472,28 @@ fn validatePathSegment(segment: []const u8) !void {
2434
2472
  }
2435
2473
 
2436
2474
  fn parseVersionNumber(value: []const u8) !u32 {
2437
- if (value.len == 0) return error.InvalidVersion;
2438
- return std.fmt.parseUnsigned(u32, value, 10);
2475
+ if (value.len == 0 or (value.len > 1 and value[0] == '0')) return error.InvalidVersion;
2476
+ return std.fmt.parseUnsigned(u32, value, 10) catch error.InvalidVersion;
2477
+ }
2478
+
2479
+ test "manifest versions use canonical numeric components" {
2480
+ try std.testing.expectEqual(@as(u32, 10), (try parseVersion("1.10.0")).minor);
2481
+ try std.testing.expectError(error.InvalidVersion, parseVersion("1.010.0"));
2482
+ try std.testing.expectError(error.InvalidVersion, parseVersion("01.0.0"));
2483
+ try std.testing.expectError(error.InvalidVersion, parseVersion("1.0.00"));
2484
+ }
2485
+
2486
+ test "manifest validation rejects leading-zero versions" {
2487
+ var tmp = std.testing.tmpDir(.{});
2488
+ defer tmp.cleanup();
2489
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "app.json", .data =
2490
+ \\{ "id": "com.example.version", "name": "version", "version": "1.010.0" }
2491
+ });
2492
+ const path = try std.fmt.allocPrint(std.testing.allocator, ".zig-cache/tmp/{s}/app.json", .{tmp.sub_path});
2493
+ defer std.testing.allocator.free(path);
2494
+ const result = try validateFile(std.testing.allocator, std.testing.io, path);
2495
+ try std.testing.expect(!result.ok);
2496
+ try std.testing.expectEqualStrings("app manifest version is invalid", result.message);
2439
2497
  }
2440
2498
 
2441
2499
  test "JSON manifest parser accepts schema metadata and rejects unknown fields" {
@@ -2462,6 +2520,25 @@ test "JSON manifest parser accepts schema metadata and rejects unknown fields" {
2462
2520
  ));
2463
2521
  }
2464
2522
 
2523
+ test "JSON manifest parser carries native update configuration" {
2524
+ const metadata = try parseJsonText(std.testing.allocator,
2525
+ \\{
2526
+ \\ "id": "com.example.updates",
2527
+ \\ "name": "updates",
2528
+ \\ "version": "1.2.3",
2529
+ \\ "updates": {
2530
+ \\ "feed_url": "https://example.com/native-update.json",
2531
+ \\ "public_key": "11qYAYKxCrfVS/7TyWQHOg7hcvPapiMlrwIaaPcHURo=",
2532
+ \\ "check_on_start": true
2533
+ \\ }
2534
+ \\}
2535
+ );
2536
+ defer metadata.deinit(std.testing.allocator);
2537
+ try std.testing.expect(metadata.updates.enabled());
2538
+ try std.testing.expect(metadata.updates.check_on_start);
2539
+ try std.testing.expectEqualStrings("https://example.com/native-update.json", metadata.updates.feed_url.?);
2540
+ }
2541
+
2465
2542
  test "JSON file validation rejects null with a teaching diagnostic regardless of extension case" {
2466
2543
  var cwd = std.Io.Dir.cwd();
2467
2544
  const root = ".zig-cache/test-validate-json-null";
@@ -54,7 +54,6 @@ pub const SigningConfig = struct {
54
54
  identity: ?[]const u8 = null,
55
55
  entitlements: ?[]const u8 = null,
56
56
  profile: ?[]const u8 = null,
57
- team_id: ?[]const u8 = null,
58
57
  };
59
58
 
60
59
  pub const PackageOptions = struct {
@@ -83,6 +82,13 @@ pub const PackageOptions = struct {
83
82
  cef_dir: []const u8 = web_engine_tool.default_cef_dir,
84
83
  signing: SigningConfig = .{},
85
84
  archive: bool = false,
85
+ /// Submit the final macOS distribution artifact to Apple's notary service,
86
+ /// then staple and validate its ticket. Requires identity signing and a
87
+ /// notarytool Keychain profile in `signing.profile`.
88
+ notarize: bool = false,
89
+ /// Emit the ZIP consumed by the native updater. macOS only; unlike the
90
+ /// user-facing DMG, this archive contains exactly the packaged .app.
91
+ update_archive: bool = false,
86
92
  /// The process environment, when the caller has one (the CLI). The
87
93
  /// Android artifact probes it for the SDK/NDK toolchain to assemble
88
94
  /// the debug APK; without it the generated project is still complete
@@ -149,10 +155,12 @@ pub const PackageStats = struct {
149
155
  /// the proof behind the report's "signed, verified" line. A package
150
156
  /// whose signing or verification fails never produces stats at all.
151
157
  signing_verified: bool = false,
158
+ notarized: bool = false,
152
159
  asset_count: usize = 0,
153
160
  web_engine: WebEngine = .system,
154
161
  web_layer: ?manifest_tool.WebLayer = null,
155
162
  archive_path: ?[]const u8 = null,
163
+ update_archive_path: ?[]const u8 = null,
156
164
  /// The Windows subsystem verdict: `console` when the package
157
165
  /// wrapped a CONSOLE-subsystem exe (the app will flash a terminal
158
166
  /// window behind itself on every launch), `gui` for a GUI-subsystem
@@ -217,6 +225,24 @@ pub fn createPackage(allocator: std.mem.Allocator, io: std.Io, options: PackageO
217
225
  return err;
218
226
  };
219
227
  try validateWebEngineTarget(options.target, options.web_engine);
228
+ if (options.notarize) {
229
+ if (options.target != .macos) {
230
+ std.debug.print("error: notarization is supported only for macOS packages\n", .{});
231
+ return error.UnsupportedNotarizationTarget;
232
+ }
233
+ if (options.signing.mode != .identity) {
234
+ std.debug.print("error: --notarize requires --signing identity and a Developer ID Application certificate\n", .{});
235
+ return error.NotarizationRequiresIdentity;
236
+ }
237
+ if (options.signing.profile == null) {
238
+ std.debug.print("error: --notarize requires --notary-profile <name>; create it with `xcrun notarytool store-credentials <name>`\n", .{});
239
+ return error.MissingNotaryProfile;
240
+ }
241
+ }
242
+ if (options.metadata.updates.enabled() and options.target == .macos and options.web_engine == .chromium) {
243
+ std.debug.print("error: native updates currently require the system macOS host; package with --web-engine system or remove the updates block\n", .{});
244
+ return error.UnsupportedUpdateHost;
245
+ }
220
246
  if (options.target == .macos and options.archive) {
221
247
  manifest_tool.validateDmgPackageSettings(options.metadata) catch |err| {
222
248
  std.debug.print("error: app.zon dmg settings are invalid ({s})\n", .{@errorName(err)});
@@ -233,12 +259,29 @@ pub fn createPackage(allocator: std.mem.Allocator, io: std.Io, options: PackageO
233
259
  .ios => try createIosArtifact(allocator, io, options),
234
260
  .android => try createAndroidArtifact(allocator, io, options),
235
261
  };
262
+ if (options.notarize) {
263
+ try runNotarization(allocator, io, options.output_path, options.signing.profile.?, true);
264
+ }
236
265
  if (options.archive) {
237
266
  const archive_path = try createArchive(allocator, io, options);
238
267
  if (archive_path) |path| {
239
268
  stats.archive_path = path;
269
+ if (options.target == .macos and options.signing.mode == .identity) {
270
+ try signDistributionArtifact(allocator, io, path, options.signing.identity.?);
271
+ }
272
+ if (options.notarize) {
273
+ try runNotarization(allocator, io, path, options.signing.profile.?, false);
274
+ }
240
275
  }
241
276
  }
277
+ if (options.notarize) {
278
+ stats.notarized = true;
279
+ }
280
+ if (options.update_archive) {
281
+ if (options.target != .macos) return error.UnsupportedUpdateTarget;
282
+ if (!options.metadata.updates.enabled()) return error.UpdatesNotConfigured;
283
+ stats.update_archive_path = try createUpdateArchive(allocator, io, options);
284
+ }
242
285
  return stats;
243
286
  }
244
287
 
@@ -273,6 +316,9 @@ pub fn printDiagnostic(stats: PackageStats) void {
273
316
  if (stats.signing_verified) {
274
317
  std.debug.print(" signing: {s} (signed, verified)\n", .{@tagName(stats.signing_mode)});
275
318
  }
319
+ if (stats.notarized) {
320
+ std.debug.print(" notarization: accepted, stapled, validated\n", .{});
321
+ }
276
322
  if (stats.windows_subsystem) |subsystem| {
277
323
  switch (subsystem) {
278
324
  .console => std.debug.print(" subsystem: console (a terminal window opens behind the app - rebuild with `native build`)\n", .{}),
@@ -283,6 +329,26 @@ pub fn printDiagnostic(stats: PackageStats) void {
283
329
  if (stats.archive_path) |archive| {
284
330
  std.debug.print(" archive: {s}\n", .{archive});
285
331
  }
332
+ if (stats.update_archive_path) |archive| {
333
+ std.debug.print(" update archive: {s}\n", .{archive});
334
+ }
335
+ }
336
+
337
+ fn createUpdateArchive(allocator: std.mem.Allocator, io: std.Io, options: PackageOptions) ![]const u8 {
338
+ const parent = std.fs.path.dirname(options.output_path) orelse ".";
339
+ const archive_name = try std.fmt.allocPrint(allocator, "{s}-{s}-macos-{s}-update.zip", .{ options.metadata.name, options.metadata.version, options.optimize });
340
+ defer allocator.free(archive_name);
341
+ const archive_path = try std.fs.path.join(allocator, &.{ parent, archive_name });
342
+ errdefer allocator.free(archive_path);
343
+ const app_path = try absolutePathAlloc(allocator, io, options.output_path);
344
+ defer allocator.free(app_path);
345
+ const archive_command_path = try absolutePathAlloc(allocator, io, archive_path);
346
+ defer allocator.free(archive_command_path);
347
+ if (!runArchiveCommand(io, &.{ "/usr/bin/ditto", "-c", "-k", "--sequesterRsrc", "--keepParent", app_path, archive_command_path }, null)) {
348
+ std.debug.print("error: update archive creation failed for {s}\n", .{archive_path});
349
+ return error.UpdateArchiveFailed;
350
+ }
351
+ return archive_path;
286
352
  }
287
353
 
288
354
  pub fn createLocalPackage(io: std.Io, output_path: []const u8) !PackageStats {
@@ -1688,6 +1754,33 @@ fn runSigning(allocator: std.mem.Allocator, io: std.Io, dir: std.Io.Dir, options
1688
1754
  return true;
1689
1755
  }
1690
1756
 
1757
+ fn signDistributionArtifact(allocator: std.mem.Allocator, io: std.Io, path: []const u8, identity: []const u8) !void {
1758
+ const signed = try codesign.signIdentityArtifact(allocator, io, path, identity);
1759
+ defer allocator.free(signed.message);
1760
+ if (!signed.ok) {
1761
+ std.debug.print("error: code signing distribution artifact {s} with \"{s}\" failed:\n{s}\n", .{ path, identity, trimmedToolOutput(signed.message) });
1762
+ return error.SigningFailed;
1763
+ }
1764
+ const verified = try codesign.verifyArtifact(allocator, io, path);
1765
+ defer allocator.free(verified.message);
1766
+ if (!verified.ok) {
1767
+ std.debug.print("error: signed distribution artifact {s} failed strict codesign verification:\n{s}\n", .{ path, trimmedToolOutput(verified.message) });
1768
+ return error.SignatureVerificationFailed;
1769
+ }
1770
+ }
1771
+
1772
+ fn runNotarization(allocator: std.mem.Allocator, io: std.Io, path: []const u8, profile: []const u8, app_bundle: bool) !void {
1773
+ const result = if (app_bundle)
1774
+ try codesign.notarizeApp(allocator, io, .{ .artifact_path = path, .keychain_profile = profile })
1775
+ else
1776
+ try codesign.notarizeArtifact(allocator, io, .{ .artifact_path = path, .keychain_profile = profile }, null);
1777
+ defer allocator.free(result.message);
1778
+ if (!result.ok) {
1779
+ std.debug.print("error: notarization failed for {s}:\n{s}\n", .{ path, trimmedToolOutput(result.message) });
1780
+ return error.NotarizationFailed;
1781
+ }
1782
+ }
1783
+
1691
1784
  /// codesign's output, trimmed of trailing newlines so the teaching
1692
1785
  /// message's fix line lands directly under it (the output itself stays
1693
1786
  /// verbatim).
@@ -3597,6 +3690,30 @@ test "identity signing without an identity is a loud failure, not a silent unsig
3597
3690
  }));
3598
3691
  }
3599
3692
 
3693
+ test "notarization refuses unsigned non-macos and uncredentialed packages before artifact creation" {
3694
+ const metadata: manifest_tool.Metadata = .{ .id = "dev.example.notarize", .name = "notarize-demo", .version = "1.0.0" };
3695
+ try std.testing.expectError(error.NotarizationRequiresIdentity, createPackage(std.testing.allocator, std.testing.io, .{
3696
+ .metadata = metadata,
3697
+ .target = .macos,
3698
+ .output_path = ".zig-cache/test-notarize-unsigned.app",
3699
+ .notarize = true,
3700
+ }));
3701
+ try std.testing.expectError(error.UnsupportedNotarizationTarget, createPackage(std.testing.allocator, std.testing.io, .{
3702
+ .metadata = metadata,
3703
+ .target = .linux,
3704
+ .output_path = ".zig-cache/test-notarize-linux",
3705
+ .signing = .{ .mode = .identity, .identity = "Developer ID Application: Test" },
3706
+ .notarize = true,
3707
+ }));
3708
+ try std.testing.expectError(error.MissingNotaryProfile, createPackage(std.testing.allocator, std.testing.io, .{
3709
+ .metadata = metadata,
3710
+ .target = .macos,
3711
+ .output_path = ".zig-cache/test-notarize-no-profile.app",
3712
+ .signing = .{ .mode = .identity, .identity = "Developer ID Application: Test" },
3713
+ .notarize = true,
3714
+ }));
3715
+ }
3716
+
3600
3717
  test "native-only windows package ships no WebView2 loader and reports web layer none" {
3601
3718
  var cwd = std.Io.Dir.cwd();
3602
3719
  const root = ".zig-cache/test-package-native-only-windows";
@@ -48,9 +48,16 @@ pub const RawManifest = struct {
48
48
  shortcuts: []const RawShortcut = &.{},
49
49
  file_associations: []const RawFileAssociation = &.{},
50
50
  url_schemes: []const RawUrlScheme = &.{},
51
+ updates: RawUpdates = .{},
51
52
  dmg: RawDmg = .{},
52
53
  };
53
54
 
55
+ pub const RawUpdates = struct {
56
+ feed_url: ?[]const u8 = null,
57
+ public_key: ?[]const u8 = null,
58
+ check_on_start: bool = false,
59
+ };
60
+
54
61
  pub const RawImages = struct {
55
62
  max_image_pixel_bytes: usize = 1024 * 1024,
56
63
  };
@@ -20,6 +20,7 @@ pub const ios = @import("ios.zig");
20
20
  pub const android = @import("android.zig");
21
21
  pub const xcodeproj = @import("xcodeproj.zig");
22
22
  pub const db = @import("db.zig");
23
+ pub const update = @import("update.zig");
23
24
 
24
25
  test {
25
26
  @import("std").testing.refAllDecls(@This());