@native-sdk/cli 0.8.3 → 0.9.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/build/app.zig +905 -61
- package/build.zig +674 -373
- package/build.zig.zon +1 -0
- package/native-sdk.d.ts +6 -0
- package/package.json +12 -11
- package/packages/core/compile-surface/core.ts +455 -3
- package/packages/core/package-lock.json +11 -11
- package/packages/core/package.json +2 -2
- package/packages/core/scripts/compiler_typecheck.mjs +116 -15
- package/packages/core/scripts/gen_service_surface.mjs +268 -0
- package/packages/core/scripts/npm_static_spike.mjs +64 -0
- package/packages/core/scripts/run_external_core_compiler.mjs +77 -6
- package/packages/core/scripts/run_external_service_compiler.mjs +240 -0
- package/packages/core/scripts/stage_external_core.mjs +9 -1
- package/packages/core/scripts/stage_external_services.mjs +172 -0
- package/packages/core/scripts/surface_manifest_diff.mjs +253 -0
- package/packages/core/scripts/vendor_service_packages.mjs +189 -0
- package/packages/core/sdk/core.d.ts +214 -2
- package/packages/core/sdk/core.ts +715 -42
- package/packages/core/sdk/events.d.ts +50 -0
- package/packages/core/sdk/events.ts +75 -0
- package/packages/core/src/checker.ts +528 -15
- package/packages/core/src/cli.ts +143 -3
- package/packages/core/src/contract.ts +26 -5
- package/packages/core/src/devhost.ts +1849 -18
- package/packages/core/src/devhost_journal.mjs +181 -0
- package/packages/core/src/devhost_resolver.mjs +17 -1
- package/packages/core/src/devhost_service_worker.mjs +90 -0
- package/packages/core/src/diagnostics.ts +84 -18
- package/packages/core/src/frontend.ts +204 -34
- package/packages/core/src/modules.ts +129 -80
- package/packages/core/src/service_contract.ts +597 -0
- package/packages/core/src/sqlite_cli.ts +93 -0
- package/packages/core/src/sqlite_codegen.ts +806 -0
- package/packages/core/src/sqlite_runtime_policy.ts +364 -0
- package/packages/core/src/typed_ast.ts +36 -8
- package/skill-data/core/SKILL.md +4 -2
- package/skill-data/core/references/project-anatomy.md +3 -2
- package/skill-data/core/references/web-engines-packaging-debugging.md +3 -1
- package/skill-data/native-ui/SKILL.md +55 -8
- package/skill-data/ts-core/SKILL.md +92 -40
- package/skill-data/ts-services/SKILL.md +126 -0
- package/skill-data/ts-services/references/service-surface.md +603 -0
- package/skill-data/zig/SKILL.md +1 -1
- package/skills/native-sdk/SKILL.md +1 -1
- package/src/app_runner/no_migrations.zig +3 -0
- package/src/app_runner/no_services.zig +20 -0
- package/src/app_runner/root.zig +104 -4
- package/src/app_runner/ts_core_main.zig +268 -4
- package/src/automation/snapshot.zig +23 -5
- package/src/embed/app_exports.zig +11 -1
- package/src/embed/c_api.zig +48 -2
- package/src/embed/conversions.zig +4 -5
- package/src/embed/host.zig +115 -1
- package/src/embed/root.zig +7 -0
- package/src/embed/tests.zig +213 -0
- package/src/embed/types.zig +51 -0
- package/src/embed/ui_host.zig +121 -5
- package/src/platform/android/NativeSdkActivity.java +131 -0
- package/src/platform/android/android_host.c +182 -1
- package/src/platform/android/native_sdk_app.h +17 -0
- package/src/platform/ios/native_sdk_app.h +17 -0
- package/src/platform/ios/uikit_host.m +115 -0
- package/src/platform/linux/cef_host.cpp +1 -1
- package/src/platform/linux/gtk_host.c +89 -17
- package/src/platform/linux/gtk_host.h +3 -0
- package/src/platform/linux/root.zig +41 -18
- package/src/platform/macos/appkit_host.h +26 -3
- package/src/platform/macos/appkit_host.m +1051 -129
- package/src/platform/macos/capture_info_plist.c +25 -0
- package/src/platform/macos/cef_host.mm +270 -36
- package/src/platform/macos/root.zig +312 -34
- package/src/platform/null_platform.zig +281 -19
- package/src/platform/null_platform_tests.zig +74 -0
- package/src/platform/root.zig +16 -0
- package/src/platform/types.zig +279 -15
- package/src/platform/windows/root.zig +243 -21
- package/src/platform/windows/webview2_host.cpp +464 -46
- package/src/primitives/app_manifest/comptime_scene.zig +2 -0
- package/src/primitives/app_manifest/root.zig +4 -0
- package/src/primitives/app_manifest/tests.zig +3 -0
- package/src/primitives/app_manifest/types.zig +34 -0
- package/src/primitives/app_manifest/validation.zig +19 -1
- package/src/primitives/canvas/code_tests.zig +9 -9
- package/src/primitives/canvas/events.zig +12 -11
- package/src/primitives/canvas/frame.zig +44 -9
- package/src/primitives/canvas/icons/mic.svg +1 -0
- package/src/primitives/canvas/icons.zig +2 -0
- package/src/primitives/canvas/root.zig +8 -0
- package/src/primitives/canvas/text_span_tests.zig +39 -0
- package/src/primitives/canvas/ui.zig +23 -4
- package/src/primitives/canvas/ui_markup.zig +15 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +9 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +1 -1
- package/src/primitives/canvas/ui_markup_tests.zig +5 -0
- package/src/primitives/canvas/ui_markup_view.zig +9 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +9 -6
- package/src/primitives/canvas/ui_schema.zig +19 -10
- package/src/primitives/canvas/ui_schema_tests.zig +5 -3
- package/src/primitives/canvas/ui_tests.zig +18 -4
- package/src/primitives/canvas/widget_invalidation.zig +9 -2
- package/src/primitives/canvas/widget_render.zig +296 -114
- package/src/primitives/canvas/widget_runtime_tests.zig +133 -0
- package/src/primitives/canvas/widget_text_input.zig +10 -10
- package/src/primitives/canvas/widget_tree.zig +1 -1
- package/src/primitives/canvas/widgets.zig +29 -5
- package/src/root.zig +56 -0
- package/src/runtime/api.zig +11 -0
- package/src/runtime/automation_snapshot.zig +4 -0
- package/src/runtime/automation_widget_dispatch.zig +1 -0
- package/src/runtime/bridge_payload.zig +2 -0
- package/src/runtime/bridge_permission_tests.zig +23 -2
- package/src/runtime/bridge_responses.zig +3 -1
- package/src/runtime/canvas_frame.zig +31 -13
- package/src/runtime/canvas_frame_animation_tests.zig +4 -0
- package/src/runtime/canvas_frame_invalidation_tests.zig +35 -10
- package/src/runtime/canvas_widget_anchored_tests.zig +83 -0
- package/src/runtime/canvas_widget_events.zig +69 -24
- package/src/runtime/canvas_widget_runtime.zig +101 -6
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +47 -4
- package/src/runtime/canvas_widget_scroll_drivers.zig +3 -3
- package/src/runtime/canvas_widget_semantics_tests.zig +2 -0
- package/src/runtime/canvas_widget_split_tree_tests.zig +228 -0
- package/src/runtime/canvas_widget_state.zig +6 -1
- package/src/runtime/canvas_widget_text_tests.zig +112 -3
- package/src/runtime/clock.zig +13 -1
- package/src/runtime/core.zig +133 -1
- package/src/runtime/credentials_store.zig +115 -0
- package/src/runtime/effects.zig +2568 -75
- package/src/runtime/effects_audio_capture_tests.zig +251 -0
- package/src/runtime/effects_credentials_tests.zig +332 -0
- package/src/runtime/effects_host_tests.zig +208 -1
- package/src/runtime/effects_relational_tests.zig +314 -0
- package/src/runtime/effects_store_tests.zig +211 -0
- package/src/runtime/flow.zig +14 -1
- package/src/runtime/gpu_surface_events.zig +6 -1
- package/src/runtime/native_command_event_tests.zig +42 -0
- package/src/runtime/persist_store.zig +666 -0
- package/src/runtime/record_store.zig +788 -0
- package/src/runtime/relational_store.zig +854 -0
- package/src/runtime/root.zig +52 -0
- package/src/runtime/runtime_event_tests.zig +70 -0
- package/src/runtime/service_host.zig +711 -0
- package/src/runtime/service_pool.zig +1314 -0
- package/src/runtime/session_blobs.zig +1 -1
- package/src/runtime/session_journal.zig +102 -0
- package/src/runtime/session_record.zig +177 -0
- package/src/runtime/session_replay.zig +109 -4
- package/src/runtime/shell_layout.zig +1 -0
- package/src/runtime/shell_layout_tests.zig +120 -0
- package/src/runtime/sqlite_engine.zig +474 -0
- package/src/runtime/state.zig +6 -0
- package/src/runtime/system_services.zig +49 -10
- package/src/runtime/tests.zig +5 -0
- package/src/runtime/ts_core_host.zig +1189 -118
- package/src/runtime/ts_core_host_tests.zig +638 -11
- package/src/runtime/ts_ui_app.zig +537 -1
- package/src/runtime/ui_app.zig +160 -19
- package/src/runtime/ui_app_tests.zig +203 -5
- package/src/runtime/validation.zig +22 -0
- package/src/runtime/view.zig +11 -0
- package/src/runtime/view_widget_scroll.zig +56 -5
- package/src/runtime/view_widget_text.zig +24 -5
- package/src/runtime/view_widget_tree.zig +1 -1
- package/src/runtime/window_storage.zig +1 -0
- package/src/runtime/window_view_runtime.zig +2 -3
- package/src/runtime/window_views.zig +19 -0
- package/src/tooling/android.zig +21 -16
- package/src/tooling/db.zig +160 -0
- package/src/tooling/ios.zig +7 -1
- package/src/tooling/manifest.zig +1248 -2
- package/src/tooling/package.zig +953 -6
- package/src/tooling/raw_manifest.zig +65 -0
- package/src/tooling/root.zig +1 -0
- package/src/tooling/templates.zig +216 -4
- package/src/tooling/ts_core.zig +283 -17
- package/src/tooling/verbs.zig +7 -0
- package/third_party/sqlite/README.md +13 -0
- package/third_party/sqlite/sqlite3.c +269649 -0
- package/third_party/sqlite/sqlite3.h +14349 -0
- package/tools/corewire/core_abi.zig +14 -2
- package/tools/corewire/emit.zig +98 -29
- package/tools/corewire/emit_facade.zig +414 -23
- package/tools/corewire/emit_profile.zig +6 -2
- package/tools/corewire/emit_service.zig +924 -0
- package/tools/corewire/main.zig +122 -0
- package/tools/corewire/service_contract.zig +250 -0
- package/tools/corewire/sidecar.zig +26 -15
package/build/app.zig
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
//! come from the native-sdk dependency.
|
|
5
5
|
|
|
6
6
|
const std = @import("std");
|
|
7
|
+
const builtin = @import("builtin");
|
|
7
8
|
|
|
8
9
|
/// The shared web-layer inference contract: this build graph is one thin
|
|
9
10
|
/// adapter over it (the CLI's manifest tooling and the app runner are the
|
|
@@ -98,12 +99,177 @@ const TsCoreStage = struct {
|
|
|
98
99
|
/// The compiled-core archive: the app module links it (with libc,
|
|
99
100
|
/// for the toolchain's runtime) beside the staged mirror.
|
|
100
101
|
archive: std.Build.LazyPath,
|
|
102
|
+
/// Plain-scriptc service host compiled from src/services/, when that
|
|
103
|
+
/// class exists and the child carrier is selected. It is installed/
|
|
104
|
+
/// packaged beside the app executable.
|
|
105
|
+
service_exe: ?std.Build.LazyPath = null,
|
|
106
|
+
/// The in-process carrier's service archive (thread-instanced,
|
|
107
|
+
/// runtime-localized), when that class exists and the in-process
|
|
108
|
+
/// carrier is selected. The app module links it beside the core's
|
|
109
|
+
/// archive.
|
|
110
|
+
service_archive: ?std.Build.LazyPath = null,
|
|
111
|
+
migrations: std.Build.LazyPath,
|
|
101
112
|
};
|
|
102
113
|
|
|
114
|
+
/// Which carrier runs src/services/ operations. Auto preserves the isolated,
|
|
115
|
+
/// single-instance child carrier; apps can explicitly opt into the parallel
|
|
116
|
+
/// in-process pool wherever the pinned service compiler can build the
|
|
117
|
+
/// runtime-localized service archive for the target (see
|
|
118
|
+
/// serviceArchiveSupported). `.service_carrier` in app.zon and the
|
|
119
|
+
/// `-Dservice-carrier` flag state the choice.
|
|
120
|
+
const ServiceCarrierOption = enum { auto, in_process, child };
|
|
121
|
+
|
|
122
|
+
const ServiceCarrier = enum { none, child, in_process };
|
|
123
|
+
|
|
124
|
+
/// Whether the pinned compiler can build TypeScript archives/executables for
|
|
125
|
+
/// this host/target pairing. Native desktop targets use their host toolchain,
|
|
126
|
+
/// including native Windows/MSVC. Cross-Windows builds use Zig's bundled GNU
|
|
127
|
+
/// sysroot; an MSVC cross target has no CRT headers or libraries to compile
|
|
128
|
+
/// the ScriptC runtime against.
|
|
129
|
+
pub fn scriptcCompileSupported(host: std.Target, target: std.Build.ResolvedTarget) bool {
|
|
130
|
+
const desktop_host = switch (host.os.tag) {
|
|
131
|
+
.macos, .linux, .windows => true,
|
|
132
|
+
else => false,
|
|
133
|
+
};
|
|
134
|
+
if (!desktop_host) return false;
|
|
135
|
+
const cross = scriptcTargetIsCross(host, target);
|
|
136
|
+
return switch (target.result.os.tag) {
|
|
137
|
+
.linux => true,
|
|
138
|
+
.windows => !cross or target.result.abi == .gnu,
|
|
139
|
+
.macos => host.os.tag == .macos,
|
|
140
|
+
else => false,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/// Whether the pinned service compiler can build the in-process carrier's
|
|
145
|
+
/// archive (runtime-localized, thread-instanced) on this build host for
|
|
146
|
+
/// this target. Its object localizers are deliberately architecture-aware:
|
|
147
|
+
/// native Linux uses host binutils, cross-ELF accepts x86_64/aarch64, COFF
|
|
148
|
+
/// accepts x86_64 (GNU when cross-compiled; the host ABI when native), and
|
|
149
|
+
/// Mach-O needs a macOS host (Apple linking rides the host toolchain's SDK).
|
|
150
|
+
pub fn serviceArchiveSupported(host: std.Target, target: std.Build.ResolvedTarget) bool {
|
|
151
|
+
if (!scriptcCompileSupported(host, target)) return false;
|
|
152
|
+
const cross = scriptcTargetIsCross(host, target);
|
|
153
|
+
return switch (target.result.os.tag) {
|
|
154
|
+
.linux => !cross or target.result.cpu.arch == .x86_64 or target.result.cpu.arch == .aarch64,
|
|
155
|
+
.windows => target.result.cpu.arch == .x86_64,
|
|
156
|
+
.macos => host.os.tag == .macos,
|
|
157
|
+
else => false,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/// Whether a Linux target's spelling lands on Zig's default glibc floor,
|
|
162
|
+
/// which predates `arc4random_buf` — a symbol the compiled service
|
|
163
|
+
/// runtime references, so the link fails late and opaquely without the
|
|
164
|
+
/// configure-time teaching. A native target (no `-Dtarget` os) resolves
|
|
165
|
+
/// the system's own glibc and is exempt; an explicitly spelled `-gnu`
|
|
166
|
+
/// target needs a stated glibc of 2.36 or later (or `-musl`, whose libc
|
|
167
|
+
/// always has the symbol).
|
|
168
|
+
pub fn linuxGlibcSpellingHitsDefaultFloor(target: std.Build.ResolvedTarget) bool {
|
|
169
|
+
if (target.result.os.tag != .linux or !target.result.abi.isGnu()) return false;
|
|
170
|
+
if (target.query.os_tag == null) return false;
|
|
171
|
+
const glibc = target.query.glibc_version orelse return true;
|
|
172
|
+
return glibc.order(.{ .major = 2, .minor = 36, .patch = 0 }) == .lt;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/// Whether ScriptC needs its zig-cc target lane rather than the native host
|
|
176
|
+
/// compiler. Keep this identical to the driver scripts' platform-triple
|
|
177
|
+
/// comparison: a stated glibc version makes an otherwise same-triple Linux
|
|
178
|
+
/// target cross because that floor must reach Zig's `-target` argument.
|
|
179
|
+
pub fn scriptcTargetIsCross(host: std.Target, target: std.Build.ResolvedTarget) bool {
|
|
180
|
+
if (target.result.os.tag != host.os.tag or target.result.cpu.arch != host.cpu.arch) return true;
|
|
181
|
+
// Zig's Windows host triple defaults to GNU even when native clang uses
|
|
182
|
+
// the installed Windows toolchain. A same-architecture MSVC target is
|
|
183
|
+
// therefore still native compiler work. Preserve an exact native GNU
|
|
184
|
+
// triple too; every other ABI change needs the zig-cc cross lane.
|
|
185
|
+
if (target.result.os.tag == .windows) {
|
|
186
|
+
return target.result.abi != host.abi and target.result.abi != .msvc;
|
|
187
|
+
}
|
|
188
|
+
return target.result.abi != host.abi or target.query.glibc_version != null;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/// The glibc-floor teaching for explicitly targeted ScriptC builds. Both the
|
|
192
|
+
/// core archive and either service carrier carry the compiled TypeScript
|
|
193
|
+
/// runtime, so all of them hit the same missing symbol. This is independent of
|
|
194
|
+
/// whether the target triple happens to match the build host.
|
|
195
|
+
pub fn scriptcLinuxGlibcSpellingTeaching(b: *std.Build, target: std.Build.ResolvedTarget) []const u8 {
|
|
196
|
+
return b.fmt(
|
|
197
|
+
"\nTypeScript target {t}-linux-gnu uses Zig's default glibc floor, which" ++
|
|
198
|
+
" predates arc4random_buf — a symbol the compiled runtime needs (glibc" ++
|
|
199
|
+
" 2.36+).\nSpell the target as \"{t}-linux-gnu.2.36\" (or later), or" ++
|
|
200
|
+
" \"{t}-linux-musl\".\n",
|
|
201
|
+
.{ target.result.cpu.arch, target.result.cpu.arch, target.result.cpu.arch },
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
pub fn panicScriptcLinuxGlibcSpelling(b: *std.Build, target: std.Build.ResolvedTarget) noreturn {
|
|
206
|
+
@panic(scriptcLinuxGlibcSpellingTeaching(b, target));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
pub fn panicUnsupportedScriptcTarget(b: *std.Build, host: std.Target, target: std.Build.ResolvedTarget) noreturn {
|
|
210
|
+
if (target.result.os.tag == .windows and scriptcTargetIsCross(host, target) and target.result.abi != .gnu) {
|
|
211
|
+
@panic(b.fmt(
|
|
212
|
+
"\nTypeScript cross-target Windows builds require the GNU ABI: Zig supplies" ++
|
|
213
|
+
" that target's CRT and system libraries, while an MSVC target needs a native" ++
|
|
214
|
+
" Windows toolchain.\nBuild {t}-windows-msvc on a matching Windows host, or" ++
|
|
215
|
+
" cross-compile as \"{t}-windows-gnu\".\n",
|
|
216
|
+
.{ target.result.cpu.arch, target.result.cpu.arch },
|
|
217
|
+
));
|
|
218
|
+
}
|
|
219
|
+
@panic(
|
|
220
|
+
"\nTypeScript desktop builds support native host targets, Linux and Windows GNU" ++
|
|
221
|
+
" cross targets from macOS/Linux/Windows, and macOS targets from macOS." ++
|
|
222
|
+
"\nChoose a supported target/host pairing.\n",
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
fn resolveServiceCarrier(
|
|
227
|
+
choice: ServiceCarrierOption,
|
|
228
|
+
has_services: bool,
|
|
229
|
+
b: *std.Build,
|
|
230
|
+
target: std.Build.ResolvedTarget,
|
|
231
|
+
) ServiceCarrier {
|
|
232
|
+
if (!has_services) return .none;
|
|
233
|
+
const host = b.graph.host.result;
|
|
234
|
+
const supported = serviceArchiveSupported(host, target);
|
|
235
|
+
const carrier: ServiceCarrier = switch (choice) {
|
|
236
|
+
.auto, .child => .child,
|
|
237
|
+
.in_process => if (supported) .in_process else @panic(
|
|
238
|
+
"\nservice_carrier = \"in_process\" requires a target the pinned service compiler" ++
|
|
239
|
+
" can produce a runtime-localized archive for: native Linux, cross-Linux" ++
|
|
240
|
+
" x86_64/aarch64, native Windows x86_64, cross-Windows x86_64 GNU," ++
|
|
241
|
+
" or macOS from a macOS build host." ++
|
|
242
|
+
"\nUse \"child\" (or drop the setting — auto selects the child carrier)" ++
|
|
243
|
+
" for this target.\n",
|
|
244
|
+
),
|
|
245
|
+
};
|
|
246
|
+
return carrier;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/// The `arch-os-abi` platform spelling every ScriptC compile lane receives.
|
|
250
|
+
/// A stated glibc version rides the abi (`gnu.2.36`) so the compiler's
|
|
251
|
+
/// cross lane builds at the spelled floor rather than the default one.
|
|
252
|
+
pub fn scriptcPlatformTriple(b: *std.Build, target: std.Build.ResolvedTarget) []const u8 {
|
|
253
|
+
const triple = b.fmt("{t}-{t}-{t}", .{ target.result.cpu.arch, target.result.os.tag, target.result.abi });
|
|
254
|
+
if (target.result.os.tag != .linux or !target.result.abi.isGnu()) return triple;
|
|
255
|
+
const glibc = target.query.glibc_version orelse return triple;
|
|
256
|
+
return if (glibc.patch == 0)
|
|
257
|
+
b.fmt("{s}.{d}.{d}", .{ triple, glibc.major, glibc.minor })
|
|
258
|
+
else
|
|
259
|
+
b.fmt("{s}.{d}.{d}.{d}", .{ triple, glibc.major, glibc.minor, glibc.patch });
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
fn parseServiceCarrierOption(raw: []const u8) ServiceCarrierOption {
|
|
263
|
+
if (std.mem.eql(u8, raw, "auto")) return .auto;
|
|
264
|
+
if (std.mem.eql(u8, raw, "in_process")) return .in_process;
|
|
265
|
+
if (std.mem.eql(u8, raw, "child")) return .child;
|
|
266
|
+
@panic("\n.service_carrier must be \"auto\", \"in_process\", or \"child\"\n");
|
|
267
|
+
}
|
|
268
|
+
|
|
103
269
|
/// The frontend's own sources — the staleness set of every build step
|
|
104
270
|
/// that runs it (a frontend edit re-checks every core).
|
|
105
271
|
const frontend_sources = [_][]const u8{
|
|
106
|
-
"checker.ts", "cli.ts", "contract.ts", "diagnostics.ts", "frontend.ts", "infer.ts", "modules.ts", "ownership.ts", "typed_ast.ts", "types.ts", "wyhash.ts",
|
|
272
|
+
"checker.ts", "cli.ts", "contract.ts", "diagnostics.ts", "frontend.ts", "infer.ts", "modules.ts", "ownership.ts", "service_contract.ts", "sqlite_codegen.ts", "sqlite_cli.ts", "sqlite_runtime_policy.ts", "typed_ast.ts", "types.ts", "wyhash.ts",
|
|
107
273
|
};
|
|
108
274
|
|
|
109
275
|
/// Whether the frontend's TypeScript compiler (@typescript/old, the
|
|
@@ -261,6 +427,25 @@ fn tsExternalCompilerJs(b: *std.Build, dep: *std.Build.Dependency) ?[]const u8 {
|
|
|
261
427
|
}
|
|
262
428
|
}
|
|
263
429
|
|
|
430
|
+
fn requireTsExternalCompilerJs(b: *std.Build, dep: *std.Build.Dependency) []const u8 {
|
|
431
|
+
return tsExternalCompilerJs(b, dep) orelse {
|
|
432
|
+
const sdk_root = tsSdkRoot(dep.builder.allocator, dep.builder.graph.io, dep);
|
|
433
|
+
std.debug.print(
|
|
434
|
+
\\
|
|
435
|
+
\\error: the external TypeScript compiler is not installed (cores and services
|
|
436
|
+
\\compile through it). It ships as an exact-pinned dependency of the SDK's
|
|
437
|
+
\\packages/core — install it once with:
|
|
438
|
+
\\ cd {s}/packages/core && npm ci
|
|
439
|
+
\\(or point NATIVE_SDK_CORE_COMPILER at the pinned release's command; an
|
|
440
|
+
\\npm-installed @native-sdk/cli carries the compiler automatically — if it is
|
|
441
|
+
\\missing there, the install is broken: reinstall @native-sdk/cli).
|
|
442
|
+
\\
|
|
443
|
+
\\
|
|
444
|
+
, .{sdk_root});
|
|
445
|
+
std.process.exit(1);
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
|
|
264
449
|
/// The SDK dependency's real root, resolved the way both the toolchain
|
|
265
450
|
/// check and its teaching name it.
|
|
266
451
|
fn tsSdkRoot(allocator: std.mem.Allocator, io: std.Io, dep: *std.Build.Dependency) []const u8 {
|
|
@@ -268,19 +453,19 @@ fn tsSdkRoot(allocator: std.mem.Allocator, io: std.Io, dep: *std.Build.Dependenc
|
|
|
268
453
|
return std.Io.Dir.cwd().realPathFileAlloc(io, raw_root, allocator) catch raw_root;
|
|
269
454
|
}
|
|
270
455
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
///
|
|
274
|
-
///
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
const node = b.findProgram(&.{"node"}, &.{}) catch {
|
|
281
|
-
@panic("\nbuilding a TypeScript app core needs node on PATH (the @native-sdk/core frontend checks the" ++
|
|
456
|
+
const TsToolingConsumer = enum { app_core, sqlite_schema };
|
|
457
|
+
|
|
458
|
+
/// Resolve the node + pinned TypeScript loader shared by the app-core
|
|
459
|
+
/// frontend and relational schema generator. Keep app-shape assertions out
|
|
460
|
+
/// of this helper: a Zig core may use SQLite without carrying a markup view.
|
|
461
|
+
fn tsToolingPreflight(b: *std.Build, dep: *std.Build.Dependency, consumer: TsToolingConsumer) []const u8 {
|
|
462
|
+
const node = b.findProgram(&.{"node"}, &.{}) catch switch (consumer) {
|
|
463
|
+
.app_core => @panic("\nbuilding a TypeScript app core needs node on PATH (the @native-sdk/core frontend checks the" ++
|
|
282
464
|
" core at build time; the binary you ship carries no JS runtime).\nInstall Node.js 22.15+ (on the 23" ++
|
|
283
|
-
" line: 23.5+) — https://nodejs.org or `brew install node` — and re-run.\n")
|
|
465
|
+
" line: 23.5+) — https://nodejs.org or `brew install node` — and re-run.\n"),
|
|
466
|
+
.sqlite_schema => @panic("\nbuilding relational SQLite migrations needs node on PATH (the schema checker and" ++
|
|
467
|
+
" migration generator run at build time; the binary you ship carries no JS runtime).\nInstall Node.js" ++
|
|
468
|
+
" 22.15+ (on the 23 line: 23.5+) — https://nodejs.org or `brew install node` — and re-run.\n"),
|
|
284
469
|
};
|
|
285
470
|
switch (tsToolchainResolution(b, dep)) {
|
|
286
471
|
.resolved => {},
|
|
@@ -292,16 +477,28 @@ fn tsCorePreflight(b: *std.Build, dep: *std.Build.Dependency, app_root: []const
|
|
|
292
477
|
// fail the configure phase cleanly — a teaching message, never
|
|
293
478
|
// a panic stack trace.
|
|
294
479
|
const sdk_root = tsSdkRoot(dep.builder.allocator, dep.builder.graph.io, dep);
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
480
|
+
switch (consumer) {
|
|
481
|
+
.app_core => std.debug.print(
|
|
482
|
+
\\
|
|
483
|
+
\\error: the @native-sdk/core frontend cannot resolve its TypeScript toolchain
|
|
484
|
+
\\(its compiler, @typescript/old). On a repo checkout, install it once with:
|
|
485
|
+
\\ cd {s}/packages/core && npm ci --include=dev
|
|
486
|
+
\\(An npm-installed @native-sdk/cli carries the toolchain automatically; if it
|
|
487
|
+
\\is missing there, the install is broken - reinstall @native-sdk/cli.)
|
|
488
|
+
\\
|
|
489
|
+
\\
|
|
490
|
+
, .{sdk_root}),
|
|
491
|
+
.sqlite_schema => std.debug.print(
|
|
492
|
+
\\
|
|
493
|
+
\\error: the relational SQLite schema generator cannot resolve its TypeScript toolchain
|
|
494
|
+
\\(its compiler, @typescript/old). On a repo checkout, install it once with:
|
|
495
|
+
\\ cd {s}/packages/core && npm ci --include=dev
|
|
496
|
+
\\(An npm-installed @native-sdk/cli carries the toolchain automatically; if it
|
|
497
|
+
\\is missing there, the install is broken - reinstall @native-sdk/cli.)
|
|
498
|
+
\\
|
|
499
|
+
\\
|
|
500
|
+
, .{sdk_root}),
|
|
501
|
+
}
|
|
305
502
|
std.process.exit(1);
|
|
306
503
|
},
|
|
307
504
|
.version_mismatch => |mismatch| {
|
|
@@ -310,22 +507,45 @@ fn tsCorePreflight(b: *std.Build, dep: *std.Build.Dependency, app_root: []const
|
|
|
310
507
|
// @typescript/old shadows the SDK's exact pin, and no install
|
|
311
508
|
// command fixes what is already installed — the conflict has
|
|
312
509
|
// to move.
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
510
|
+
switch (consumer) {
|
|
511
|
+
.app_core => std.debug.print(
|
|
512
|
+
\\
|
|
513
|
+
\\error: the @native-sdk/core frontend's TypeScript compiler resolves at the
|
|
514
|
+
\\wrong version: @typescript/old resolves to typescript {s}, but the SDK pins
|
|
515
|
+
\\npm:typescript@{s}. Another package in this tree pins a conflicting
|
|
516
|
+
\\@typescript/old - align it with the SDK's pin (or remove it) and reinstall,
|
|
517
|
+
\\so the SDK's exact pin is the copy that resolves.
|
|
518
|
+
\\
|
|
519
|
+
\\
|
|
520
|
+
, .{ mismatch.resolved, mismatch.pinned }),
|
|
521
|
+
.sqlite_schema => std.debug.print(
|
|
522
|
+
\\
|
|
523
|
+
\\error: the relational SQLite schema generator's TypeScript compiler resolves at the
|
|
524
|
+
\\wrong version: @typescript/old resolves to typescript {s}, but the SDK pins
|
|
525
|
+
\\npm:typescript@{s}. Another package in this tree pins a conflicting
|
|
526
|
+
\\@typescript/old - align it with the SDK's pin (or remove it) and reinstall,
|
|
527
|
+
\\so the SDK's exact pin is the copy that resolves.
|
|
528
|
+
\\
|
|
529
|
+
\\
|
|
530
|
+
, .{ mismatch.resolved, mismatch.pinned }),
|
|
531
|
+
}
|
|
323
532
|
std.process.exit(1);
|
|
324
533
|
},
|
|
325
534
|
}
|
|
326
535
|
return node;
|
|
327
536
|
}
|
|
328
537
|
|
|
538
|
+
/// The TS-core-only shape gate plus the shared tooling preflight. The
|
|
539
|
+
/// frontend (the subset checker and contract-sidecar emitter) runs under
|
|
540
|
+
/// node; the compile itself is the external toolchain's.
|
|
541
|
+
fn tsCorePreflight(b: *std.Build, dep: *std.Build.Dependency, app_root: []const u8) []const u8 {
|
|
542
|
+
if (!appFileExists(b, app_root, "src/app.native")) {
|
|
543
|
+
@panic("\nthis app has a TypeScript core (src/core.ts) but no view: TS apps render markup," ++
|
|
544
|
+
" so add src/app.native (the whole view tier binds the core's model)\n");
|
|
545
|
+
}
|
|
546
|
+
return tsToolingPreflight(b, dep, .app_core);
|
|
547
|
+
}
|
|
548
|
+
|
|
329
549
|
/// The TypeScript-core compile lane: the frontend checks the core and
|
|
330
550
|
/// emits its contract sidecar, corewire projects the generated compile
|
|
331
551
|
/// entry and library-mode profile, the stager assembles the compile
|
|
@@ -337,8 +557,69 @@ fn tsCorePreflight(b: *std.Build, dep: *std.Build.Dependency, app_root: []const
|
|
|
337
557
|
/// its own compile. The staged module directory carries core.zig (the
|
|
338
558
|
/// mirror) + its staged runtime + app.native + main.zig, so the
|
|
339
559
|
/// generated wiring imports one fixed shape.
|
|
340
|
-
fn tsCoreStage(
|
|
560
|
+
fn tsCoreStage(
|
|
561
|
+
b: *std.Build,
|
|
562
|
+
dep: *std.Build.Dependency,
|
|
563
|
+
target: std.Build.ResolvedTarget,
|
|
564
|
+
app_root: []const u8,
|
|
565
|
+
app_name: []const u8,
|
|
566
|
+
persist_capability: bool,
|
|
567
|
+
store_capability: bool,
|
|
568
|
+
relational_capability: bool,
|
|
569
|
+
credentials_capability: bool,
|
|
570
|
+
credentials_permission: bool,
|
|
571
|
+
persist_version: ?u64,
|
|
572
|
+
service_packages: []const ServicePackageConfig,
|
|
573
|
+
service_carrier_choice: ServiceCarrierOption,
|
|
574
|
+
service_pool_workers: ?u8,
|
|
575
|
+
) TsCoreStage {
|
|
341
576
|
const node = tsCorePreflight(b, dep, app_root);
|
|
577
|
+
const has_services = appHasServiceFiles(b, app_root);
|
|
578
|
+
if (!scriptcCompileSupported(b.graph.host.result, target)) {
|
|
579
|
+
panicUnsupportedScriptcTarget(b, b.graph.host.result, target);
|
|
580
|
+
}
|
|
581
|
+
// Every TypeScript app compiles its core archive for the target. Any
|
|
582
|
+
// explicitly spelled Linux GNU target without a sufficient glibc version
|
|
583
|
+
// lands on Zig's too-old default floor, even when its triple matches the
|
|
584
|
+
// build host; reject it before either compile lane reaches the linker.
|
|
585
|
+
if (linuxGlibcSpellingHitsDefaultFloor(target)) {
|
|
586
|
+
panicScriptcLinuxGlibcSpelling(b, target);
|
|
587
|
+
}
|
|
588
|
+
const service_carrier = resolveServiceCarrier(service_carrier_choice, has_services, b, target);
|
|
589
|
+
|
|
590
|
+
// Relational schema analysis runs the real SQLite parser in memory before
|
|
591
|
+
// the ordinary core checker. Its generated SDK/static surfaces carry the
|
|
592
|
+
// named Cmd.q/Sub.q members, while the Zig projection embeds the exact
|
|
593
|
+
// append-only migration chain the checker accepted.
|
|
594
|
+
var checked_sdk_core: std.Build.LazyPath = dep.path("packages/core/sdk/core.ts");
|
|
595
|
+
var checked_static_core: std.Build.LazyPath = dep.path("packages/core/compile-surface/core.ts");
|
|
596
|
+
var migrations_zig: std.Build.LazyPath = dep.path("src/app_runner/no_migrations.zig");
|
|
597
|
+
if (relational_capability) {
|
|
598
|
+
const sqlite_check = b.addSystemCommand(&.{node});
|
|
599
|
+
sqlite_check.addFileArg(dep.path("build/ts_run.mjs"));
|
|
600
|
+
sqlite_check.addFileArg(dep.path("packages/core/src/sqlite_cli.ts"));
|
|
601
|
+
sqlite_check.addArg("--src");
|
|
602
|
+
sqlite_check.addDirectoryArg(b.path(appPath(b, app_root, "src")));
|
|
603
|
+
sqlite_check.addArg("--sdk-in");
|
|
604
|
+
sqlite_check.addFileArg(dep.path("packages/core/sdk/core.ts"));
|
|
605
|
+
sqlite_check.addArg("--static-in");
|
|
606
|
+
sqlite_check.addFileArg(dep.path("packages/core/compile-surface/core.ts"));
|
|
607
|
+
sqlite_check.addArg("--sdk-out");
|
|
608
|
+
checked_sdk_core = sqlite_check.addOutputFileArg("core.ts");
|
|
609
|
+
sqlite_check.addArg("--static-out");
|
|
610
|
+
checked_static_core = sqlite_check.addOutputFileArg("core_static.ts");
|
|
611
|
+
sqlite_check.addArg("--zig-out");
|
|
612
|
+
migrations_zig = sqlite_check.addOutputFileArg("migrations.zig");
|
|
613
|
+
sqlite_check.addArg("--metadata-out");
|
|
614
|
+
_ = sqlite_check.addOutputFileArg("sqlite.meta.json");
|
|
615
|
+
sqlite_check.addArgs(&.{ "--state", b.pathFromRoot(appPath(b, app_root, "src/schema/migrations.lock.json")) });
|
|
616
|
+
if (appFileExists(b, app_root, "src/schema/migrations.lock.json")) {
|
|
617
|
+
sqlite_check.addFileInput(b.path(appPath(b, app_root, "src/schema/migrations.lock.json")));
|
|
618
|
+
}
|
|
619
|
+
sqlite_check.addFileInput(dep.path("packages/core/src/sqlite_codegen.ts"));
|
|
620
|
+
sqlite_check.addFileInput(dep.path("packages/core/src/sqlite_runtime_policy.ts"));
|
|
621
|
+
addAppSqlDirInputs(b, sqlite_check, appPath(b, app_root, "src"));
|
|
622
|
+
}
|
|
342
623
|
|
|
343
624
|
// The frontend, in check-only mode: the subset checker and the
|
|
344
625
|
// contract sidecar, no emission. Every check-time teaching gates the
|
|
@@ -363,11 +644,38 @@ fn tsCoreStage(b: *std.Build, dep: *std.Build.Dependency, app_root: []const u8,
|
|
|
363
644
|
// The document's entry spelling is app-relative (the sidecar/facade
|
|
364
645
|
// contract carries no machine paths).
|
|
365
646
|
check.addArgs(&.{ "--contract-entry", "src/core.ts" });
|
|
647
|
+
const services_contract: ?std.Build.LazyPath = if (has_services) services_contract: {
|
|
648
|
+
check.addArg("--services-contract");
|
|
649
|
+
break :services_contract check.addOutputFileArg("services.contract.json");
|
|
650
|
+
} else null;
|
|
651
|
+
if (persist_capability) check.addArgs(&.{ "--capability", "persist" });
|
|
652
|
+
for (service_packages) |package_entry| {
|
|
653
|
+
check.addArgs(&.{
|
|
654
|
+
"--service-package",
|
|
655
|
+
b.fmt("{s}|{s}|{s}", .{ package_entry.name, package_entry.version, package_entry.content_hash }),
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
if (store_capability) check.addArgs(&.{ "--capability", "store" });
|
|
659
|
+
if (relational_capability) check.addArgs(&.{ "--capability", "sqlite" });
|
|
660
|
+
if (credentials_capability) check.addArgs(&.{ "--capability", "credentials" });
|
|
661
|
+
if (credentials_permission) check.addArgs(&.{ "--permission", "credentials" });
|
|
662
|
+
if (relational_capability) {
|
|
663
|
+
check.addArg("--sdk-core");
|
|
664
|
+
check.addFileArg(checked_sdk_core);
|
|
665
|
+
}
|
|
666
|
+
if (persist_version) |version| {
|
|
667
|
+
check.addArgs(&.{ "--persist-version", b.fmt("{d}", .{version}) });
|
|
668
|
+
check.addArgs(&.{ "--persist-state", appPath(b, app_root, ".native/cache/persist-schema.json") });
|
|
669
|
+
}
|
|
366
670
|
addTsDirInputs(b, dep.builder, check, "packages/core/sdk");
|
|
367
671
|
addAppTsDirInputs(b, check, appPath(b, app_root, "src"));
|
|
368
672
|
for (frontend_sources) |source| {
|
|
369
673
|
check.addFileInput(dep.path(b.fmt("packages/core/src/{s}", .{source})));
|
|
370
674
|
}
|
|
675
|
+
// Service contracts echo the exact scriptc pin read from this manifest.
|
|
676
|
+
// Declare that runtime read explicitly so a compiler bump invalidates a
|
|
677
|
+
// warm build cache before the compile lane checks the echoed version.
|
|
678
|
+
if (has_services) check.addFileInput(dep.path("packages/core/package.json"));
|
|
371
679
|
|
|
372
680
|
// corewire, compiled from the SDK dependency for the build host: one
|
|
373
681
|
// invocation projects the generated compile entry and its profile,
|
|
@@ -381,6 +689,96 @@ fn tsCoreStage(b: *std.Build, dep: *std.Build.Dependency, app_root: []const u8,
|
|
|
381
689
|
project.addArg("--profile");
|
|
382
690
|
const profile = project.addOutputFileArg("core_profile.json");
|
|
383
691
|
|
|
692
|
+
// The fourth corewire projection is intentionally driven only by the
|
|
693
|
+
// service sidecar: the generated TypeScript dispatch loop and Zig
|
|
694
|
+
// name/index registry never rediscover facts from author source.
|
|
695
|
+
var service_registry: std.Build.LazyPath = dep.path("src/app_runner/no_services.zig");
|
|
696
|
+
var service_exe: ?std.Build.LazyPath = null;
|
|
697
|
+
var service_archive: ?std.Build.LazyPath = null;
|
|
698
|
+
var service_client: ?std.Build.LazyPath = null;
|
|
699
|
+
if (services_contract) |service_contract| {
|
|
700
|
+
const service_project = b.addRunArtifact(corewire_exe);
|
|
701
|
+
service_project.addArg("--services-sidecar");
|
|
702
|
+
service_project.addFileArg(service_contract);
|
|
703
|
+
service_project.addArg("--service-host-main");
|
|
704
|
+
const service_host_main = service_project.addOutputFileArg("service_host_main.ts");
|
|
705
|
+
service_project.addArg("--service-registry");
|
|
706
|
+
service_registry = service_project.addOutputFileArg("services.zig");
|
|
707
|
+
service_project.addArg("--service-client");
|
|
708
|
+
service_client = service_project.addOutputFileArg("services.gen.ts");
|
|
709
|
+
const service_inproc_main: ?std.Build.LazyPath = if (service_carrier == .in_process) inproc: {
|
|
710
|
+
service_project.addArg("--service-inproc-main");
|
|
711
|
+
break :inproc service_project.addOutputFileArg("service_inproc_main.ts");
|
|
712
|
+
} else null;
|
|
713
|
+
const service_inproc_profile: ?std.Build.LazyPath = if (service_carrier == .in_process) inproc: {
|
|
714
|
+
service_project.addArg("--service-inproc-profile");
|
|
715
|
+
break :inproc service_project.addOutputFileArg("service_profile.json");
|
|
716
|
+
} else null;
|
|
717
|
+
|
|
718
|
+
// Ordinary service TypeScript is staged without core-subset rewrites.
|
|
719
|
+
// The one service-boundary lowering turns NS1067's `{ kind, message }`
|
|
720
|
+
// throw into the tagged Error shape scriptc 0.0.28 can catch from an
|
|
721
|
+
// imported op; no deterministic profile fences participate here.
|
|
722
|
+
const service_stage_run = b.addSystemCommand(&.{node});
|
|
723
|
+
service_stage_run.addFileArg(dep.path("packages/core/scripts/stage_external_services.mjs"));
|
|
724
|
+
service_stage_run.addArg("--src");
|
|
725
|
+
service_stage_run.addDirectoryArg(b.path(appPath(b, app_root, "src")));
|
|
726
|
+
service_stage_run.addArg("--host-main");
|
|
727
|
+
service_stage_run.addFileArg(service_host_main);
|
|
728
|
+
if (service_inproc_main) |inproc_main| {
|
|
729
|
+
service_stage_run.addArg("--inproc-main");
|
|
730
|
+
service_stage_run.addFileArg(inproc_main);
|
|
731
|
+
}
|
|
732
|
+
if (service_inproc_profile) |inproc_profile| {
|
|
733
|
+
service_stage_run.addArg("--inproc-profile");
|
|
734
|
+
service_stage_run.addFileArg(inproc_profile);
|
|
735
|
+
}
|
|
736
|
+
service_stage_run.addArg("--contract");
|
|
737
|
+
service_stage_run.addFileArg(service_contract);
|
|
738
|
+
service_stage_run.addArg("--out");
|
|
739
|
+
const service_stage_dir = service_stage_run.addOutputDirectoryArg("services-stage");
|
|
740
|
+
// The staging script discovers nested service modules recursively;
|
|
741
|
+
// a directory LazyPath alone does not hash those discovered files.
|
|
742
|
+
service_stage_run.has_side_effects = true;
|
|
743
|
+
|
|
744
|
+
const service_compile = b.addSystemCommand(&.{node});
|
|
745
|
+
service_compile.addFileArg(dep.path("packages/core/scripts/run_external_service_compiler.mjs"));
|
|
746
|
+
service_compile.addArg("--stage");
|
|
747
|
+
service_compile.addDirectoryArg(service_stage_dir);
|
|
748
|
+
service_compile.addArg("--manifest");
|
|
749
|
+
service_compile.addFileArg(dep.path("packages/core/package.json"));
|
|
750
|
+
service_compile.addArg("--contract");
|
|
751
|
+
service_compile.addFileArg(service_contract);
|
|
752
|
+
if (service_carrier == .in_process) {
|
|
753
|
+
// The in-process carrier links the service class into the app
|
|
754
|
+
// binary; no sibling executable is built or packaged.
|
|
755
|
+
service_compile.addArg("--out-archive");
|
|
756
|
+
service_archive = service_compile.addOutputFileArg(b.fmt("lib{s}_services.a", .{externalCoreSymbolName(b, app_name)}));
|
|
757
|
+
} else {
|
|
758
|
+
service_compile.addArg("--out-exe");
|
|
759
|
+
const service_suffix = if (target.result.os.tag == .windows) ".exe" else "";
|
|
760
|
+
service_exe = service_compile.addOutputFileArg(b.fmt("{s}_services{s}", .{ app_name, service_suffix }));
|
|
761
|
+
}
|
|
762
|
+
service_compile.addArgs(&.{
|
|
763
|
+
"--host-platform",
|
|
764
|
+
b.fmt("{t}-{t}-{t}", .{ b.graph.host.result.cpu.arch, b.graph.host.result.os.tag, b.graph.host.result.abi }),
|
|
765
|
+
"--target-platform",
|
|
766
|
+
scriptcPlatformTriple(b, target),
|
|
767
|
+
// Cross service compiles run the pinned compiler's zig-cc
|
|
768
|
+
// lane; hand over this build's own zig so the lane never
|
|
769
|
+
// depends on a PATH zig (native compiles ignore it).
|
|
770
|
+
"--zig-exe",
|
|
771
|
+
b.graph.zig_exe,
|
|
772
|
+
});
|
|
773
|
+
if (b.graph.environ_map.get("NATIVE_SDK_CORE_COMPILER")) |override| {
|
|
774
|
+
service_compile.addArgs(&.{ "--compiler", override });
|
|
775
|
+
} else {
|
|
776
|
+
const compiler_js = requireTsExternalCompilerJs(b, dep);
|
|
777
|
+
service_compile.addArg("--compiler-js");
|
|
778
|
+
service_compile.addFileArg(.{ .cwd_relative = compiler_js });
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
|
|
384
782
|
// The compile stage: author sources + staged SDK + static surface +
|
|
385
783
|
// generated entry/profile, one scratch tree.
|
|
386
784
|
const stage_run = b.addSystemCommand(&.{node});
|
|
@@ -390,11 +788,15 @@ fn tsCoreStage(b: *std.Build, dep: *std.Build.Dependency, app_root: []const u8,
|
|
|
390
788
|
stage_run.addArg("--sdk");
|
|
391
789
|
stage_run.addDirectoryArg(dep.path("packages/core/sdk"));
|
|
392
790
|
stage_run.addArg("--static");
|
|
393
|
-
stage_run.addFileArg(
|
|
791
|
+
stage_run.addFileArg(checked_static_core);
|
|
394
792
|
stage_run.addArg("--facade");
|
|
395
793
|
stage_run.addFileArg(facade);
|
|
396
794
|
stage_run.addArg("--profile");
|
|
397
795
|
stage_run.addFileArg(profile);
|
|
796
|
+
if (service_client) |client| {
|
|
797
|
+
stage_run.addArg("--services-client");
|
|
798
|
+
stage_run.addFileArg(client);
|
|
799
|
+
}
|
|
398
800
|
stage_run.addArg("--out");
|
|
399
801
|
const stage_dir = stage_run.addOutputDirectoryArg("stage");
|
|
400
802
|
|
|
@@ -408,31 +810,28 @@ fn tsCoreStage(b: *std.Build, dep: *std.Build.Dependency, app_root: []const u8,
|
|
|
408
810
|
compile.addArgs(&.{ "--name", symbol_name });
|
|
409
811
|
compile.addArg("--manifest");
|
|
410
812
|
compile.addFileArg(dep.path("packages/core/package.json"));
|
|
813
|
+
compile.addArg("--frontend-sidecar");
|
|
814
|
+
compile.addFileArg(contract);
|
|
411
815
|
compile.addArg("--out-archive");
|
|
412
816
|
const archive = compile.addOutputFileArg(b.fmt("lib{s}.a", .{symbol_name}));
|
|
413
817
|
compile.addArg("--out-sidecar");
|
|
414
818
|
const compiled_sidecar = compile.addOutputFileArg("core.contract.json");
|
|
819
|
+
compile.addArgs(&.{
|
|
820
|
+
"--host-platform",
|
|
821
|
+
b.fmt("{t}-{t}-{t}", .{ b.graph.host.result.cpu.arch, b.graph.host.result.os.tag, b.graph.host.result.abi }),
|
|
822
|
+
"--target-platform",
|
|
823
|
+
scriptcPlatformTriple(b, target),
|
|
824
|
+
// Keep the core and service archives on the same cross compiler and
|
|
825
|
+
// target. Native compiles ignore the supplied Zig path.
|
|
826
|
+
"--zig-exe",
|
|
827
|
+
b.graph.zig_exe,
|
|
828
|
+
});
|
|
415
829
|
if (b.graph.environ_map.get("NATIVE_SDK_CORE_COMPILER")) |override| {
|
|
416
830
|
// The development override: point at any toolchain command; the
|
|
417
831
|
// driver still refuses a release other than the SDK's pin.
|
|
418
832
|
compile.addArgs(&.{ "--compiler", override });
|
|
419
833
|
} else {
|
|
420
|
-
const compiler_js =
|
|
421
|
-
const sdk_root = tsSdkRoot(dep.builder.allocator, dep.builder.graph.io, dep);
|
|
422
|
-
std.debug.print(
|
|
423
|
-
\\
|
|
424
|
-
\\error: the external core compiler is not installed (TypeScript cores compile
|
|
425
|
-
\\through it). It ships as an exact-pinned dependency of the SDK's packages/core
|
|
426
|
-
\\— install it once with:
|
|
427
|
-
\\ cd {s}/packages/core && npm ci
|
|
428
|
-
\\(or point NATIVE_SDK_CORE_COMPILER at the pinned release's command; an
|
|
429
|
-
\\npm-installed @native-sdk/cli carries the compiler automatically — if it is
|
|
430
|
-
\\missing there, the install is broken: reinstall @native-sdk/cli).
|
|
431
|
-
\\
|
|
432
|
-
\\
|
|
433
|
-
, .{sdk_root});
|
|
434
|
-
std.process.exit(1);
|
|
435
|
-
};
|
|
834
|
+
const compiler_js = requireTsExternalCompilerJs(b, dep);
|
|
436
835
|
compile.addArg("--compiler-js");
|
|
437
836
|
compile.addFileArg(.{ .cwd_relative = compiler_js });
|
|
438
837
|
}
|
|
@@ -450,9 +849,58 @@ fn tsCoreStage(b: *std.Build, dep: *std.Build.Dependency, app_root: []const u8,
|
|
|
450
849
|
_ = staged.addCopyFile(shim, "core.zig");
|
|
451
850
|
_ = staged.addCopyFile(dep.path("tools/corewire/shim_rt.zig"), "shim_rt.zig");
|
|
452
851
|
_ = staged.addCopyFile(dep.path("tools/corewire/core_abi.zig"), "core_abi.zig");
|
|
852
|
+
_ = staged.addCopyFile(service_registry, "services.zig");
|
|
853
|
+
// The carrier selection, as one staged constant module: the generated
|
|
854
|
+
// wiring comptime-switches its service transport on it.
|
|
855
|
+
_ = staged.add("service_carrier.zig", b.fmt(
|
|
856
|
+
\\//! Generated by the app build: the resolved service-carrier selection.
|
|
857
|
+
\\pub const Kind = enum {{ none, child, in_process }};
|
|
858
|
+
\\pub const kind: Kind = .{t};
|
|
859
|
+
\\/// Pool width for the in-process carrier; null resolves the
|
|
860
|
+
\\/// runtime default (min(4, cores)).
|
|
861
|
+
\\pub const pool_workers: ?usize = {?d};
|
|
862
|
+
\\
|
|
863
|
+
, .{ service_carrier, service_pool_workers }));
|
|
864
|
+
_ = staged.addCopyFile(migrations_zig, "migrations.zig");
|
|
453
865
|
_ = staged.addCopyFile(b.path(appPath(b, app_root, "src/app.native")), "app.native");
|
|
454
866
|
const main_root = staged.addCopyFile(dep.path("src/app_runner/ts_core_main.zig"), "main.zig");
|
|
455
|
-
return .{
|
|
867
|
+
return .{
|
|
868
|
+
.main_root = main_root,
|
|
869
|
+
.archive = archive,
|
|
870
|
+
.service_exe = service_exe,
|
|
871
|
+
.service_archive = service_archive,
|
|
872
|
+
.migrations = migrations_zig,
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
fn sqliteMigrationsStage(b: *std.Build, dep: *std.Build.Dependency, app_root: []const u8) std.Build.LazyPath {
|
|
877
|
+
const node = tsToolingPreflight(b, dep, .sqlite_schema);
|
|
878
|
+
const generate = b.addSystemCommand(&.{node});
|
|
879
|
+
generate.addFileArg(dep.path("build/ts_run.mjs"));
|
|
880
|
+
generate.addFileArg(dep.path("packages/core/src/sqlite_cli.ts"));
|
|
881
|
+
generate.addArg("--src");
|
|
882
|
+
generate.addDirectoryArg(b.path(appPath(b, app_root, "src")));
|
|
883
|
+
generate.addArg("--zig-out");
|
|
884
|
+
const migrations = generate.addOutputFileArg("migrations.zig");
|
|
885
|
+
generate.addArgs(&.{ "--state", b.pathFromRoot(appPath(b, app_root, "src/schema/migrations.lock.json")) });
|
|
886
|
+
if (appFileExists(b, app_root, "src/schema/migrations.lock.json")) {
|
|
887
|
+
generate.addFileInput(b.path(appPath(b, app_root, "src/schema/migrations.lock.json")));
|
|
888
|
+
}
|
|
889
|
+
generate.addFileInput(dep.path("packages/core/src/sqlite_codegen.ts"));
|
|
890
|
+
generate.addFileInput(dep.path("packages/core/src/sqlite_runtime_policy.ts"));
|
|
891
|
+
addAppSqlDirInputs(b, generate, appPath(b, app_root, "src"));
|
|
892
|
+
return migrations;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
fn addAppSqlDirInputs(b: *std.Build, run: *std.Build.Step.Run, src_path: []const u8) void {
|
|
896
|
+
var dir = b.build_root.handle.openDir(b.graph.io, src_path, .{ .iterate = true }) catch return;
|
|
897
|
+
defer dir.close(b.graph.io);
|
|
898
|
+
var walker = dir.walk(b.allocator) catch return;
|
|
899
|
+
defer walker.deinit();
|
|
900
|
+
while (walker.next(b.graph.io) catch null) |entry| {
|
|
901
|
+
if (entry.kind != .file or !std.mem.endsWith(u8, entry.basename, ".sql")) continue;
|
|
902
|
+
run.addFileInput(b.path(b.fmt("{s}/{s}", .{ src_path, entry.path })));
|
|
903
|
+
}
|
|
456
904
|
}
|
|
457
905
|
|
|
458
906
|
/// corewire (the contract-sidecar shim generator), compiled from the SDK
|
|
@@ -510,10 +958,24 @@ fn addAppTsDirInputs(b: *std.Build, transpile: *std.Build.Step.Run, src_path: []
|
|
|
510
958
|
}
|
|
511
959
|
}
|
|
512
960
|
|
|
961
|
+
fn appHasServiceFiles(b: *std.Build, app_root: []const u8) bool {
|
|
962
|
+
const services_path = appPath(b, app_root, "src/services");
|
|
963
|
+
var dir = b.build_root.handle.openDir(b.graph.io, services_path, .{ .iterate = true }) catch return false;
|
|
964
|
+
defer dir.close(b.graph.io);
|
|
965
|
+
var walker = dir.walk(b.allocator) catch return false;
|
|
966
|
+
defer walker.deinit();
|
|
967
|
+
while (walker.next(b.graph.io) catch null) |entry| {
|
|
968
|
+
if (entry.kind == .file and std.mem.endsWith(u8, entry.basename, ".ts") and
|
|
969
|
+
!std.mem.endsWith(u8, entry.basename, ".d.ts")) return true;
|
|
970
|
+
}
|
|
971
|
+
return false;
|
|
972
|
+
}
|
|
973
|
+
|
|
513
974
|
/// The `native_sdk_app_*` C ABI every embed static library exports.
|
|
514
975
|
pub const mobile_export_symbol_names = [_][]const u8{
|
|
515
976
|
"native_sdk_app_create",
|
|
516
977
|
"native_sdk_app_destroy",
|
|
978
|
+
"native_sdk_app_destroy_with_status",
|
|
517
979
|
"native_sdk_app_start",
|
|
518
980
|
"native_sdk_app_activate",
|
|
519
981
|
"native_sdk_app_deactivate",
|
|
@@ -525,9 +987,11 @@ pub const mobile_export_symbol_names = [_][]const u8{
|
|
|
525
987
|
"native_sdk_app_text_input_state",
|
|
526
988
|
"native_sdk_app_set_text_measure",
|
|
527
989
|
"native_sdk_app_set_audio_service",
|
|
990
|
+
"native_sdk_app_set_credential_service",
|
|
528
991
|
"native_sdk_app_audio_event",
|
|
529
992
|
"native_sdk_app_set_image_service",
|
|
530
993
|
"native_sdk_app_set_automation_dir",
|
|
994
|
+
"native_sdk_app_set_data_root",
|
|
531
995
|
"native_sdk_app_touch",
|
|
532
996
|
"native_sdk_app_scroll",
|
|
533
997
|
"native_sdk_app_key",
|
|
@@ -575,6 +1039,21 @@ pub const MobileLibOptions = struct {
|
|
|
575
1039
|
/// `src/embed/ui_host.zig`. Ignored for `.scene = .webview`.
|
|
576
1040
|
main: []const u8 = "src/main.zig",
|
|
577
1041
|
scene: MobileSceneOption = .canvas,
|
|
1042
|
+
/// Link and install the engine-owned Tier-2 record store. Standard
|
|
1043
|
+
/// `addApp` builds infer this from app.zon; direct `addMobileLib`
|
|
1044
|
+
/// callers state it here because that lower-level API has no manifest.
|
|
1045
|
+
store_capability: bool = false,
|
|
1046
|
+
/// Link and install the engine-owned Tier-3 relational database.
|
|
1047
|
+
relational_capability: bool = false,
|
|
1048
|
+
/// Generated append-only migration module. Direct low-level callers may
|
|
1049
|
+
/// omit it and open an empty version-0 database.
|
|
1050
|
+
relational_migrations: ?std.Build.LazyPath = null,
|
|
1051
|
+
/// Compile the Tier-4 core credential effects into the mobile host.
|
|
1052
|
+
credentials_capability: bool = false,
|
|
1053
|
+
/// Grant those effects access to the registered OS credential service.
|
|
1054
|
+
credentials_permission: bool = false,
|
|
1055
|
+
/// Stable app identity used as the Keychain/Keystore service namespace.
|
|
1056
|
+
credentials_service: []const u8 = "dev.native_sdk.app",
|
|
578
1057
|
};
|
|
579
1058
|
|
|
580
1059
|
/// Mobile counterpart of `addApp`: produce the embed static library
|
|
@@ -612,10 +1091,29 @@ fn addMobileLibWithTarget(b: *std.Build, dep: *std.Build.Dependency, target: std
|
|
|
612
1091
|
});
|
|
613
1092
|
exports_mod.addImport("native_sdk", native_sdk_mod);
|
|
614
1093
|
if (options.scene == .canvas) {
|
|
1094
|
+
const mobile_options = b.addOptions();
|
|
1095
|
+
mobile_options.addOption(bool, "store_capability", options.store_capability);
|
|
1096
|
+
mobile_options.addOption(bool, "relational_capability", options.relational_capability);
|
|
1097
|
+
mobile_options.addOption(bool, "credentials_capability", options.credentials_capability);
|
|
1098
|
+
mobile_options.addOption(bool, "credentials_permission", options.credentials_permission);
|
|
1099
|
+
mobile_options.addOption([]const u8, "credentials_service", options.credentials_service);
|
|
1100
|
+
exports_mod.addImport("mobile_build_options", mobile_options.createModule());
|
|
1101
|
+
const migration_path = options.relational_migrations orelse dep.path("src/app_runner/no_migrations.zig");
|
|
1102
|
+
const migration_mod = b.createModule(.{ .root_source_file = migration_path, .target = target, .optimize = optimize });
|
|
1103
|
+
migration_mod.addImport("native_sdk", native_sdk_mod);
|
|
1104
|
+
exports_mod.addImport("relational_migrations", migration_mod);
|
|
615
1105
|
const app_mod = localModule(b, target, optimize, options.main);
|
|
616
1106
|
app_mod.addImport("native_sdk", native_sdk_mod);
|
|
617
1107
|
exports_mod.addImport("app", app_mod);
|
|
618
1108
|
}
|
|
1109
|
+
if (options.store_capability or options.relational_capability) {
|
|
1110
|
+
exports_mod.addIncludePath(dep.path("third_party/sqlite"));
|
|
1111
|
+
exports_mod.addCSourceFile(.{
|
|
1112
|
+
.file = dep.path("third_party/sqlite/sqlite3.c"),
|
|
1113
|
+
.flags = sqliteCFlags(b, target),
|
|
1114
|
+
});
|
|
1115
|
+
exports_mod.link_libc = true;
|
|
1116
|
+
}
|
|
619
1117
|
exports_mod.export_symbol_names = &mobile_export_symbol_names;
|
|
620
1118
|
|
|
621
1119
|
const lib = b.addLibrary(.{
|
|
@@ -692,10 +1190,47 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
|
|
|
692
1190
|
" target mobile yet.\nBuild for a desktop target, or port the core to a Zig" ++
|
|
693
1191
|
" `mobileOptions` app — Zig and markup cores are fully supported on mobile.\n");
|
|
694
1192
|
}
|
|
1193
|
+
// The service-carrier selection: `-Dservice-carrier` overrides app.zon's
|
|
1194
|
+
// `.service_carrier`; both default to auto (the child carrier).
|
|
1195
|
+
const service_carrier_choice: ServiceCarrierOption = choice: {
|
|
1196
|
+
if (b.option([]const u8, "service-carrier", "How src/services operations run: auto (default), in_process, child")) |flag| {
|
|
1197
|
+
break :choice parseServiceCarrierOption(flag);
|
|
1198
|
+
}
|
|
1199
|
+
break :choice parseServiceCarrierOption(app_config.service_carrier);
|
|
1200
|
+
};
|
|
1201
|
+
const service_pool_workers: ?u8 = workers: {
|
|
1202
|
+
const configured = b.option(u8, "service-pool-size", "In-process service carrier worker threads (1-16; default min(4, cores))") orelse
|
|
1203
|
+
app_config.service_pool_size;
|
|
1204
|
+
if (configured) |count| {
|
|
1205
|
+
if (count < 1 or count > 16) @panic("\nservice pool size must be between 1 and 16\n");
|
|
1206
|
+
}
|
|
1207
|
+
break :workers configured;
|
|
1208
|
+
};
|
|
695
1209
|
const ts_stage: ?TsCoreStage = if (core_tree == .ts)
|
|
696
|
-
tsCoreStage(
|
|
1210
|
+
tsCoreStage(
|
|
1211
|
+
b,
|
|
1212
|
+
dep,
|
|
1213
|
+
target,
|
|
1214
|
+
app_options.app_root,
|
|
1215
|
+
app_options.name,
|
|
1216
|
+
app_config.persist_capability,
|
|
1217
|
+
app_config.store_capability,
|
|
1218
|
+
app_config.relational_capability,
|
|
1219
|
+
app_config.credentials_capability,
|
|
1220
|
+
app_config.credentials_permission,
|
|
1221
|
+
app_config.persist_version,
|
|
1222
|
+
app_config.service_packages,
|
|
1223
|
+
service_carrier_choice,
|
|
1224
|
+
service_pool_workers,
|
|
1225
|
+
)
|
|
697
1226
|
else
|
|
698
1227
|
null;
|
|
1228
|
+
const relational_migrations = if (ts_stage) |stage|
|
|
1229
|
+
stage.migrations
|
|
1230
|
+
else if (app_config.relational_capability)
|
|
1231
|
+
sqliteMigrationsStage(b, dep, app_options.app_root)
|
|
1232
|
+
else
|
|
1233
|
+
dep.path("src/app_runner/no_migrations.zig");
|
|
699
1234
|
|
|
700
1235
|
// Mobile targets get the embed static library as a `lib` step: the
|
|
701
1236
|
// artifact the toolkit-owned iOS host (and any hand-written shim)
|
|
@@ -706,6 +1241,12 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
|
|
|
706
1241
|
addMobileLibWithTarget(b, dep, target, optimize, .{
|
|
707
1242
|
.name = app_options.name,
|
|
708
1243
|
.main = appPath(b, app_options.app_root, app_options.main),
|
|
1244
|
+
.store_capability = app_config.store_capability,
|
|
1245
|
+
.relational_capability = app_config.relational_capability,
|
|
1246
|
+
.relational_migrations = relational_migrations,
|
|
1247
|
+
.credentials_capability = app_config.credentials_capability,
|
|
1248
|
+
.credentials_permission = app_config.credentials_permission,
|
|
1249
|
+
.credentials_service = app_config.app_id,
|
|
709
1250
|
});
|
|
710
1251
|
}
|
|
711
1252
|
const platform_option = b.option(PlatformOption, "platform", "Desktop backend: auto, null, macos, linux, windows") orelse .auto;
|
|
@@ -754,7 +1295,7 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
|
|
|
754
1295
|
options.addOption(bool, "web_layer", web_layer);
|
|
755
1296
|
const options_mod = options.createModule();
|
|
756
1297
|
|
|
757
|
-
const app_mod = appModule(b, dep, target, app_optimize, app_options, options_mod, ts_stage);
|
|
1298
|
+
const app_mod = appModule(b, dep, target, app_optimize, app_options, options_mod, ts_stage, relational_migrations, app_config);
|
|
758
1299
|
const exe = b.addExecutable(.{
|
|
759
1300
|
.name = app_options.name,
|
|
760
1301
|
.root_module = app_mod,
|
|
@@ -787,13 +1328,29 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
|
|
|
787
1328
|
const install = b.addInstallArtifact(exe, .{});
|
|
788
1329
|
b.getInstallStep().dependOn(&install.step);
|
|
789
1330
|
|
|
790
|
-
const
|
|
1331
|
+
const service_install: ?*std.Build.Step.InstallFile = if (ts_stage) |stage| if (stage.service_exe) |service_exe| service_install: {
|
|
1332
|
+
const suffix = if (target.result.os.tag == .windows) ".exe" else "";
|
|
1333
|
+
const value = b.addInstallFileWithDir(service_exe, .bin, b.fmt("{s}_services{s}", .{ app_options.name, suffix }));
|
|
1334
|
+
b.getInstallStep().dependOn(&value.step);
|
|
1335
|
+
break :service_install value;
|
|
1336
|
+
} else null else null;
|
|
1337
|
+
|
|
1338
|
+
// A service-bearing app runs from the installed layout so the host is
|
|
1339
|
+
// a real sibling exactly as it is in a package. Service-free apps keep
|
|
1340
|
+
// the direct cached-artifact fast path.
|
|
1341
|
+
const run = if (service_install != null) run: {
|
|
1342
|
+
const suffix = if (target.result.os.tag == .windows) ".exe" else "";
|
|
1343
|
+
const value = b.addSystemCommand(&.{b.getInstallPath(.bin, b.fmt("{s}{s}", .{ app_options.name, suffix }))});
|
|
1344
|
+
value.step.dependOn(&install.step);
|
|
1345
|
+
value.step.dependOn(&service_install.?.step);
|
|
1346
|
+
break :run value;
|
|
1347
|
+
} else b.addRunArtifact(exe);
|
|
791
1348
|
addCefRuntimeRunFiles(b, target, run, exe, web_engine, cef_dir);
|
|
792
1349
|
addWebView2RuntimeRunFiles(dep, target, run, web_engine, web_layer);
|
|
793
1350
|
const run_step = b.step("run", "Run the app");
|
|
794
1351
|
run_step.dependOn(&run.step);
|
|
795
1352
|
|
|
796
|
-
const test_app_mod = if (app_optimize == optimize) app_mod else appModule(b, dep, target, optimize, app_options, options_mod, ts_stage);
|
|
1353
|
+
const test_app_mod = if (app_optimize == optimize) app_mod else appModule(b, dep, target, optimize, app_options, options_mod, ts_stage, relational_migrations, app_config);
|
|
797
1354
|
const tests = b.addTest(.{ .root_module = test_app_mod, .use_llvm = useLlvmWorkaround(target) });
|
|
798
1355
|
const test_step = b.step("test", "Run tests");
|
|
799
1356
|
test_step.dependOn(&b.addRunArtifact(tests).step);
|
|
@@ -896,6 +1453,10 @@ pub fn addAppArtifacts(b: *std.Build, dep: *std.Build.Dependency, app_options: A
|
|
|
896
1453
|
b.fmt("zig-out/package/{s}", .{package_target_name}));
|
|
897
1454
|
package_run.addArg("--binary");
|
|
898
1455
|
package_run.addFileArg(exe.getEmittedBin());
|
|
1456
|
+
if (ts_stage) |stage| if (stage.service_exe) |service_exe| {
|
|
1457
|
+
package_run.addArg("--service-binary");
|
|
1458
|
+
package_run.addFileArg(service_exe);
|
|
1459
|
+
};
|
|
899
1460
|
// The archive and report names carry an optimize label; this
|
|
900
1461
|
// build graph knows the packaged binary's REAL mode, so forward
|
|
901
1462
|
// it instead of letting the CLI assume one.
|
|
@@ -962,7 +1523,7 @@ fn exampleOptimizeMode(b: *std.Build, requested: ?std.builtin.OptimizeMode, defa
|
|
|
962
1523
|
};
|
|
963
1524
|
}
|
|
964
1525
|
|
|
965
|
-
fn appModule(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, app_options: AppOptions, options_mod: *std.Build.Module, ts_stage: ?TsCoreStage) *std.Build.Module {
|
|
1526
|
+
fn appModule(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, app_options: AppOptions, options_mod: *std.Build.Module, ts_stage: ?TsCoreStage, relational_migrations: std.Build.LazyPath, app_config: AppManifestBuildConfig) *std.Build.Module {
|
|
966
1527
|
const native_sdk_mod = nativeSdkModuleWithTerminal(b, dep, target, optimize, app_options.terminal_sessions);
|
|
967
1528
|
const runner_mod = b.createModule(.{
|
|
968
1529
|
.root_source_file = dep.path("src/app_runner/root.zig"),
|
|
@@ -973,6 +1534,9 @@ fn appModule(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.Resolv
|
|
|
973
1534
|
runner_mod.addImport("native_sdk", native_sdk_mod);
|
|
974
1535
|
runner_mod.addImport("build_options", options_mod);
|
|
975
1536
|
runner_mod.addImport("app_manifest_zon", manifest_mod);
|
|
1537
|
+
const migration_mod = b.createModule(.{ .root_source_file = relational_migrations, .target = target, .optimize = optimize });
|
|
1538
|
+
migration_mod.addImport("native_sdk", native_sdk_mod);
|
|
1539
|
+
runner_mod.addImport("relational_migrations", migration_mod);
|
|
976
1540
|
|
|
977
1541
|
const app_mod = if (ts_stage) |stage|
|
|
978
1542
|
// TypeScript core: the app module roots at the staged generated
|
|
@@ -996,10 +1560,54 @@ fn appModule(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.Resolv
|
|
|
996
1560
|
// toolchain's runtime needs libc.
|
|
997
1561
|
app_mod.link_libc = true;
|
|
998
1562
|
app_mod.addObjectFile(stage.archive);
|
|
1563
|
+
// The in-process service archive links beside it (distinct symbol
|
|
1564
|
+
// prefix; its runtime internals are localized).
|
|
1565
|
+
if (stage.service_archive) |service_archive| app_mod.addObjectFile(service_archive);
|
|
1566
|
+
}
|
|
1567
|
+
if (app_config.sqlite_capability) {
|
|
1568
|
+
// `store` and the relational `sqlite` tier share this exact object.
|
|
1569
|
+
// The source is absent from every artifact declaring neither
|
|
1570
|
+
// capability, which keeps capability inference a real binary-size
|
|
1571
|
+
// boundary rather than a runtime flag.
|
|
1572
|
+
app_mod.addIncludePath(dep.path("third_party/sqlite"));
|
|
1573
|
+
app_mod.addCSourceFile(.{
|
|
1574
|
+
.file = dep.path("third_party/sqlite/sqlite3.c"),
|
|
1575
|
+
.flags = &sqlite_c_defines,
|
|
1576
|
+
});
|
|
1577
|
+
app_mod.link_libc = true;
|
|
999
1578
|
}
|
|
1579
|
+
addMacosPrivacyInfoPlist(b, app_mod, target, app_config);
|
|
1000
1580
|
return app_mod;
|
|
1001
1581
|
}
|
|
1002
1582
|
|
|
1583
|
+
/// Bare Mach-O executables launched by the dev loop do not have an app
|
|
1584
|
+
/// bundle's external Info.plist. macOS still requires capture usage strings
|
|
1585
|
+
/// before it will show the consent prompt, so put the permission-derived
|
|
1586
|
+
/// fragment in the conventional embedded section too. Packaged apps retain
|
|
1587
|
+
/// their richer external plist generated by package.zig.
|
|
1588
|
+
fn addMacosPrivacyInfoPlist(b: *std.Build, app_mod: *std.Build.Module, target: std.Build.ResolvedTarget, config: AppManifestBuildConfig) void {
|
|
1589
|
+
if (target.result.os.tag != .macos) return;
|
|
1590
|
+
if (!config.microphone_permission and !config.system_audio_permission) return;
|
|
1591
|
+
|
|
1592
|
+
const microphone = if (config.microphone_permission)
|
|
1593
|
+
" <key>NSMicrophoneUsageDescription</key>\\n <string>This app captures microphone audio when you start recording.</string>\\n"
|
|
1594
|
+
else
|
|
1595
|
+
"";
|
|
1596
|
+
const system_audio = if (config.system_audio_permission)
|
|
1597
|
+
" <key>NSAudioCaptureUsageDescription</key>\\n <string>This app captures system audio when you start recording.</string>\\n" ++
|
|
1598
|
+
" <key>NSScreenCaptureUsageDescription</key>\\n <string>This app captures system audio when you start recording.</string>\\n"
|
|
1599
|
+
else
|
|
1600
|
+
"";
|
|
1601
|
+
const source = b.fmt(
|
|
1602
|
+
\\#define NATIVE_SDK_INFO_PLIST "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" "<plist version=\"1.0\">\n<dict>\n{s}{s}</dict>\n</plist>\n"
|
|
1603
|
+
\\__attribute__((used, section("__TEXT,__info_plist")))
|
|
1604
|
+
\\static const unsigned char native_sdk_info_plist[sizeof(NATIVE_SDK_INFO_PLIST) - 1] = NATIVE_SDK_INFO_PLIST;
|
|
1605
|
+
\\
|
|
1606
|
+
, .{ microphone, system_audio });
|
|
1607
|
+
const generated = b.addWriteFiles().add("native_sdk_macos_info_plist.c", source);
|
|
1608
|
+
app_mod.addCSourceFile(.{ .file = generated, .flags = &.{} });
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1003
1611
|
fn nativeSdkTarget(b: *std.Build) std.Build.ResolvedTarget {
|
|
1004
1612
|
const target = b.standardTargetOptions(.{});
|
|
1005
1613
|
if (target.result.os.tag != .macos) return target;
|
|
@@ -1014,6 +1622,175 @@ fn nativeSdkTarget(b: *std.Build) std.Build.ResolvedTarget {
|
|
|
1014
1622
|
return b.resolveTargetQuery(query);
|
|
1015
1623
|
}
|
|
1016
1624
|
|
|
1625
|
+
const sqlite_c_defines = [_][]const u8{
|
|
1626
|
+
"-DSQLITE_THREADSAFE=2",
|
|
1627
|
+
"-DSQLITE_OMIT_LOAD_EXTENSION",
|
|
1628
|
+
"-DSQLITE_DQS=0",
|
|
1629
|
+
"-DSQLITE_ENABLE_FTS5",
|
|
1630
|
+
"-DSQLITE_ENABLE_JSON1",
|
|
1631
|
+
"-DSQLITE_ENABLE_UPDATE_HOOK",
|
|
1632
|
+
"-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1",
|
|
1633
|
+
"-DSQLITE_DEFAULT_MEMSTATUS=0",
|
|
1634
|
+
};
|
|
1635
|
+
|
|
1636
|
+
/// Zig deliberately supplies no libc headers for Apple/Android cross targets.
|
|
1637
|
+
/// Store-capable mobile libraries therefore compile the vendored amalgamation
|
|
1638
|
+
/// against the same platform SDK the host tier will use to link the archive.
|
|
1639
|
+
/// Desktop targets keep Zig's ordinary libc discovery.
|
|
1640
|
+
fn sqliteCFlags(b: *std.Build, target: std.Build.ResolvedTarget) []const []const u8 {
|
|
1641
|
+
if (target.result.os.tag == .ios) {
|
|
1642
|
+
const sysroot = b.sysroot orelse iosSdkPath(b, target.result.abi == .simulator) orelse
|
|
1643
|
+
std.debug.panic("a store-capable iOS library needs the Apple SDK; install Xcode or pass --sysroot <iphone SDK path>", .{});
|
|
1644
|
+
return b.dupeStrings(&.{
|
|
1645
|
+
sqlite_c_defines[0],
|
|
1646
|
+
sqlite_c_defines[1],
|
|
1647
|
+
sqlite_c_defines[2],
|
|
1648
|
+
sqlite_c_defines[3],
|
|
1649
|
+
sqlite_c_defines[4],
|
|
1650
|
+
sqlite_c_defines[5],
|
|
1651
|
+
sqlite_c_defines[6],
|
|
1652
|
+
sqlite_c_defines[7],
|
|
1653
|
+
"-isysroot",
|
|
1654
|
+
sysroot,
|
|
1655
|
+
b.fmt("-isystem{s}/usr/include", .{sysroot}),
|
|
1656
|
+
});
|
|
1657
|
+
}
|
|
1658
|
+
if (target.result.abi.isAndroid()) {
|
|
1659
|
+
const sysroot = b.sysroot orelse androidNdkSysrootPath(b) orelse
|
|
1660
|
+
std.debug.panic("a store-capable Android library needs the NDK; set ANDROID_NDK_ROOT or ANDROID_HOME, or pass --sysroot <NDK sysroot>", .{});
|
|
1661
|
+
const triple = target.result.linuxTriple(b.allocator) catch @panic("out of memory");
|
|
1662
|
+
return b.dupeStrings(&.{
|
|
1663
|
+
sqlite_c_defines[0],
|
|
1664
|
+
sqlite_c_defines[1],
|
|
1665
|
+
sqlite_c_defines[2],
|
|
1666
|
+
sqlite_c_defines[3],
|
|
1667
|
+
sqlite_c_defines[4],
|
|
1668
|
+
sqlite_c_defines[5],
|
|
1669
|
+
sqlite_c_defines[6],
|
|
1670
|
+
sqlite_c_defines[7],
|
|
1671
|
+
b.fmt("-isystem{s}/usr/include/{s}", .{ sysroot, triple }),
|
|
1672
|
+
b.fmt("-isystem{s}/usr/include", .{sysroot}),
|
|
1673
|
+
});
|
|
1674
|
+
}
|
|
1675
|
+
return &sqlite_c_defines;
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
fn iosSdkPath(b: *std.Build, simulator: bool) ?[]const u8 {
|
|
1679
|
+
const result = std.process.run(b.allocator, b.graph.io, .{
|
|
1680
|
+
.argv = &.{ "xcrun", "--sdk", if (simulator) "iphonesimulator" else "iphoneos", "--show-sdk-path" },
|
|
1681
|
+
.stdout_limit = .limited(4096),
|
|
1682
|
+
.stderr_limit = .limited(4096),
|
|
1683
|
+
}) catch return null;
|
|
1684
|
+
defer b.allocator.free(result.stderr);
|
|
1685
|
+
if (result.term != .exited or result.term.exited != 0) {
|
|
1686
|
+
b.allocator.free(result.stdout);
|
|
1687
|
+
return null;
|
|
1688
|
+
}
|
|
1689
|
+
return std.mem.trimEnd(u8, result.stdout, "\r\n");
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
fn androidNdkSysrootPath(b: *std.Build) ?[]const u8 {
|
|
1693
|
+
for ([_][]const u8{ "ANDROID_NDK_ROOT", "ANDROID_NDK_HOME", "ANDROID_NDK_LATEST_HOME" }) |name| {
|
|
1694
|
+
if (b.graph.environ_map.get(name)) |root| {
|
|
1695
|
+
if (root.len > 0) {
|
|
1696
|
+
if (ndkSysrootUnder(b, root)) |sysroot| return sysroot;
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
|
|
1701
|
+
const sdk_root = androidSdkRoot(b) orelse return null;
|
|
1702
|
+
const ndk_root = latestVersionSubdir(b, sdk_root, "ndk") orelse blk: {
|
|
1703
|
+
const legacy = b.pathJoin(&.{ sdk_root, "ndk-bundle" });
|
|
1704
|
+
break :blk if (buildDirExists(b, legacy)) legacy else return null;
|
|
1705
|
+
};
|
|
1706
|
+
return ndkSysrootUnder(b, ndk_root);
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
fn androidSdkRoot(b: *std.Build) ?[]const u8 {
|
|
1710
|
+
for ([_][]const u8{ "ANDROID_HOME", "ANDROID_SDK_ROOT" }) |name| {
|
|
1711
|
+
if (b.graph.environ_map.get(name)) |root| {
|
|
1712
|
+
if (root.len > 0 and buildDirExists(b, root)) return root;
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
return switch (builtin.os.tag) {
|
|
1716
|
+
.macos => if (b.graph.environ_map.get("HOME")) |home|
|
|
1717
|
+
b.pathJoin(&.{ home, "Library", "Android", "sdk" })
|
|
1718
|
+
else
|
|
1719
|
+
null,
|
|
1720
|
+
.windows => if (b.graph.environ_map.get("LOCALAPPDATA")) |local_app_data|
|
|
1721
|
+
b.pathJoin(&.{ local_app_data, "Android", "Sdk" })
|
|
1722
|
+
else
|
|
1723
|
+
null,
|
|
1724
|
+
else => if (b.graph.environ_map.get("HOME")) |home|
|
|
1725
|
+
b.pathJoin(&.{ home, "Android", "Sdk" })
|
|
1726
|
+
else
|
|
1727
|
+
null,
|
|
1728
|
+
};
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
fn ndkSysrootUnder(b: *std.Build, ndk_root: []const u8) ?[]const u8 {
|
|
1732
|
+
const prebuilt_path = b.pathJoin(&.{ ndk_root, "toolchains", "llvm", "prebuilt" });
|
|
1733
|
+
var cwd = std.Io.Dir.cwd();
|
|
1734
|
+
var dir = cwd.openDir(b.graph.io, prebuilt_path, .{ .iterate = true }) catch return null;
|
|
1735
|
+
defer dir.close(b.graph.io);
|
|
1736
|
+
var iterator = dir.iterate();
|
|
1737
|
+
while (iterator.next(b.graph.io) catch return null) |entry| {
|
|
1738
|
+
if (entry.kind != .directory) continue;
|
|
1739
|
+
const sysroot = b.pathJoin(&.{ prebuilt_path, entry.name, "sysroot" });
|
|
1740
|
+
if (buildDirExists(b, b.pathJoin(&.{ sysroot, "usr", "include" }))) return sysroot;
|
|
1741
|
+
}
|
|
1742
|
+
return null;
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1745
|
+
fn latestVersionSubdir(b: *std.Build, root: []const u8, parent: []const u8) ?[]const u8 {
|
|
1746
|
+
const parent_path = b.pathJoin(&.{ root, parent });
|
|
1747
|
+
var cwd = std.Io.Dir.cwd();
|
|
1748
|
+
var dir = cwd.openDir(b.graph.io, parent_path, .{ .iterate = true }) catch return null;
|
|
1749
|
+
defer dir.close(b.graph.io);
|
|
1750
|
+
var best: ?[]const u8 = null;
|
|
1751
|
+
defer if (best) |name| b.allocator.free(name);
|
|
1752
|
+
var iterator = dir.iterate();
|
|
1753
|
+
while (iterator.next(b.graph.io) catch return null) |entry| {
|
|
1754
|
+
if (entry.kind != .directory) continue;
|
|
1755
|
+
if (best) |current| {
|
|
1756
|
+
if (!versionLess(current, entry.name)) continue;
|
|
1757
|
+
b.allocator.free(current);
|
|
1758
|
+
best = null;
|
|
1759
|
+
}
|
|
1760
|
+
best = b.allocator.dupe(u8, entry.name) catch @panic("out of memory");
|
|
1761
|
+
}
|
|
1762
|
+
const name = best orelse return null;
|
|
1763
|
+
return b.pathJoin(&.{ parent_path, name });
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
fn versionLess(a: []const u8, b: []const u8) bool {
|
|
1767
|
+
var a_parts = std.mem.splitScalar(u8, a, '.');
|
|
1768
|
+
var b_parts = std.mem.splitScalar(u8, b, '.');
|
|
1769
|
+
while (true) {
|
|
1770
|
+
const a_part = a_parts.next();
|
|
1771
|
+
const b_part = b_parts.next();
|
|
1772
|
+
if (a_part == null and b_part == null) return false;
|
|
1773
|
+
if (a_part == null) return true;
|
|
1774
|
+
if (b_part == null) return false;
|
|
1775
|
+
const a_num = std.fmt.parseUnsigned(u64, a_part.?, 10) catch null;
|
|
1776
|
+
const b_num = std.fmt.parseUnsigned(u64, b_part.?, 10) catch null;
|
|
1777
|
+
if (a_num != null and b_num != null) {
|
|
1778
|
+
if (a_num.? != b_num.?) return a_num.? < b_num.?;
|
|
1779
|
+
} else switch (std.mem.order(u8, a_part.?, b_part.?)) {
|
|
1780
|
+
.lt => return true,
|
|
1781
|
+
.gt => return false,
|
|
1782
|
+
.eq => {},
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
|
|
1787
|
+
fn buildDirExists(b: *std.Build, path: []const u8) bool {
|
|
1788
|
+
var cwd = std.Io.Dir.cwd();
|
|
1789
|
+
var dir = cwd.openDir(b.graph.io, path, .{}) catch return false;
|
|
1790
|
+
dir.close(b.graph.io);
|
|
1791
|
+
return true;
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1017
1794
|
fn macosSdkPath(b: *std.Build) ?[]const u8 {
|
|
1018
1795
|
if (b.graph.environ_map.get("SDKROOT")) |sdkroot| {
|
|
1019
1796
|
if (sdkroot.len > 0) return sdkroot;
|
|
@@ -1061,6 +1838,10 @@ fn nativeSdkModuleWithTerminal(b: *std.Build, dep: *std.Build.Dependency, target
|
|
|
1061
1838
|
debug_mod.addImport("trace", trace_mod);
|
|
1062
1839
|
|
|
1063
1840
|
const native_sdk_mod = externalModule(b, dep, target, optimize, "src/root.zig");
|
|
1841
|
+
// The header makes the internal wrapper parsable even when lazy exports
|
|
1842
|
+
// are reflected; the amalgamation itself is attached below only for an
|
|
1843
|
+
// opted-in store/sqlite artifact.
|
|
1844
|
+
native_sdk_mod.addIncludePath(dep.path("third_party/sqlite"));
|
|
1064
1845
|
native_sdk_mod.addImport("geometry", geometry_mod);
|
|
1065
1846
|
native_sdk_mod.addImport("assets", assets_mod);
|
|
1066
1847
|
native_sdk_mod.addImport("app_dirs", app_dirs_mod);
|
|
@@ -1156,6 +1937,8 @@ fn linkPlatform(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.Res
|
|
|
1156
1937
|
app_mod.linkFramework("AppKit", .{});
|
|
1157
1938
|
// The audio playback service (the AppKit host's single AVPlayer).
|
|
1158
1939
|
app_mod.linkFramework("AVFoundation", .{});
|
|
1940
|
+
app_mod.linkFramework("CoreMedia", .{});
|
|
1941
|
+
app_mod.linkFramework("ScreenCaptureKit", .{ .weak = true });
|
|
1159
1942
|
// CVPixelBuffer for the video frame path (the video player's
|
|
1160
1943
|
// AVPlayerItemVideoOutput frames). CoreMedia's CMTime use stays
|
|
1161
1944
|
// header-only, but the pixel-buffer calls are real symbols.
|
|
@@ -1289,6 +2072,13 @@ fn linkPlatform(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.Res
|
|
|
1289
2072
|
app_mod.linkSystemLibrary("ole32", .{});
|
|
1290
2073
|
app_mod.linkSystemLibrary("oleacc", .{});
|
|
1291
2074
|
app_mod.linkSystemLibrary("shell32", .{});
|
|
2075
|
+
// TypeScript cores link ScriptC's host runtime, whose network-interface
|
|
2076
|
+
// helpers use GetAdaptersAddresses and Winsock address conversion; the
|
|
2077
|
+
// in-process service archive shares the same runtime and additionally
|
|
2078
|
+
// reaches advapi32 (crypto-backed randomness).
|
|
2079
|
+
app_mod.linkSystemLibrary("iphlpapi", .{});
|
|
2080
|
+
app_mod.linkSystemLibrary("ws2_32", .{});
|
|
2081
|
+
app_mod.linkSystemLibrary("advapi32", .{});
|
|
1292
2082
|
// The audio backend: Media Foundation (session + source resolver
|
|
1293
2083
|
// + streaming audio renderer) and WinHTTP (the cache fill).
|
|
1294
2084
|
app_mod.linkSystemLibrary("mf", .{});
|
|
@@ -1381,22 +2171,43 @@ fn addCefCheck(b: *std.Build, target: std.Build.ResolvedTarget, cef_dir: []const
|
|
|
1381
2171
|
/// manifest falls back to the system engine WITH the web layer kept —
|
|
1382
2172
|
/// over-inclusion is a size cost, wrong exclusion is a broken app.
|
|
1383
2173
|
const AppManifestBuildConfig = struct {
|
|
2174
|
+
app_id: []const u8 = "dev.native_sdk.app",
|
|
1384
2175
|
web_engine: WebEngineOption = .system,
|
|
1385
2176
|
cef_dir: []const u8 = "third_party/cef/macos",
|
|
1386
2177
|
cef_auto_install: bool = false,
|
|
1387
2178
|
webview_layer: WebLayerOption = .auto,
|
|
2179
|
+
microphone_permission: bool = false,
|
|
2180
|
+
system_audio_permission: bool = false,
|
|
2181
|
+
persist_capability: bool = false,
|
|
2182
|
+
persist_version: ?u64 = null,
|
|
2183
|
+
service_packages: []const ServicePackageConfig = &.{},
|
|
2184
|
+
service_carrier: []const u8 = "auto",
|
|
2185
|
+
service_pool_size: ?u8 = null,
|
|
2186
|
+
store_capability: bool = false,
|
|
2187
|
+
relational_capability: bool = false,
|
|
2188
|
+
credentials_capability: bool = false,
|
|
2189
|
+
credentials_permission: bool = false,
|
|
2190
|
+
sqlite_capability: bool = false,
|
|
1388
2191
|
/// The first web declaration found (for teaching messages), or null
|
|
1389
2192
|
/// when app.zon declares no web use. `web_engine = "system"` alone is
|
|
1390
2193
|
/// NOT web intent — it is the default in many canvas manifests.
|
|
1391
2194
|
web_declaration: ?web_layer_contract.Declaration = null,
|
|
1392
2195
|
};
|
|
1393
2196
|
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
2197
|
+
const ServicePackageConfig = struct {
|
|
2198
|
+
name: []const u8,
|
|
2199
|
+
version: []const u8,
|
|
2200
|
+
content_hash: []const u8,
|
|
2201
|
+
};
|
|
2202
|
+
|
|
2203
|
+
/// The lenient app.zon shape the build graph parses for inference: web
|
|
2204
|
+
/// inclusion, permissions, and the persistence capability/version handed to
|
|
2205
|
+
/// the TypeScript checker. Everything else is ignored. Full schema validation
|
|
2206
|
+
/// stays with `native validate` and the runner's comptime import.
|
|
1398
2207
|
const InferenceManifest = struct {
|
|
2208
|
+
id: []const u8 = "dev.native_sdk.app",
|
|
1399
2209
|
capabilities: []const []const u8 = &.{},
|
|
2210
|
+
permissions: []const []const u8 = &.{},
|
|
1400
2211
|
web_engine: []const u8 = "system",
|
|
1401
2212
|
webview_layer: []const u8 = "auto",
|
|
1402
2213
|
core_compiler: []const u8 = "external",
|
|
@@ -1405,6 +2216,12 @@ const InferenceManifest = struct {
|
|
|
1405
2216
|
auto_install: bool = false,
|
|
1406
2217
|
} = .{},
|
|
1407
2218
|
frontend: ?struct {} = null,
|
|
2219
|
+
persist: ?struct {
|
|
2220
|
+
version: u64,
|
|
2221
|
+
} = null,
|
|
2222
|
+
service_packages: []const ServicePackageConfig = &.{},
|
|
2223
|
+
service_carrier: []const u8 = "auto",
|
|
2224
|
+
service_pool_size: u8 = 0,
|
|
1408
2225
|
shell: struct {
|
|
1409
2226
|
windows: []const struct {
|
|
1410
2227
|
views: []const struct {
|
|
@@ -1447,14 +2264,41 @@ fn appManifestBuildConfig(b: *std.Build, app_root: []const u8) AppManifestBuildC
|
|
|
1447
2264
|
@panic("\napp.zon .core_compiler must be \"external\" (the default and only lane)\n");
|
|
1448
2265
|
}
|
|
1449
2266
|
return .{
|
|
2267
|
+
.app_id = raw.id,
|
|
1450
2268
|
.web_engine = web_layer_contract.parseWebEngine(raw.web_engine) orelse .system,
|
|
1451
2269
|
.cef_dir = raw.cef.dir,
|
|
1452
2270
|
.cef_auto_install = raw.cef.auto_install,
|
|
1453
2271
|
.webview_layer = web_layer_contract.parseWebViewLayer(raw.webview_layer) orelse @panic("app.zon .webview_layer must be \"auto\", \"include\", or \"exclude\""),
|
|
2272
|
+
.microphone_permission = hasManifestPermission(raw.permissions, "microphone"),
|
|
2273
|
+
.system_audio_permission = hasManifestPermission(raw.permissions, "system_audio"),
|
|
2274
|
+
.persist_capability = hasManifestCapability(raw.capabilities, "persist"),
|
|
2275
|
+
.persist_version = if (raw.persist) |persist| persist.version else null,
|
|
2276
|
+
.service_packages = raw.service_packages,
|
|
2277
|
+
.service_carrier = raw.service_carrier,
|
|
2278
|
+
.service_pool_size = if (raw.service_pool_size == 0) null else raw.service_pool_size,
|
|
2279
|
+
.store_capability = hasManifestCapability(raw.capabilities, "store"),
|
|
2280
|
+
.relational_capability = hasManifestCapability(raw.capabilities, "sqlite"),
|
|
2281
|
+
.credentials_capability = hasManifestCapability(raw.capabilities, "credentials"),
|
|
2282
|
+
.credentials_permission = hasManifestPermission(raw.permissions, "credentials"),
|
|
2283
|
+
.sqlite_capability = hasManifestCapability(raw.capabilities, "store") or hasManifestCapability(raw.capabilities, "sqlite"),
|
|
1454
2284
|
.web_declaration = web_layer_contract.manifestDeclaration(raw),
|
|
1455
2285
|
};
|
|
1456
2286
|
}
|
|
1457
2287
|
|
|
2288
|
+
fn hasManifestPermission(permissions: []const []const u8, expected: []const u8) bool {
|
|
2289
|
+
for (permissions) |permission| {
|
|
2290
|
+
if (std.mem.eql(u8, permission, expected)) return true;
|
|
2291
|
+
}
|
|
2292
|
+
return false;
|
|
2293
|
+
}
|
|
2294
|
+
|
|
2295
|
+
fn hasManifestCapability(capabilities: []const []const u8, expected: []const u8) bool {
|
|
2296
|
+
for (capabilities) |capability| {
|
|
2297
|
+
if (std.mem.eql(u8, capability, expected)) return true;
|
|
2298
|
+
}
|
|
2299
|
+
return false;
|
|
2300
|
+
}
|
|
2301
|
+
|
|
1458
2302
|
/// The web-layer decision for this build: the shared contract fed this
|
|
1459
2303
|
/// boundary's inputs — the manifest declarations from the lenient parse
|
|
1460
2304
|
/// and the engine RESOLVED from `-Dweb-engine` orelse app.zon. WEB means
|