@native-sdk/cli 0.9.0 → 0.9.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 +331 -24
- package/build.zig +179 -11
- package/native-sdk.d.ts +8 -0
- package/package.json +10 -10
- package/packages/core/compile-surface/core.ts +70 -1
- package/packages/core/package-lock.json +11 -11
- package/packages/core/package.json +2 -2
- package/packages/core/scripts/merge_static_archives.mjs +78 -0
- package/packages/core/scripts/run_external_core_compiler.mjs +52 -7
- package/packages/core/scripts/run_external_service_compiler.mjs +53 -13
- package/packages/core/scripts/stage_external_services.mjs +1 -1
- package/packages/core/sdk/core.d.ts +75 -0
- package/packages/core/sdk/core.ts +167 -12
- package/packages/core/sdk/events.d.ts +53 -0
- package/packages/core/sdk/events.ts +78 -7
- package/packages/core/src/checker.ts +470 -2
- package/packages/core/src/cli.ts +13 -0
- package/packages/core/src/contract.ts +3 -1
- package/packages/core/src/devhost.ts +30 -1
- package/packages/core/src/devhost_journal.mjs +10 -8
- package/packages/core/src/diagnostics.ts +99 -8
- package/packages/core/src/frontend.ts +6 -0
- package/packages/core/src/infer.ts +24 -0
- package/skill-data/automation/SKILL.md +1 -1
- package/skill-data/native-ui/SKILL.md +11 -5
- package/skill-data/ts-core/SKILL.md +53 -20
- package/skill-data/ts-services/SKILL.md +4 -4
- package/skill-data/ts-services/references/service-surface.md +2 -1
- package/skill-data/zig/SKILL.md +1 -1
- package/src/app_runner/root.zig +29 -0
- package/src/app_runner/ts_core_main.zig +5 -0
- package/src/app_runner/ts_core_mobile.zig +241 -0
- package/src/automation/protocol.zig +5 -1
- package/src/automation/snapshot.zig +8 -6
- package/src/embed/app_exports.zig +1 -0
- package/src/embed/root.zig +1 -0
- package/src/embed/tests.zig +28 -0
- package/src/embed/ui_host.zig +68 -2
- package/src/platform/linux/cef_host.cpp +7 -1
- package/src/platform/linux/gtk_host.c +200 -5
- package/src/platform/linux/gtk_host.h +2 -1
- package/src/platform/linux/root.zig +69 -4
- package/src/platform/macos/appkit_host.h +11 -7
- package/src/platform/macos/appkit_host.m +210 -88
- package/src/platform/macos/cef_host.mm +210 -88
- package/src/platform/macos/root.zig +77 -30
- package/src/platform/null_platform.zig +234 -51
- package/src/platform/null_platform_tests.zig +39 -0
- package/src/platform/root.zig +10 -0
- package/src/platform/types.zig +105 -16
- package/src/platform/windows/root.zig +20 -6
- package/src/platform/windows/webview2_host.cpp +41 -5
- package/src/root.zig +7 -0
- package/src/runtime/api.zig +8 -0
- package/src/runtime/automation_commands.zig +35 -2
- package/src/runtime/automation_snapshot.zig +32 -24
- package/src/runtime/bridge_permission_tests.zig +35 -1
- package/src/runtime/bridge_responses.zig +1 -1
- package/src/runtime/builtin_bridge.zig +11 -1
- package/src/runtime/core.zig +12 -6
- package/src/runtime/effects.zig +1323 -35
- package/src/runtime/effects_file_tests.zig +587 -0
- package/src/runtime/effects_notification_tests.zig +11 -0
- package/src/runtime/file_access.zig +400 -0
- package/src/runtime/file_effect_crash_helper.zig +28 -0
- package/src/runtime/file_effect_crash_tests.zig +37 -0
- package/src/runtime/flow.zig +21 -9
- package/src/runtime/native_command_event_tests.zig +44 -2
- package/src/runtime/pty.zig +5 -2
- package/src/runtime/root.zig +5 -0
- package/src/runtime/session_blobs.zig +4 -1
- package/src/runtime/session_journal.zig +56 -5
- package/src/runtime/session_record.zig +38 -0
- package/src/runtime/session_replay.zig +97 -7
- package/src/runtime/session_tests.zig +81 -0
- package/src/runtime/state.zig +10 -0
- package/src/runtime/system_services.zig +129 -36
- package/src/runtime/ts_core_host.zig +281 -11
- package/src/runtime/ts_core_host_tests.zig +95 -1
- package/src/runtime/ts_ui_app.zig +461 -8
- package/src/runtime/ui_app.zig +321 -109
- package/src/runtime/ui_app_tests.zig +132 -6
- package/src/runtime/ui_app_window_tests.zig +61 -7
- package/src/runtime/validation.zig +20 -0
- package/src/tooling/templates.zig +28 -0
- package/src/tooling/ts_core.zig +83 -0
- package/tools/corewire/emit.zig +3 -3
- package/tools/corewire/emit_facade.zig +65 -5
- package/tools/corewire/emit_profile.zig +2 -2
- package/tools/corewire/emit_service.zig +2 -2
- package/tools/corewire/service_contract.zig +4 -4
- package/tools/corewire/sidecar.zig +4 -4
package/build/app.zig
CHANGED
|
@@ -75,6 +75,156 @@ fn appFileExists(b: *std.Build, app_root: []const u8, sub_path: []const u8) bool
|
|
|
75
75
|
return true;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
const TsWindowView = struct {
|
|
79
|
+
label: []const u8,
|
|
80
|
+
source_path: []const u8,
|
|
81
|
+
staged_path: []const u8,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const TsWindowSource = struct {
|
|
85
|
+
set_path: []const u8,
|
|
86
|
+
source_path: []const u8,
|
|
87
|
+
staged_path: []const u8,
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const TsWindowViews = struct {
|
|
91
|
+
views: []const TsWindowView,
|
|
92
|
+
sources: []const TsWindowSource,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/// Default TypeScript secondary-window views are statically discovered under
|
|
96
|
+
/// `src/windows/`: `settings.native` serves descriptor label `settings`.
|
|
97
|
+
/// Direct files form the generated launcher's closed, comptime-compiled view
|
|
98
|
+
/// set while nested `.native` files are the shared import source set and
|
|
99
|
+
/// `windows(model)` owns dynamic liveness.
|
|
100
|
+
fn collectTsWindowViews(b: *std.Build, app_root: []const u8) TsWindowViews {
|
|
101
|
+
const windows_path = appPath(b, app_root, "src/windows");
|
|
102
|
+
var dir = b.build_root.handle.openDir(b.graph.io, windows_path, .{ .iterate = true }) catch return .{ .views = &.{}, .sources = &.{} };
|
|
103
|
+
defer dir.close(b.graph.io);
|
|
104
|
+
var walker = dir.walk(b.allocator) catch return .{ .views = &.{}, .sources = &.{} };
|
|
105
|
+
defer walker.deinit();
|
|
106
|
+
var views: std.ArrayList(TsWindowView) = .empty;
|
|
107
|
+
var sources: std.ArrayList(TsWindowSource) = .empty;
|
|
108
|
+
while (walker.next(b.graph.io) catch null) |entry| {
|
|
109
|
+
if (entry.kind != .file or !std.mem.endsWith(u8, entry.path, ".native")) continue;
|
|
110
|
+
const normalized_path = b.dupe(entry.path);
|
|
111
|
+
for (normalized_path) |*char| {
|
|
112
|
+
if (char.* == '\\') char.* = '/';
|
|
113
|
+
}
|
|
114
|
+
sources.append(b.allocator, .{
|
|
115
|
+
.set_path = normalized_path,
|
|
116
|
+
.source_path = b.fmt("src/windows/{s}", .{normalized_path}),
|
|
117
|
+
.staged_path = b.fmt("windows/{s}", .{normalized_path}),
|
|
118
|
+
}) catch @panic("OOM");
|
|
119
|
+
// Direct children are label-addressed window roots. Nested files
|
|
120
|
+
// are component sources those roots may import transitively.
|
|
121
|
+
if (std.mem.indexOfScalar(u8, entry.path, '/') != null or std.mem.indexOfScalar(u8, entry.path, '\\') != null) continue;
|
|
122
|
+
const label = entry.path[0 .. entry.path.len - ".native".len];
|
|
123
|
+
if (label.len == 0 or label.len > 64 or std.mem.eql(u8, label, ".") or std.mem.eql(u8, label, "..")) {
|
|
124
|
+
@panic("\ninvalid TypeScript secondary-window view filename: use src/windows/<label>.native with a non-empty label of at most 64 bytes\n");
|
|
125
|
+
}
|
|
126
|
+
for (label) |ch| {
|
|
127
|
+
if (ch == 0 or ch == '/' or ch == '\\') {
|
|
128
|
+
@panic("\ninvalid TypeScript secondary-window view filename: the filename stem must be a valid window label\n");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
views.append(b.allocator, .{
|
|
132
|
+
.label = b.dupe(label),
|
|
133
|
+
.source_path = b.fmt("src/windows/{s}", .{entry.path}),
|
|
134
|
+
.staged_path = b.fmt("windows/{s}", .{entry.path}),
|
|
135
|
+
}) catch @panic("OOM");
|
|
136
|
+
}
|
|
137
|
+
const less = struct {
|
|
138
|
+
fn than(_: void, a: TsWindowView, z: TsWindowView) bool {
|
|
139
|
+
return std.mem.order(u8, a.label, z.label) == .lt;
|
|
140
|
+
}
|
|
141
|
+
}.than;
|
|
142
|
+
std.mem.sort(TsWindowView, views.items, {}, less);
|
|
143
|
+
const source_less = struct {
|
|
144
|
+
fn than(_: void, a: TsWindowSource, z: TsWindowSource) bool {
|
|
145
|
+
return std.mem.order(u8, a.set_path, z.set_path) == .lt;
|
|
146
|
+
}
|
|
147
|
+
}.than;
|
|
148
|
+
std.mem.sort(TsWindowSource, sources.items, {}, source_less);
|
|
149
|
+
return .{ .views = views.items, .sources = sources.items };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
fn tsWindowRegistrySource(b: *std.Build, registry: TsWindowViews) []const u8 {
|
|
153
|
+
const views = registry.views;
|
|
154
|
+
var out: std.ArrayList(u8) = .empty;
|
|
155
|
+
out.appendSlice(b.allocator,
|
|
156
|
+
\\//! Generated by build/app.zig from src/windows/<label>.native.
|
|
157
|
+
\\const std = @import("std");
|
|
158
|
+
\\const native_sdk = @import("native_sdk");
|
|
159
|
+
\\const core = @import("core.zig");
|
|
160
|
+
\\const canvas = native_sdk.canvas;
|
|
161
|
+
\\const Adapter = native_sdk.TsUiApp(core);
|
|
162
|
+
\\const App = Adapter.App;
|
|
163
|
+
\\
|
|
164
|
+
) catch @panic("OOM");
|
|
165
|
+
if (registry.sources.len > 0) {
|
|
166
|
+
out.appendSlice(b.allocator,
|
|
167
|
+
\\const window_sources = [_]canvas.ui_markup.SourceFile{
|
|
168
|
+
\\
|
|
169
|
+
) catch @panic("OOM");
|
|
170
|
+
for (registry.sources) |source| {
|
|
171
|
+
const line = std.fmt.allocPrint(
|
|
172
|
+
b.allocator,
|
|
173
|
+
" .{{ .path = \"{f}\", .source = @embedFile(\"{f}\") }},\n",
|
|
174
|
+
.{ std.zig.fmtString(source.set_path), std.zig.fmtString(source.staged_path) },
|
|
175
|
+
) catch @panic("OOM");
|
|
176
|
+
out.appendSlice(b.allocator, line) catch @panic("OOM");
|
|
177
|
+
}
|
|
178
|
+
out.appendSlice(b.allocator, "};\n") catch @panic("OOM");
|
|
179
|
+
}
|
|
180
|
+
for (views, 0..) |view, index| {
|
|
181
|
+
const line = std.fmt.allocPrint(
|
|
182
|
+
b.allocator,
|
|
183
|
+
"const WindowView{d} = canvas.CompiledMarkupImports(core.Model, core.Msg, \"{f}\", &window_sources);\n",
|
|
184
|
+
.{ index, std.zig.fmtString(std.fs.path.basename(view.staged_path)) },
|
|
185
|
+
) catch @panic("OOM");
|
|
186
|
+
out.appendSlice(b.allocator, line) catch @panic("OOM");
|
|
187
|
+
}
|
|
188
|
+
if (views.len == 0) {
|
|
189
|
+
out.appendSlice(b.allocator,
|
|
190
|
+
\\pub fn build(_: *App.Ui, _: *const core.Model, _: []const u8) App.Ui.Node {
|
|
191
|
+
\\ @compileError("this TypeScript core exports windows(model), but the app has no src/windows/<label>.native views");
|
|
192
|
+
\\}
|
|
193
|
+
\\pub const fragments = [_]canvas.MarkupFragment{};
|
|
194
|
+
\\
|
|
195
|
+
) catch @panic("OOM");
|
|
196
|
+
return out.items;
|
|
197
|
+
}
|
|
198
|
+
out.appendSlice(b.allocator,
|
|
199
|
+
\\pub fn build(ui: *App.Ui, model: *const core.Model, label: []const u8) App.Ui.Node {
|
|
200
|
+
\\
|
|
201
|
+
) catch @panic("OOM");
|
|
202
|
+
for (views, 0..) |view, index| {
|
|
203
|
+
const line = std.fmt.allocPrint(
|
|
204
|
+
b.allocator,
|
|
205
|
+
" if (std.mem.eql(u8, label, \"{f}\")) return WindowView{d}.build(ui, model);\n",
|
|
206
|
+
.{ std.zig.fmtString(view.label), index },
|
|
207
|
+
) catch @panic("OOM");
|
|
208
|
+
out.appendSlice(b.allocator, line) catch @panic("OOM");
|
|
209
|
+
}
|
|
210
|
+
out.appendSlice(b.allocator,
|
|
211
|
+
\\ @panic("windows(model) declared a label with no src/windows/<label>.native view");
|
|
212
|
+
\\}
|
|
213
|
+
\\pub const fragments = [_]canvas.MarkupFragment{
|
|
214
|
+
\\
|
|
215
|
+
) catch @panic("OOM");
|
|
216
|
+
for (views, 0..) |view, index| {
|
|
217
|
+
const line = std.fmt.allocPrint(
|
|
218
|
+
b.allocator,
|
|
219
|
+
" WindowView{d}.fragment(\"{f}\"),\n",
|
|
220
|
+
.{ index, std.zig.fmtString(view.source_path) },
|
|
221
|
+
) catch @panic("OOM");
|
|
222
|
+
out.appendSlice(b.allocator, line) catch @panic("OOM");
|
|
223
|
+
}
|
|
224
|
+
out.appendSlice(b.allocator, "};\n") catch @panic("OOM");
|
|
225
|
+
return out.items;
|
|
226
|
+
}
|
|
227
|
+
|
|
78
228
|
/// How a TypeScript core compiles: through the external core compiler,
|
|
79
229
|
/// always. The frontend checks the core and emits its contract sidecar,
|
|
80
230
|
/// corewire projects the compile entry and profile, the exact-pinned
|
|
@@ -96,6 +246,10 @@ const core_compiler_teaching =
|
|
|
96
246
|
/// and test modules.
|
|
97
247
|
const TsCoreStage = struct {
|
|
98
248
|
main_root: std.Build.LazyPath,
|
|
249
|
+
/// The staged mobile wiring (ts_core_mobile.zig beside the same
|
|
250
|
+
/// mirror/markup/registry files): the embed static library's `app`
|
|
251
|
+
/// module roots here on iOS/Android targets.
|
|
252
|
+
mobile_root: std.Build.LazyPath,
|
|
99
253
|
/// The compiled-core archive: the app module links it (with libc,
|
|
100
254
|
/// for the toolchain's runtime) beside the staged mirror.
|
|
101
255
|
archive: std.Build.LazyPath,
|
|
@@ -125,7 +279,11 @@ const ServiceCarrier = enum { none, child, in_process };
|
|
|
125
279
|
/// this host/target pairing. Native desktop targets use their host toolchain,
|
|
126
280
|
/// including native Windows/MSVC. Cross-Windows builds use Zig's bundled GNU
|
|
127
281
|
/// sysroot; an MSVC cross target has no CRT headers or libraries to compile
|
|
128
|
-
/// the ScriptC runtime against.
|
|
282
|
+
/// the ScriptC runtime against. Mobile targets are aarch64 only and
|
|
283
|
+
/// archive-only (library mode — the app links the archive; no standalone
|
|
284
|
+
/// executable exists there): iOS device/simulator archives build on a macOS
|
|
285
|
+
/// host against the selected Apple SDK, Android archives build on any
|
|
286
|
+
/// desktop host against a discovered NDK sysroot.
|
|
129
287
|
pub fn scriptcCompileSupported(host: std.Target, target: std.Build.ResolvedTarget) bool {
|
|
130
288
|
const desktop_host = switch (host.os.tag) {
|
|
131
289
|
.macos, .linux, .windows => true,
|
|
@@ -134,9 +292,10 @@ pub fn scriptcCompileSupported(host: std.Target, target: std.Build.ResolvedTarge
|
|
|
134
292
|
if (!desktop_host) return false;
|
|
135
293
|
const cross = scriptcTargetIsCross(host, target);
|
|
136
294
|
return switch (target.result.os.tag) {
|
|
137
|
-
.linux => true,
|
|
295
|
+
.linux => if (target.result.abi.isAndroid()) target.result.cpu.arch == .aarch64 else true,
|
|
138
296
|
.windows => !cross or target.result.abi == .gnu,
|
|
139
297
|
.macos => host.os.tag == .macos,
|
|
298
|
+
.ios => host.os.tag == .macos and target.result.cpu.arch == .aarch64,
|
|
140
299
|
else => false,
|
|
141
300
|
};
|
|
142
301
|
}
|
|
@@ -144,16 +303,18 @@ pub fn scriptcCompileSupported(host: std.Target, target: std.Build.ResolvedTarge
|
|
|
144
303
|
/// Whether the pinned service compiler can build the in-process carrier's
|
|
145
304
|
/// archive (runtime-localized, thread-instanced) on this build host for
|
|
146
305
|
/// this target. Its object localizers are deliberately architecture-aware:
|
|
147
|
-
/// native Linux uses host binutils, cross-ELF accepts x86_64/aarch64
|
|
148
|
-
///
|
|
149
|
-
///
|
|
306
|
+
/// native Linux uses host binutils, cross-ELF accepts x86_64/aarch64
|
|
307
|
+
/// (Android's aarch64 archives ride this lane), COFF accepts x86_64 (GNU
|
|
308
|
+
/// when cross-compiled; the host ABI when native), and Mach-O — macOS, iOS
|
|
309
|
+
/// device, and iOS simulator — needs a macOS host (Apple linking rides the
|
|
310
|
+
/// host toolchain's SDK).
|
|
150
311
|
pub fn serviceArchiveSupported(host: std.Target, target: std.Build.ResolvedTarget) bool {
|
|
151
312
|
if (!scriptcCompileSupported(host, target)) return false;
|
|
152
313
|
const cross = scriptcTargetIsCross(host, target);
|
|
153
314
|
return switch (target.result.os.tag) {
|
|
154
315
|
.linux => !cross or target.result.cpu.arch == .x86_64 or target.result.cpu.arch == .aarch64,
|
|
155
316
|
.windows => target.result.cpu.arch == .x86_64,
|
|
156
|
-
.macos => host.os.tag == .macos,
|
|
317
|
+
.macos, .ios => host.os.tag == .macos,
|
|
157
318
|
else => false,
|
|
158
319
|
};
|
|
159
320
|
}
|
|
@@ -216,9 +377,16 @@ pub fn panicUnsupportedScriptcTarget(b: *std.Build, host: std.Target, target: st
|
|
|
216
377
|
.{ target.result.cpu.arch, target.result.cpu.arch },
|
|
217
378
|
));
|
|
218
379
|
}
|
|
380
|
+
if (target.result.os.tag == .ios and host.os.tag != .macos) {
|
|
381
|
+
@panic(
|
|
382
|
+
"\nTypeScript iOS builds run on a macOS build host only: the Apple SDK sysroot" ++
|
|
383
|
+
" and Mach-O symbol localization live there.\nBuild iOS apps on a Mac.\n",
|
|
384
|
+
);
|
|
385
|
+
}
|
|
219
386
|
@panic(
|
|
220
|
-
"\nTypeScript
|
|
221
|
-
"
|
|
387
|
+
"\nTypeScript builds support native host targets, Linux and Windows GNU cross" ++
|
|
388
|
+
" targets from macOS/Linux/Windows, macOS targets from macOS, and the mobile" ++
|
|
389
|
+
" targets aarch64 iOS/iOS-simulator (from macOS) and aarch64 Android." ++
|
|
222
390
|
"\nChoose a supported target/host pairing.\n",
|
|
223
391
|
);
|
|
224
392
|
}
|
|
@@ -232,13 +400,27 @@ fn resolveServiceCarrier(
|
|
|
232
400
|
if (!has_services) return .none;
|
|
233
401
|
const host = b.graph.host.result;
|
|
234
402
|
const supported = serviceArchiveSupported(host, target);
|
|
403
|
+
// Mobile has no child processes, so the in-process pool is the only
|
|
404
|
+
// carrier there: auto resolves to it, and an explicit "child" is a
|
|
405
|
+
// stated impossibility, taught rather than quietly rewritten.
|
|
406
|
+
if (target.result.os.tag == .ios or target.result.abi.isAndroid()) {
|
|
407
|
+
return switch (choice) {
|
|
408
|
+
.auto, .in_process => if (supported) .in_process else panicUnsupportedScriptcTarget(b, host, target),
|
|
409
|
+
.child => @panic(
|
|
410
|
+
"\nservice_carrier = \"child\" is unavailable on mobile targets: iOS and Android" ++
|
|
411
|
+
" apps cannot spawn a sibling service process, so src/services operations run" ++
|
|
412
|
+
" on the in-process pool there.\nUse \"auto\" or \"in_process\" (desktop" ++
|
|
413
|
+
" builds of the same app keep the child carrier under auto).\n",
|
|
414
|
+
),
|
|
415
|
+
};
|
|
416
|
+
}
|
|
235
417
|
const carrier: ServiceCarrier = switch (choice) {
|
|
236
418
|
.auto, .child => .child,
|
|
237
419
|
.in_process => if (supported) .in_process else @panic(
|
|
238
420
|
"\nservice_carrier = \"in_process\" requires a target the pinned service compiler" ++
|
|
239
421
|
" can produce a runtime-localized archive for: native Linux, cross-Linux" ++
|
|
240
422
|
" x86_64/aarch64, native Windows x86_64, cross-Windows x86_64 GNU," ++
|
|
241
|
-
"
|
|
423
|
+
" macOS from a macOS build host, or a mobile target." ++
|
|
242
424
|
"\nUse \"child\" (or drop the setting — auto selects the child carrier)" ++
|
|
243
425
|
" for this target.\n",
|
|
244
426
|
),
|
|
@@ -574,6 +756,7 @@ fn tsCoreStage(
|
|
|
574
756
|
service_pool_workers: ?u8,
|
|
575
757
|
) TsCoreStage {
|
|
576
758
|
const node = tsCorePreflight(b, dep, app_root);
|
|
759
|
+
const window_views = collectTsWindowViews(b, app_root);
|
|
577
760
|
const has_services = appHasServiceFiles(b, app_root);
|
|
578
761
|
if (!scriptcCompileSupported(b.graph.host.result, target)) {
|
|
579
762
|
panicUnsupportedScriptcTarget(b, b.graph.host.result, target);
|
|
@@ -659,6 +842,10 @@ fn tsCoreStage(
|
|
|
659
842
|
if (relational_capability) check.addArgs(&.{ "--capability", "sqlite" });
|
|
660
843
|
if (credentials_capability) check.addArgs(&.{ "--capability", "credentials" });
|
|
661
844
|
if (credentials_permission) check.addArgs(&.{ "--permission", "credentials" });
|
|
845
|
+
// Activate the cross-tier registry check even when discovery found no
|
|
846
|
+
// roots: the empty set must reject a core that declares a window.
|
|
847
|
+
check.addArg("--window-views");
|
|
848
|
+
for (window_views.views) |view| check.addArgs(&.{ "--window-view", view.label });
|
|
662
849
|
if (relational_capability) {
|
|
663
850
|
check.addArg("--sdk-core");
|
|
664
851
|
check.addFileArg(checked_sdk_core);
|
|
@@ -717,7 +904,7 @@ fn tsCoreStage(
|
|
|
717
904
|
|
|
718
905
|
// Ordinary service TypeScript is staged without core-subset rewrites.
|
|
719
906
|
// The one service-boundary lowering turns NS1067's `{ kind, message }`
|
|
720
|
-
// throw into the tagged Error shape
|
|
907
|
+
// throw into the tagged Error shape the pinned compiler can catch from an
|
|
721
908
|
// imported op; no deterministic profile fences participate here.
|
|
722
909
|
const service_stage_run = b.addSystemCommand(&.{node});
|
|
723
910
|
service_stage_run.addFileArg(dep.path("packages/core/scripts/stage_external_services.mjs"));
|
|
@@ -770,6 +957,7 @@ fn tsCoreStage(
|
|
|
770
957
|
"--zig-exe",
|
|
771
958
|
b.graph.zig_exe,
|
|
772
959
|
});
|
|
960
|
+
addScriptcAndroidNdk(b, service_compile, target);
|
|
773
961
|
if (b.graph.environ_map.get("NATIVE_SDK_CORE_COMPILER")) |override| {
|
|
774
962
|
service_compile.addArgs(&.{ "--compiler", override });
|
|
775
963
|
} else {
|
|
@@ -826,6 +1014,7 @@ fn tsCoreStage(
|
|
|
826
1014
|
"--zig-exe",
|
|
827
1015
|
b.graph.zig_exe,
|
|
828
1016
|
});
|
|
1017
|
+
addScriptcAndroidNdk(b, compile, target);
|
|
829
1018
|
if (b.graph.environ_map.get("NATIVE_SDK_CORE_COMPILER")) |override| {
|
|
830
1019
|
// The development override: point at any toolchain command; the
|
|
831
1020
|
// driver still refuses a release other than the SDK's pin.
|
|
@@ -863,9 +1052,18 @@ fn tsCoreStage(
|
|
|
863
1052
|
, .{ service_carrier, service_pool_workers }));
|
|
864
1053
|
_ = staged.addCopyFile(migrations_zig, "migrations.zig");
|
|
865
1054
|
_ = staged.addCopyFile(b.path(appPath(b, app_root, "src/app.native")), "app.native");
|
|
1055
|
+
for (window_views.sources) |source| {
|
|
1056
|
+
_ = staged.addCopyFile(b.path(appPath(b, app_root, source.source_path)), source.staged_path);
|
|
1057
|
+
}
|
|
1058
|
+
_ = staged.add("window_views.zig", tsWindowRegistrySource(b, window_views));
|
|
866
1059
|
const main_root = staged.addCopyFile(dep.path("src/app_runner/ts_core_main.zig"), "main.zig");
|
|
1060
|
+
// The mobile wiring stages beside the desktop entry: same mirror, same
|
|
1061
|
+
// registry, same carrier constant — only the shell differs (the embed
|
|
1062
|
+
// host's AppDef contract instead of a process `main`).
|
|
1063
|
+
const mobile_root = staged.addCopyFile(dep.path("src/app_runner/ts_core_mobile.zig"), "mobile.zig");
|
|
867
1064
|
return .{
|
|
868
1065
|
.main_root = main_root,
|
|
1066
|
+
.mobile_root = mobile_root,
|
|
869
1067
|
.archive = archive,
|
|
870
1068
|
.service_exe = service_exe,
|
|
871
1069
|
.service_archive = service_archive,
|
|
@@ -1052,8 +1250,30 @@ pub const MobileLibOptions = struct {
|
|
|
1052
1250
|
credentials_capability: bool = false,
|
|
1053
1251
|
/// Grant those effects access to the registered OS credential service.
|
|
1054
1252
|
credentials_permission: bool = false,
|
|
1253
|
+
/// Grant raw file effects access outside the OS-owned app data root.
|
|
1254
|
+
filesystem_permission: bool = false,
|
|
1055
1255
|
/// Stable app identity used as the Keychain/Keystore service namespace.
|
|
1056
1256
|
credentials_service: []const u8 = "dev.native_sdk.app",
|
|
1257
|
+
/// A TypeScript core's staged mobile wiring: set by `addAppArtifacts`
|
|
1258
|
+
/// when the tree carries src/core.ts. The `app` module roots at the
|
|
1259
|
+
/// staged mobile entry instead of `main`, and the compiled core (and
|
|
1260
|
+
/// in-process service) archives merge into the embed static library —
|
|
1261
|
+
/// the host tiers keep linking exactly one archive.
|
|
1262
|
+
ts_core: ?MobileTsCore = null,
|
|
1263
|
+
};
|
|
1264
|
+
|
|
1265
|
+
/// The TypeScript pieces a mobile embed library consumes (see
|
|
1266
|
+
/// `MobileLibOptions.ts_core`).
|
|
1267
|
+
pub const MobileTsCore = struct {
|
|
1268
|
+
/// The staged mobile wiring (mobile.zig beside the generated mirror).
|
|
1269
|
+
main_root: std.Build.LazyPath,
|
|
1270
|
+
/// The compiled-core archive; merged into the embed library.
|
|
1271
|
+
archive: std.Build.LazyPath,
|
|
1272
|
+
/// The in-process service archive, when src/services exists.
|
|
1273
|
+
service_archive: ?std.Build.LazyPath,
|
|
1274
|
+
/// The app.zon module the mobile wiring reads scene chrome, identity,
|
|
1275
|
+
/// and theme from (`app_manifest_zon`).
|
|
1276
|
+
manifest_mod: *std.Build.Module,
|
|
1057
1277
|
};
|
|
1058
1278
|
|
|
1059
1279
|
/// Mobile counterpart of `addApp`: produce the embed static library
|
|
@@ -1096,16 +1316,40 @@ fn addMobileLibWithTarget(b: *std.Build, dep: *std.Build.Dependency, target: std
|
|
|
1096
1316
|
mobile_options.addOption(bool, "relational_capability", options.relational_capability);
|
|
1097
1317
|
mobile_options.addOption(bool, "credentials_capability", options.credentials_capability);
|
|
1098
1318
|
mobile_options.addOption(bool, "credentials_permission", options.credentials_permission);
|
|
1319
|
+
mobile_options.addOption(bool, "filesystem_permission", options.filesystem_permission);
|
|
1099
1320
|
mobile_options.addOption([]const u8, "credentials_service", options.credentials_service);
|
|
1100
1321
|
exports_mod.addImport("mobile_build_options", mobile_options.createModule());
|
|
1101
1322
|
const migration_path = options.relational_migrations orelse dep.path("src/app_runner/no_migrations.zig");
|
|
1102
1323
|
const migration_mod = b.createModule(.{ .root_source_file = migration_path, .target = target, .optimize = optimize });
|
|
1103
1324
|
migration_mod.addImport("native_sdk", native_sdk_mod);
|
|
1104
1325
|
exports_mod.addImport("relational_migrations", migration_mod);
|
|
1105
|
-
|
|
1326
|
+
// A TypeScript core's app module roots at the staged mobile wiring;
|
|
1327
|
+
// a Zig core's at the app's own mobile entry. Either way the embed
|
|
1328
|
+
// host sees the same AppDef contract (Model/Msg/initModel/
|
|
1329
|
+
// mobileOptions).
|
|
1330
|
+
const app_mod = if (options.ts_core) |ts| ts_app: {
|
|
1331
|
+
const mod = b.createModule(.{
|
|
1332
|
+
.root_source_file = ts.main_root,
|
|
1333
|
+
.target = target,
|
|
1334
|
+
.optimize = optimize,
|
|
1335
|
+
});
|
|
1336
|
+
mod.addImport("app_manifest_zon", ts.manifest_mod);
|
|
1337
|
+
break :ts_app mod;
|
|
1338
|
+
} else localModule(b, target, optimize, options.main);
|
|
1106
1339
|
app_mod.addImport("native_sdk", native_sdk_mod);
|
|
1107
1340
|
exports_mod.addImport("app", app_mod);
|
|
1108
1341
|
}
|
|
1342
|
+
if (options.ts_core) |ts| {
|
|
1343
|
+
// The compiled TypeScript archives merge into the embed static
|
|
1344
|
+
// library (Zig's static-lib emission bundles archive inputs), so
|
|
1345
|
+
// the iOS/Android host tiers keep linking the one archive they
|
|
1346
|
+
// already stage. The toolchain's runtime needs libc; the host
|
|
1347
|
+
// link supplies it (plus -lm/-ldl on Android, which the Android
|
|
1348
|
+
// host link already passes).
|
|
1349
|
+
exports_mod.link_libc = true;
|
|
1350
|
+
exports_mod.addObjectFile(ts.archive);
|
|
1351
|
+
if (ts.service_archive) |service_archive| exports_mod.addObjectFile(service_archive);
|
|
1352
|
+
}
|
|
1109
1353
|
if (options.store_capability or options.relational_capability) {
|
|
1110
1354
|
exports_mod.addIncludePath(dep.path("third_party/sqlite"));
|
|
1111
1355
|
exports_mod.addCSourceFile(.{
|
|
@@ -1128,10 +1372,39 @@ fn addMobileLibWithTarget(b: *std.Build, dep: *std.Build.Dependency, target: std
|
|
|
1128
1372
|
// Intel simulators). Force LLVM there; Release already uses it.
|
|
1129
1373
|
.use_llvm = useLlvmWorkaround(target),
|
|
1130
1374
|
});
|
|
1131
|
-
b.installArtifact(lib);
|
|
1132
1375
|
|
|
1133
1376
|
const lib_step = b.step("lib", "Build the mobile embed static library");
|
|
1134
|
-
|
|
1377
|
+
if (options.ts_core != null and target.result.abi.isAndroid()) {
|
|
1378
|
+
// Zig's ELF static-library emission stores the compiled TypeScript
|
|
1379
|
+
// archives as nested members instead of merging their objects (the
|
|
1380
|
+
// Mach-O emission merges), and the NDK's -shared host link would
|
|
1381
|
+
// skip those blobs with only a warning. Flatten to one plain
|
|
1382
|
+
// object archive so the Android host tier keeps linking exactly
|
|
1383
|
+
// the archive it already stages.
|
|
1384
|
+
const merged = mergeMobileArchive(b, dep, lib, options.name);
|
|
1385
|
+
const lib_name = b.fmt("lib{s}.a", .{options.name});
|
|
1386
|
+
b.getInstallStep().dependOn(&b.addInstallFileWithDir(merged, .lib, lib_name).step);
|
|
1387
|
+
lib_step.dependOn(&b.addInstallFileWithDir(merged, .lib, lib_name).step);
|
|
1388
|
+
} else {
|
|
1389
|
+
b.installArtifact(lib);
|
|
1390
|
+
lib_step.dependOn(&b.addInstallArtifact(lib, .{}).step);
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
/// Flatten an Android embed library whose members include the compiled
|
|
1395
|
+
/// TypeScript archives (see the call site above). Runs under node like the
|
|
1396
|
+
/// rest of the TypeScript lane's drivers.
|
|
1397
|
+
fn mergeMobileArchive(b: *std.Build, dep: *std.Build.Dependency, lib: *std.Build.Step.Compile, name: []const u8) std.Build.LazyPath {
|
|
1398
|
+
const node = b.findProgram(&.{"node"}, &.{}) catch
|
|
1399
|
+
@panic("\nmerging the mobile TypeScript archives needs node on PATH (the TypeScript core lane already requires it).\n");
|
|
1400
|
+
const merge = b.addSystemCommand(&.{node});
|
|
1401
|
+
merge.addFileArg(dep.path("packages/core/scripts/merge_static_archives.mjs"));
|
|
1402
|
+
merge.addArgs(&.{ "--zig", b.graph.zig_exe, "--format", "gnu" });
|
|
1403
|
+
merge.addArg("--out");
|
|
1404
|
+
const merged = merge.addOutputFileArg(b.fmt("lib{s}.a", .{name}));
|
|
1405
|
+
merge.addArg("--in");
|
|
1406
|
+
merge.addFileArg(lib.getEmittedBin());
|
|
1407
|
+
return merged;
|
|
1135
1408
|
}
|
|
1136
1409
|
|
|
1137
1410
|
/// The pieces `addApp` wires, for callers that extend the standard app
|
|
@@ -1182,14 +1455,6 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
|
|
|
1182
1455
|
" a Zig core.\nDrop the flag or port the core to TypeScript.\n");
|
|
1183
1456
|
}
|
|
1184
1457
|
}
|
|
1185
|
-
// Mobile targets are taught BEFORE lane selection: TypeScript cores
|
|
1186
|
-
// are desktop-only until the external core toolchain grows mobile
|
|
1187
|
-
// targets; Zig/markup cores stay fully supported on mobile.
|
|
1188
|
-
if (core_tree == .ts and (target.result.os.tag == .ios or target.result.abi.isAndroid())) {
|
|
1189
|
-
@panic("\nTypeScript app cores are desktop-only today: the external core compiler does not" ++
|
|
1190
|
-
" target mobile yet.\nBuild for a desktop target, or port the core to a Zig" ++
|
|
1191
|
-
" `mobileOptions` app — Zig and markup cores are fully supported on mobile.\n");
|
|
1192
|
-
}
|
|
1193
1458
|
// The service-carrier selection: `-Dservice-carrier` overrides app.zon's
|
|
1194
1459
|
// `.service_carrier`; both default to auto (the child carrier).
|
|
1195
1460
|
const service_carrier_choice: ServiceCarrierOption = choice: {
|
|
@@ -1236,7 +1501,9 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
|
|
|
1236
1501
|
// artifact the toolkit-owned iOS host (and any hand-written shim)
|
|
1237
1502
|
// links, so `native dev|package --target ios` works against every
|
|
1238
1503
|
// standard app build — generated graph or ejected — with nothing but
|
|
1239
|
-
// `-Dtarget`. Desktop targets keep the step absent.
|
|
1504
|
+
// `-Dtarget`. Desktop targets keep the step absent. A TypeScript core
|
|
1505
|
+
// roots the library's app module at the staged mobile wiring and
|
|
1506
|
+
// merges the compiled archives into it.
|
|
1240
1507
|
if (target.result.os.tag == .ios or target.result.abi.isAndroid()) {
|
|
1241
1508
|
addMobileLibWithTarget(b, dep, target, optimize, .{
|
|
1242
1509
|
.name = app_options.name,
|
|
@@ -1246,7 +1513,14 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
|
|
|
1246
1513
|
.relational_migrations = relational_migrations,
|
|
1247
1514
|
.credentials_capability = app_config.credentials_capability,
|
|
1248
1515
|
.credentials_permission = app_config.credentials_permission,
|
|
1516
|
+
.filesystem_permission = app_config.filesystem_permission,
|
|
1249
1517
|
.credentials_service = app_config.app_id,
|
|
1518
|
+
.ts_core = if (ts_stage) |stage| .{
|
|
1519
|
+
.main_root = stage.mobile_root,
|
|
1520
|
+
.archive = stage.archive,
|
|
1521
|
+
.service_archive = stage.service_archive,
|
|
1522
|
+
.manifest_mod = b.createModule(.{ .root_source_file = b.path(appPath(b, app_options.app_root, "app.zon")) }),
|
|
1523
|
+
} else null,
|
|
1250
1524
|
});
|
|
1251
1525
|
}
|
|
1252
1526
|
const platform_option = b.option(PlatformOption, "platform", "Desktop backend: auto, null, macos, linux, windows") orelse .auto;
|
|
@@ -1636,8 +1910,10 @@ const sqlite_c_defines = [_][]const u8{
|
|
|
1636
1910
|
/// Zig deliberately supplies no libc headers for Apple/Android cross targets.
|
|
1637
1911
|
/// Store-capable mobile libraries therefore compile the vendored amalgamation
|
|
1638
1912
|
/// against the same platform SDK the host tier will use to link the archive.
|
|
1639
|
-
/// Desktop targets keep Zig's ordinary libc discovery.
|
|
1640
|
-
|
|
1913
|
+
/// Desktop targets keep Zig's ordinary libc discovery. Pub because the SDK's
|
|
1914
|
+
/// own build graph compiles the same amalgamation into modules that also
|
|
1915
|
+
/// configure under a mobile -Dtarget (the mobile e2e battery).
|
|
1916
|
+
pub fn sqliteCFlags(b: *std.Build, target: std.Build.ResolvedTarget) []const []const u8 {
|
|
1641
1917
|
if (target.result.os.tag == .ios) {
|
|
1642
1918
|
const sysroot = b.sysroot orelse iosSdkPath(b, target.result.abi == .simulator) orelse
|
|
1643
1919
|
std.debug.panic("a store-capable iOS library needs the Apple SDK; install Xcode or pass --sysroot <iphone SDK path>", .{});
|
|
@@ -1689,6 +1965,35 @@ fn iosSdkPath(b: *std.Build, simulator: bool) ?[]const u8 {
|
|
|
1689
1965
|
return std.mem.trimEnd(u8, result.stdout, "\r\n");
|
|
1690
1966
|
}
|
|
1691
1967
|
|
|
1968
|
+
/// Thread the Android NDK location into a ScriptC driver invocation the
|
|
1969
|
+
/// way `--zig-exe` threads this build's zig: resolved here, at the one
|
|
1970
|
+
/// boundary that already knows how to discover it, so the compiler's own
|
|
1971
|
+
/// discovery never depends on the ambient environment. A missing NDK stays
|
|
1972
|
+
/// quiet — the driver and compiler own the teaching when an Android
|
|
1973
|
+
/// compile actually needs one.
|
|
1974
|
+
pub fn addScriptcAndroidNdk(b: *std.Build, run: *std.Build.Step.Run, target: std.Build.ResolvedTarget) void {
|
|
1975
|
+
if (!target.result.abi.isAndroid()) return;
|
|
1976
|
+
const ndk_root = androidNdkRootPath(b) orelse return;
|
|
1977
|
+
run.addArgs(&.{ "--android-ndk", ndk_root });
|
|
1978
|
+
}
|
|
1979
|
+
|
|
1980
|
+
/// The NDK's root directory (the directory holding toolchains/llvm):
|
|
1981
|
+
/// ANDROID_NDK_ROOT/ANDROID_NDK_HOME wins, else the newest ndk/<version>
|
|
1982
|
+
/// under the platform SDK location — the same order the compiler's own
|
|
1983
|
+
/// discovery uses, so threading it changes nothing but the authority.
|
|
1984
|
+
fn androidNdkRootPath(b: *std.Build) ?[]const u8 {
|
|
1985
|
+
for ([_][]const u8{ "ANDROID_NDK_ROOT", "ANDROID_NDK_HOME", "ANDROID_NDK_LATEST_HOME" }) |name| {
|
|
1986
|
+
if (b.graph.environ_map.get(name)) |root| {
|
|
1987
|
+
if (root.len > 0 and buildDirExists(b, root)) return root;
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
const sdk_root = androidSdkRoot(b) orelse return null;
|
|
1991
|
+
return latestVersionSubdir(b, sdk_root, "ndk") orelse blk: {
|
|
1992
|
+
const legacy = b.pathJoin(&.{ sdk_root, "ndk-bundle" });
|
|
1993
|
+
break :blk if (buildDirExists(b, legacy)) legacy else null;
|
|
1994
|
+
};
|
|
1995
|
+
}
|
|
1996
|
+
|
|
1692
1997
|
fn androidNdkSysrootPath(b: *std.Build) ?[]const u8 {
|
|
1693
1998
|
for ([_][]const u8{ "ANDROID_NDK_ROOT", "ANDROID_NDK_HOME", "ANDROID_NDK_LATEST_HOME" }) |name| {
|
|
1694
1999
|
if (b.graph.environ_map.get(name)) |root| {
|
|
@@ -2187,6 +2492,7 @@ const AppManifestBuildConfig = struct {
|
|
|
2187
2492
|
relational_capability: bool = false,
|
|
2188
2493
|
credentials_capability: bool = false,
|
|
2189
2494
|
credentials_permission: bool = false,
|
|
2495
|
+
filesystem_permission: bool = false,
|
|
2190
2496
|
sqlite_capability: bool = false,
|
|
2191
2497
|
/// The first web declaration found (for teaching messages), or null
|
|
2192
2498
|
/// when app.zon declares no web use. `web_engine = "system"` alone is
|
|
@@ -2280,6 +2586,7 @@ fn appManifestBuildConfig(b: *std.Build, app_root: []const u8) AppManifestBuildC
|
|
|
2280
2586
|
.relational_capability = hasManifestCapability(raw.capabilities, "sqlite"),
|
|
2281
2587
|
.credentials_capability = hasManifestCapability(raw.capabilities, "credentials"),
|
|
2282
2588
|
.credentials_permission = hasManifestPermission(raw.permissions, "credentials"),
|
|
2589
|
+
.filesystem_permission = hasManifestPermission(raw.permissions, "filesystem"),
|
|
2283
2590
|
.sqlite_capability = hasManifestCapability(raw.capabilities, "store") or hasManifestCapability(raw.capabilities, "sqlite"),
|
|
2284
2591
|
.web_declaration = web_layer_contract.manifestDeclaration(raw),
|
|
2285
2592
|
};
|