Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/src/app/web-engines/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ zero-native has one app/runtime API and selectable web engine backends. The defa
</tr>
<tr>
<td>Windows</td>
<td>In progress</td>
<td>WebView2</td>
<td>In progress</td>
</tr>
</tbody>
Expand All @@ -41,6 +41,8 @@ The intended parity contract is the same Zig app model, same runtime services, s

System mode has no bundled browser dependency. It uses the OS web engine, so rendering and web platform support follow the user's installed OS.

On Windows the system engine uses the WebView2 Runtime (included with Windows 11, available on Windows 10 via the evergreen runtime). The build looks for `<WebView2.h>` at `third_party/webview2-sdk/build/native/include` by default; pass `-Dwebview2-sdk-dir` to use a different path.

## Chromium (CEF)

Set the app engine once:
Expand Down Expand Up @@ -108,6 +110,10 @@ Core maintainers can build CEF from source with `tools/cef/build-from-source.sh`
<td><code>-Dcef-auto-install=true</code></td>
<td>Temporarily opt into running <code>zero-native cef install</code> during Chromium builds when CEF is missing.</td>
</tr>
<tr>
<td><code>-Dwebview2-sdk-dir=path</code></td>
<td>Windows only. Path to the WebView2 SDK root directory containing <code>build/native/include</code>. When omitted, defaults to <code>third_party/webview2-sdk</code>.</td>
</tr>
</tbody>
</table>

Expand Down
7 changes: 7 additions & 0 deletions docs/src/app/windows-build/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { pageMetadata } from "@/lib/page-metadata";

export const metadata = pageMetadata("windows-build");

export default function Layout({ children }: { children: React.ReactNode }) {
return children;
}
98 changes: 98 additions & 0 deletions docs/src/app/windows-build/page.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Windows Build

zero-native supports Windows via the WebView2 Runtime. The system engine uses WebView2.

## Prerequisites

