PHP declarations → generated C → native Win32 executable

JX emits native Windows window apps from PHP page declarations.

The JX native window C emission path takes a PHP input file with jx_* declarations, emits a GCC-compilable C file, and builds a standalone Win32/GDI executable with no WebView and no browser dependency.

Inputin.php with jx_page_title, body, modal, iframe, JSON, and API declarations.
Emissionjx -o out.c in.php writes a C source file and prints the follow-up GCC command.
ExecutableGCC/MinGW links a native out.exe using ws2_32, gdi32, and user32.

Overview

JX native window C emission is a direct static generation workflow. PHP is used as a declaration source, not as a browser page and not as a WebView wrapper. The emitted C file contains the native window renderer, embedded page data, optional embedded CSS, optional bundled assets, and a small localhost API surface.

1.
Write PHP with jx_* declarations.
2.
Run jx -o out.c in.php.
3.
Compile out.c into a native Windows executable.

The resulting executable opens a native Win32/GDI window. It does not require Edge WebView2, Chromium, Electron, a browser, or a PHP runtime for the static jx_* page emission path.

Requirements

Basic Workflow

Emit C from a PHP declaration page:

jx -o out.c in.php

After successful emission, JX prints the follow-up GCC command. Use that command as the canonical next step, especially when the generated file or output executable names differ from the examples below.

Compile Command

gcc -O2 -Wall -Wextra -mwindows -I . -o out.exe out.c -lws2_32 -lgdi32 -luser32
Link order matters. Put libraries after out.c. In particular, -lws2_32 must appear after the generated C input so Winsock symbols are resolved.

PowerShell Example

Windows PowerShell using MSYS2 UCRT64 GCC:

$gcc = "C:\msys64\ucrt64\bin\gcc.exe"

# Build JX from native source.
& $gcc -O2 -Wall -Wextra -I . -o jx.exe src/native/jx.c

# Emit generated C from the PHP page declaration file.
.\jx.exe -o out.c examples\native_window_input.php

# Compile the native Win32/GDI executable.
& $gcc -O2 -Wall -Wextra -mwindows -I . -o out.exe out.c -lws2_32 -lgdi32 -luser32

# Run it.
.\out.exe

Linux/WSL Cross-Compile Example

From Linux or WSL, use MinGW-w64 to build a Windows executable:

sudo apt-get update
sudo apt-get install -y gcc mingw-w64

# Build the local JX emitter.
gcc -O2 -Wall -Wextra -I . -o jx src/native/jx.c

# Emit generated C.
./jx -o out.c examples/native_window_input.php

# Cross-compile a Windows executable.
x86_64-w64-mingw32-gcc -O2 -Wall -Wextra -mwindows -I . -o out.exe out.c -lws2_32 -lgdi32 -luser32

jx_* Page Declarations

DeclarationPurpose
jx_page_titleSets the main native window/page title.
jx_page_badgeSets a short badge or status label.
jx_page_bodySets the primary body content rendered by the native window.
jx_modal_titleSets modal title text.
jx_modal_bodySets modal body text.
jx_iframe_titleSets iframe/island title metadata.
jx_iframe_htmlStores iframe/island HTML payload for the generated app.
jx_page_jsonEmbeds attachment JSON returned through /json.
jx_local_apiEnables the local API bridge in the native executable.

Localhost API

When local API support is enabled, the native executable exposes localhost endpoints for inspecting and updating the compiled window state.

EndpointBehavior
/jsonReturns the compiled attachment JSON from jx_page_json.
/update?title=...&badge=...&body=...Updates title, badge, and body state.
/modal?title=...&body=...Updates modal title and body state.
/iframe?title=...&html=...Updates iframe title and HTML payload state.
curl http://127.0.0.1:7878/json

Example Input

The main example is expected at:

examples/native_window_input.php

A short annotated shape:

<?php
// Native window text.
jx_page_title("JX Native Window Demo");
jx_page_badge("native-win32");
jx_page_body("Generated C rendered by a native Win32/GDI executable.");

// Modal content.
jx_modal_title("About this executable");
jx_modal_body("This is not a WebView and does not open a browser.");

// Iframe/island payload metadata.
jx_iframe_title("Embedded Island");
jx_iframe_html("<h1>Island payload</h1>");

// Compiled JSON attachment returned by /json.
jx_page_json('{"engine":"jx","target":"native-window-c"}');

// Enable localhost bridge endpoints.
jx_local_api(true);

CSS

If a sibling style.css exists next to the PHP input file, JX infers it and embeds it into the generated C. This keeps the generated native executable self-contained for the static page assets it knows how to bundle.

examples/native_window_input.php
examples/style.css

jx -o out.c examples/native_window_input.php

Includes, Requires, CSS Images

Bridge-mode bundling supports static quoted relative PHP includes:

JX can also bundle assets referenced by CSS url(...) and quoted image paths when they are static, quoted, and relative to the page being emitted. The single-executable page example is expected at:

examples/single_exe_page/page.php

Example shape:

<?php
require_once "partials/header.php";
include "partials/body.php";

jx_page_title("Single EXE page");
jx_page_body("Includes and relative assets can be bundled into generated C.");

Troubleshooting

Winsock linker errors

undefined reference to __imp_socket
undefined reference to __imp_WSAStartup

This means -lws2_32 is missing or appears before out.c. Re-run the compile with libraries at the end:

gcc -O2 -Wall -Wextra -mwindows -I . -o out.exe out.c -lws2_32 -lgdi32 -luser32

What This Is Not

Verification

End-to-end smoke path:

# 1. Build JX.
gcc -O2 -Wall -Wextra -I . -o jx src/native/jx.c

# 2. Emit C.
./jx -o out.c examples/native_window_input.php

# 3. Compile EXE.
x86_64-w64-mingw32-gcc -O2 -Wall -Wextra -mwindows -I . -o out.exe out.c -lws2_32 -lgdi32 -luser32

# 4. Run the EXE on Windows.
./out.exe

# 5. Query compiled JSON while the EXE is running.
curl http://127.0.0.1:7878/json

For the long-form repo documentation, see native-window-c-emission.md.