@native-sdk/cli 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +4 -4
  2. package/assets/icon.icns +0 -0
  3. package/assets/icon.ico +0 -0
  4. package/assets/icon.png +0 -0
  5. package/assets/icon.svg +15 -0
  6. package/assets/native-sdk.entitlements +10 -0
  7. package/assets/native-sdk.manifest +28 -0
  8. package/build/app.zig +40 -1
  9. package/build.zig +50 -4
  10. package/package.json +13 -11
  11. package/src/platform/macos/appkit_host.m +21 -6
  12. package/src/platform/windows/webview2_host.cpp +377 -72
  13. package/src/primitives/canvas/chart.zig +8 -7
  14. package/src/primitives/canvas/chart_tests.zig +2 -2
  15. package/src/primitives/canvas/commands.zig +27 -0
  16. package/src/primitives/canvas/gpu.zig +8 -0
  17. package/src/primitives/canvas/markdown_tests.zig +1 -1
  18. package/src/primitives/canvas/reference.zig +82 -3
  19. package/src/primitives/canvas/reference_tests.zig +155 -1
  20. package/src/primitives/canvas/serialization.zig +16 -3
  21. package/src/primitives/canvas/themes/geist.zig +6 -0
  22. package/src/primitives/canvas/tokens.zig +7 -0
  23. package/src/primitives/canvas/widget_builtin_tests.zig +191 -0
  24. package/src/primitives/canvas/widget_render.zig +29 -41
  25. package/src/primitives/canvas/widget_render_controls.zig +55 -42
  26. package/src/primitives/canvas/widget_render_style.zig +53 -0
  27. package/src/primitives/canvas/widget_render_surfaces.zig +19 -18
  28. package/src/primitives/canvas/widget_runtime_tests.zig +20 -21
  29. package/src/runtime/canvas_frame_packet_tests.zig +9 -1
  30. package/src/runtime/canvas_frame_patch_tests.zig +39 -1
  31. package/src/runtime/canvas_widget_control_tests.zig +4 -4
  32. package/src/runtime/ui_app.zig +78 -10
  33. package/src/runtime/ui_app_tests.zig +111 -2
  34. package/src/runtime/ui_app_window_tests.zig +93 -0
  35. package/src/tooling/cef.zig +1 -1
  36. package/src/tooling/package.zig +45 -0
  37. package/src/tooling/templates.zig +46 -5
  38. package/third_party/webview2/LICENSE.txt +27 -0
  39. package/third_party/webview2/README.md +19 -0
  40. package/third_party/webview2/arm64/WebView2Loader.dll +0 -0
  41. package/third_party/webview2/include/EventToken.h +12 -0
  42. package/third_party/webview2/include/WebView2.h +60636 -0
  43. package/third_party/webview2/x64/WebView2Loader.dll +0 -0
@@ -703,7 +703,7 @@ fn nativeCiYaml(allocator: std.mem.Allocator, names: TemplateNames, framework_pa
703
703
  \\ - name: Fetch native-sdk
704
704
  \\ run: |
705
705
  \\ if [ ! -f "$NATIVE_SDK_PATH/build.zig" ]; then
706
- \\ git clone --depth 1 https://github.com/vercel-labs/zero-native.git "$NATIVE_SDK_PATH"
706
+ \\ git clone --depth 1 https://github.com/vercel-labs/native.git "$NATIVE_SDK_PATH"
707
707
  \\ fi
708
708
  \\ - run: zig build test -Dplatform=null
709
709
  \\
@@ -720,7 +720,7 @@ fn nativeCiYaml(allocator: std.mem.Allocator, names: TemplateNames, framework_pa
720
720
  \\ - name: Fetch native-sdk
721
721
  \\ run: |
722
722
  \\ if [ ! -f "$NATIVE_SDK_PATH/build.zig" ]; then
723
- \\ git clone --depth 1 https://github.com/vercel-labs/zero-native.git "$NATIVE_SDK_PATH"
723
+ \\ git clone --depth 1 https://github.com/vercel-labs/native.git "$NATIVE_SDK_PATH"
724
724
  \\ fi
725
725
  \\ - name: Build the Native SDK CLI
726
726
  \\ run: cd "$NATIVE_SDK_PATH" && zig build
@@ -782,7 +782,7 @@ fn frontendCiYaml(allocator: std.mem.Allocator, names: TemplateNames) ![]const u
782
782
  \\ - name: Fetch native-sdk
783
783
  \\ run: |
784
784
  \\ if [ ! -f "$NATIVE_SDK_PATH/build.zig" ]; then
785
- \\ git clone --depth 1 https://github.com/vercel-labs/zero-native.git "$NATIVE_SDK_PATH"
785
+ \\ git clone --depth 1 https://github.com/vercel-labs/native.git "$NATIVE_SDK_PATH"
786
786
  \\ fi
787
787
  \\ - run: zig build test -Dplatform=null -Dnative-sdk-path="$NATIVE_SDK_PATH"
788
788
  \\
@@ -944,11 +944,13 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
944
944
  \\ const run = b.addRunArtifact(exe);
945
945
  \\ run.step.dependOn(&frontend_build.step);
946
946
  \\ addCefRuntimeRunFiles(b, target, run, exe, web_engine, cef_dir);
947
+ \\ addWebView2RuntimeRunFiles(b, target, run, web_engine, native_sdk_path);
947
948
  \\ const run_step = b.step("run", "Run the app");
948
949
  \\ run_step.dependOn(&run.step);
949
950
  \\
950
951
  \\ const dev = b.addSystemCommand(&.{ "native", "dev", "--manifest", "app.zon", "--binary" });
951
952
  \\ dev.addFileArg(exe.getEmittedBin());
953
+ \\ addWebView2RuntimeRunFiles(b, target, dev, web_engine, native_sdk_path);
952
954
  \\ dev.step.dependOn(&exe.step);
953
955
  \\ dev.step.dependOn(&frontend_install.step);
954
956
  \\ const dev_step = b.step("dev", "Run the frontend dev server and native shell");
@@ -972,6 +974,11 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
972
974
  \\ b.fmt("zig-out/package/{s}-0.1.0-{s}-{s}{s}", .{ app_exe_name, @tagName(package_target), optimize_name, packageSuffix(package_target) }),
973
975
  \\ "--binary",
974
976
  \\ });