- Windows 10 or later with the [WebView2 Runtime](https://developer.microsoft.com/en-us/microsoft-edge/webview2/) (included with Windows 11)
- [Zig](https://ziglang.org/download/) 0.16.0 or later

## Building

```sh
zig build run -Dplatform=windows
```

This installs frontend dependencies, builds assets, compiles the binary, and runs the app.

## WebView2 SDK

The generated project looks for the WebView2 SDK at `third_party/webview2-sdk/` by default. You need to vendor the SDK there (one-time setup per project).

### Acquiring the SDK

The WebView2 SDK is distributed as a NuGet package. Download and extract it with PowerShell:

```bash
Invoke-WebRequest -Uri https://www.nuget.org/api/v2/package/Microsoft.Web.WebView2/1.0.3351.48 -OutFile webview2.zip
New-Item -ItemType Directory -Path third_party/webview2-sdk -Force
Expand-Archive -Path webview2.zip -DestinationPath third_party/webview2-sdk
Remove-Item webview2.zip
```

`WebView2.h` includes `EventToken.h` (a standard Windows SDK header not shipped in the NuGet). Create it at `third_party/webview2-sdk/build/native/include/EventToken.h`:

```c
#ifndef _EVENTTOKEN_H_
#define _EVENTTOKEN_H_

#ifdef __cplusplus
extern "C" {
#endif

typedef struct EventRegistrationToken {
__int64 value;
} EventRegistrationToken;

#ifdef __cplusplus
}
#endif

#endif
```

> This file is normally provided by the Windows SDK. The workaround above is only needed when vendoring the NuGet without Visual Studio or the standalone Windows SDK installed.

Once vendored, no extra flags are needed:

```sh
zig build run -Dplatform=windows
```

To use a different SDK path instead of the default, pass `-Dwebview2-sdk-dir`:

```sh
zig build run -Dplatform=windows -Dwebview2-sdk-dir=path/to/sdk
```

## App Manifest

The generated `app.zon` includes `"windows"` in `.platforms` and a `.windows` window configuration:

```zig
.platforms = .{ "macos", "linux", "windows" },
.windows = .{
.{ .label = "main", .title = "My App", .width = 720, .height = 480, .restore_state = true },
},
```

## Packaging

```sh
zig build package -Dplatform=windows -Dpackage-target=windows
```

Creates a self-contained directory with the binary and assets under `zig-out/package/`. The binary resolves assets relative to its own location inside the package, so the package can be moved as a whole.

To override the frontend directory at runtime, set `ZERO_NATIVE_FRONTEND_DIR`:

```sh
set ZERO_NATIVE_FRONTEND_DIR=C:\path\to\dist
testing22.exe
```

## Diagnostics

```sh
zero-native doctor --manifest app.zon --web-engine system
```
1 change: 1 addition & 0 deletions docs/src/lib/docs-navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const navSections: NavSection[] = [
title: "Core Concepts",
items: [
{ name: "Web Engines", href: "/web-engines" },
{ name: "Windows Build", href: "/windows-build" },
{ name: "Windows", href: "/windows" },
{ name: "Bridge", href: "/bridge" },
{ name: "Builtin Commands", href: "/bridge/builtin-commands" },
Expand Down
1 change: 1 addition & 0 deletions docs/src/lib/page-titles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const PAGE_TITLES: Record<string, string> = {
extensions: "Extensions",
embed: "Embedded App",
"web-engines": "Web Engines",
"windows-build": "Windows Build",
packages: "Package Distribution",
};

Expand Down
2 changes: 1 addition & 1 deletion examples/hello/app.zon
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.display_name = "Hello",
.version = "0.1.0",
.icons = .{ "assets/icon.icns" },
.platforms = .{ "macos", "linux" },
.platforms = .{ "macos", "linux", "windows" },
.permissions = .{},
.capabilities = .{ "webview" },
.security = .{
Expand Down
2 changes: 1 addition & 1 deletion examples/next/app.zon
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.display_name = "Next Example",
.version = "0.1.0",
.icons = .{ "assets/icon.icns" },
.platforms = .{ "macos", "linux" },
.platforms = .{ "macos", "linux", "windows" },
.permissions = .{},
.capabilities = .{ "webview" },
.frontend = .{
Expand Down
2 changes: 1 addition & 1 deletion examples/react/app.zon
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.display_name = "React Example",
.version = "0.1.0",
.icons = .{ "assets/icon.icns" },
.platforms = .{ "macos", "linux" },
.platforms = .{ "macos", "linux", "windows" },
.permissions = .{},
.capabilities = .{ "webview" },
.frontend = .{
Expand Down
2 changes: 1 addition & 1 deletion examples/svelte/app.zon
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.display_name = "Svelte Example",
.version = "0.1.0",
.icons = .{ "assets/icon.icns" },
.platforms = .{ "macos", "linux" },
.platforms = .{ "macos", "linux", "windows" },
.permissions = .{},
.capabilities = .{ "webview" },
.frontend = .{
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/app.zon
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.display_name = "Vue Example",
.version = "0.1.0",
.icons = .{ "assets/icon.icns" },
.platforms = .{ "macos", "linux" },
.platforms = .{ "macos", "linux", "windows" },
.permissions = .{},
.capabilities = .{ "webview" },
.frontend = .{
Expand Down
2 changes: 1 addition & 1 deletion examples/webview/app.zon
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.display_name = "WebView Example",
.version = "0.1.0",
.icons = .{ "assets/icon.icns" },
.platforms = .{ "macos", "linux" },
.platforms = .{ "macos", "linux", "windows" },
.permissions = .{ "window" },
.capabilities = .{ "webview", "js_bridge" },
.bridge = .{
Expand Down
10 changes: 10 additions & 0 deletions src/frontend/root.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ pub fn sourceFromEnv(env_map: *std.process.Environ.Map, config: Config) platform
if (env_map.get(config.dev_url_env)) |url| {
if (url.len > 0) return platform.WebViewSource.url(url);
}
if (env_map.get("ZERO_NATIVE_FRONTEND_DIR")) |dir| {
if (dir.len > 0) {
return platform.WebViewSource.assets(.{
.root_path = dir,
.entry = config.entry,
.origin = config.origin,
.spa_fallback = config.spa_fallback,
});
}
}
return productionSource(config);
}

Expand Down
4 changes: 2 additions & 2 deletions src/platform/root.zig
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ pub const Platform = struct {
};

pub const Backend = enum {
@"null",
null,
macos,
linux,
windows,
Expand All @@ -412,7 +412,7 @@ pub const NullPlatform = struct {
requested_frames: u32 = 1,
loaded_source: ?WebViewSource = null,
security_policy: security.Policy = .{},
window_sources: [max_windows]?WebViewSource = [_]?WebViewSource{null} ** max_windows,
window_sources: [max_windows]?WebViewSource = @splat(null),
windows: [max_windows]WindowInfo = undefined,
window_count: usize = 0,
bridge_response: [16 * 1024]u8 = undefined,
Expand Down
2 changes: 2 additions & 0 deletions src/platform/windows/cef_host.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Windows Chromium currently shares the Win32 host surface with the system backend.
// CEF-specific browser creation is isolated behind this translation unit so the
// build can link the CEF runtime and evolve without changing the Zig ABI.
// When building CEF, we skip the WebView2-specific initialization code.
#define ZERO_NATIVE_CEF_BUILD
#include "webview2_host.cpp"
Loading
Loading