977
+ \\ // The CLI resolves SDK-owned package inputs (the vendored WebView2
978
+ \\ // loader) from the framework root; a PATH-resolved `native` could
979
+ \\ // belong to a different checkout than the one this build compiled
980
+ \\ // against, so hand the same root over explicitly.
981
+ \\ package.setEnvironmentVariable("NATIVE_SDK_PATH", b.pathFromRoot(native_sdk_path));
975
982
  \\ package.addFileArg(exe.getEmittedBin());
976
983
  \\ package.addArgs(&.{ "--web-engine", @tagName(web_engine), "--cef-dir", cef_dir });
977
984
  \\ if (cef_auto_install) package.addArg("--cef-auto-install");
@@ -1139,7 +1146,19 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
1139
1146
  \\ if (web_engine == .chromium) app_mod.linkSystemLibrary("stdc++", .{});
1140
1147
  \\ } else if (platform == .windows) {
1141
1148
  \\ switch (web_engine) {
1142
- \\ .system => app_mod.addCSourceFile(.{ .file = nativeSdkPath(b, native_sdk_path, "src/platform/windows/webview2_host.cpp"), .flags = &.{ "-std=c++17" } }),
1149
+ \\ .system => {
1150
+ \\ // The vendored WebView2 SDK header (third_party/webview2)
1151
+ \\ // turns on the host's embedded-WebView layer; the host
1152
+ \\ // fails the compile by design if it cannot be found.
1153
+ \\ app_mod.addIncludePath(nativeSdkPath(b, native_sdk_path, "third_party/webview2/include"));
1154
+ \\ app_mod.addCSourceFile(.{ .file = nativeSdkPath(b, native_sdk_path, "src/platform/windows/webview2_host.cpp"), .flags = &.{ "-std=c++17" } });
1155
+ \\ // WebView2Loader.dll rides next to the installed app
1156
+ \\ // executable: the host loads it at runtime to discover
1157
+ \\ // the machine's WebView2 runtime. Canvas apps never
1158
+ \\ // touch it.
1159
+ \\ const loader = b.addInstallBinFile(nativeSdkPath(b, native_sdk_path, webView2LoaderSubPath(target)), "WebView2Loader.dll");
1160
+ \\ b.getInstallStep().dependOn(&loader.step);
1161
+ \\ },
1143
1162
  \\ .chromium => {
1144
1163
  \\ const cef_check = addCefCheck(b, target, cef_dir);
1145
1164
  \\ if (cef_auto_install) {
@@ -1172,6 +1191,26 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path:
1172
1191
  \\ }
1173
1192
  \\}
1174
1193
  \\
1194
+ \\/// The vendored WebView2Loader.dll for the target architecture, relative
1195
+ \\/// to the framework root.
1196
+ \\fn webView2LoaderSubPath(target: std.Build.ResolvedTarget) []const u8 {
1197
+ \\ return if (target.result.cpu.arch == .aarch64)
1198
+ \\ "third_party/webview2/arm64/WebView2Loader.dll"
1199
+ \\ else
1200
+ \\ "third_party/webview2/x64/WebView2Loader.dll";
1201
+ \\}
1202
+ \\
1203
+ \\/// `zig build run` and `zig build dev` execute the cached artifact, which
1204
+ \\/// has no installed WebView2Loader.dll beside it; the vendored loader's
1205
+ \\/// directory goes on the step's PATH so the host's LoadLibrary resolves it
1206
+ \\/// (`native dev` passes its environment on to the app it spawns).
1207
+ \\fn addWebView2RuntimeRunFiles(b: *std.Build, target: std.Build.ResolvedTarget, run: *std.Build.Step.Run, web_engine: WebEngineOption, native_sdk_path: []const u8) void {
1208
+ \\ if (web_engine != .system) return;
1209
+ \\ if (target.result.os.tag != .windows) return;
1210
+ \\ const loader_dir = std.fs.path.dirname(webView2LoaderSubPath(target)).?;
1211
+ \\ run.addPathDir(b.pathFromRoot(b.pathJoin(&.{ native_sdk_path, loader_dir })));
1212
+ \\}
1213
+ \\
1175
1214
  \\fn addCefRuntimeRunFiles(b: *std.Build, target: std.Build.ResolvedTarget, run: *std.Build.Step.Run, exe: *std.Build.Step.Compile, web_engine: WebEngineOption, cef_dir: []const u8) void {
1176
1215
  \\ if (web_engine != .chromium) return;
1177
1216
  \\ if (target.result.os.tag != .macos) return;
@@ -2835,6 +2874,8 @@ test "writeDefaultApp emits Vite project files" {
2835
2874
  try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "frontend_build.step.dependOn(&frontend_install.step)") != null);
2836
2875
  try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "\"native\", \"dev\"") != null);
2837
2876
  try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "dev.step.dependOn(&frontend_install.step)") != null);
2877
+ try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "addWebView2RuntimeRunFiles(b, target, dev, web_engine, native_sdk_path)") != null);
2878
+ try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "package.setEnvironmentVariable(\"NATIVE_SDK_PATH\", b.pathFromRoot(native_sdk_path))") != null);
2838
2879
  try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "chromium") != null);
2839
2880
  try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "cef-dir") != null);
2840
2881
  try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "src/platform/macos/cef_host.mm") != null);
@@ -3001,7 +3042,7 @@ test "writeDefaultApp emits a CI workflow for native apps" {
3001
3042
  try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "test -s .zig-cache/native-sdk-automation/screenshot-main-canvas.png") != null);
3002
3043
  // The framework fetch step reuses the build.zig.zon dependency path.
3003
3044
  try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "NATIVE_SDK_PATH:") != null);
3004
- try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "git clone --depth 1 https://github.com/vercel-labs/zero-native.git \"$NATIVE_SDK_PATH\"") != null);
3045
+ try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "git clone --depth 1 https://github.com/vercel-labs/native.git \"$NATIVE_SDK_PATH\"") != null);
3005
3046
  }
3006
3047
 
3007
3048
  /// Structural sanity for generated workflows (the repo scaffold CI job runs
@@ -0,0 +1,27 @@
1
+ Copyright (C) Microsoft Corporation. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions are
5
+ met:
6
+
7
+ * Redistributions of source code must retain the above copyright
8
+ notice, this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above
10
+ copyright notice, this list of conditions and the following disclaimer
11
+ in the documentation and/or other materials provided with the
12
+ distribution.
13
+ * The name of Microsoft Corporation, or the names of its contributors
14
+ may not be used to endorse or promote products derived from this
15
+ software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,19 @@
1
+ # WebView2 SDK Vendor Layout
2
+
3
+ The Windows system web engine embeds the OS WebView2 runtime. The interface header and the loader library that discovers the installed runtime come from the WebView2 SDK NuGet package and are vendored here so a repo checkout builds the real embedded-WebView Windows host with no extra fetch step.
4
+
5
+ Vendored from the `Microsoft.Web.WebView2` NuGet package, version `1.0.2903.40` (package sha256 `ef128016dd1e51c59178c827ed5b8aa3322c57afa8675d930f8109505542ad74`), under the package's BSD-style license (`LICENSE.txt`, kept verbatim alongside the files it covers):
6
+
7
+ ```text
8
+ third_party/webview2/
9
+ LICENSE.txt package LICENSE.txt, verbatim
10
+ include/WebView2.h build/native/include/WebView2.h, verbatim
11
+ x64/WebView2Loader.dll build/native/x64/WebView2Loader.dll, verbatim
12
+ arm64/WebView2Loader.dll build/native/arm64/WebView2Loader.dll, verbatim
13
+ ```
14
+
15
+ `include/EventToken.h` is a first-party compatibility shim (see its header comment), not a package file.
16
+
17
+ The build adds `include/` to the include path of the Windows host and stages the architecture's `WebView2Loader.dll` next to the app executable; the host loads it at runtime to locate the installed WebView2 runtime (preinstalled on stock Windows 11; on older machines the Evergreen runtime installer provides it). Apps that never load a WebView run fine without either piece.
18
+
19
+ To update: download a newer `Microsoft.Web.WebView2` package from NuGet, replace the files listed above verbatim, and record the new version and package sha256 here.
@@ -0,0 +1,12 @@
1
+ /* First-party compatibility shim, not part of the WebView2 SDK package:
2
+ * WebView2.h includes "EventToken.h" for this one struct, and the
3
+ * mingw-w64 headers zig ships do not carry that file. The layout is the
4
+ * OS ABI's event-registration cookie — a single 64-bit value. */
5
+ #ifndef __EVENTTOKEN_H__
6
+ #define __EVENTTOKEN_H__
7
+
8
+ typedef struct EventRegistrationToken {
9
+ __int64 value;
10
+ } EventRegistrationToken;
11
+
12
+ #endif