kwxgen parses the kwxFFI C header files and generates foreign-language bindings for wxWidgets.
It reads the include/ headers and src/kwx_defs.cpp to build a complete model of the FFI
surface (~572 classes, ~4,679 methods, ~485 events, 99 key constants, ~1,174 defined constants),
then emits idiomatic bindings for each target language.
kwxgen lives in kwxFFI and is consumed by the six language port repos. The generated files
are written into the consumer repo's source tree — kwxFFI itself is unchanged by generate.
Each language port follows the same three-step pattern:
- Obtain kwxFFI (submodule or clone)
- Build
kwxgen— pure C++23, zero external dependencies, builds in seconds - Run
kwxgen generate— reads the kwxFFI headers, writes bindings into your repo
The sections below detail the exact steps for each language.
Prerequisites: CMake 3.30+ and a C++23 compiler
Step 1 — Build kwxgen and generate (from CMakeLists.txt or a script):
cmake -S extern/kwxFFI/tools/kwxgen -B build/kwxgen -G Ninja
cmake --build build/kwxgen
build/kwxgen/kwxgen generate \
--headers extern/kwxFFI/include \
--defs extern/kwxFFI/src/kwx_defs.cpp \
--lang fortran \
--out src/gen/Generated output (src/gen/): one wx_button.f90-style module per class using
ISO_C_BINDING interface blocks, plus wx_events.f90, wx_keys.f90,
wx_constants.f90. Compile and use normally:
use wx_button
use wx_eventsPrerequisites: CMake 3.30+, a C++23 compiler.
add_custom_command(
OUTPUT
**Generated output** (`wx/`): one `*_gen.go` file per class + `events_gen.go`,
`keys_gen.go`, `constants_gen.go`. Each file has the appropriate `// #include` cgo
directives.
**Verify bindings are current** (e.g. in CI):
```sh
kwxgen verify --headers extern/kwxFFI/include \
--defs extern/kwxFFI/src/kwx_defs.cpp \
--lang go --dir wx/
Prerequisites: CMake 3.30+ and a C++23 compiler to build kwxgen
Step 1 — Build kwxgen (standalone, no CMake integration required for pure-Lua projects):
cmake -S extern/kwxFFI/tools/kwxgen -B build/kwxgen -G Ninja
cmake --build build/kwxgenStep 2 — Generate bindings:
build/kwxgen/kwxgen generate \
--headers extern/kwxFFI/include \
--defs extern/kwxFFI/src/kwx_defs.cpp \
--lang luajit \
--out lua/wx/Generated output (lua/wx/): kwxffi.lua — a single file with a consolidated
ffi.cdef[[ ... ]] block covering all declarations, plus one helper .lua per class
with idiomatic Lua wrappers. Load with:
local wx = require("wx.kwxffi")Prerequisites: CMake 3.30+ and a C++23 compiler.
Step 1 — Build kwxgen:
cmake -S extern/kwxFFI/tools/kwxgen -B build/kwxgen -G Ninja
cmake --build build/kwxgenStep 2 — Generate bindings (typically from deps/build.jl or a Makefile):
build/kwxgen/kwxgen generate \
--headers extern/kwxFFI/include \
--defs extern/kwxFFI/src/kwx_defs.cpp \
--lang julia \
--out src/gen/Generated output (src/gen/): one .jl file per class using ccall, plus
events.jl, keys.jl, constants.jl. Include from your package:
include("gen/events.jl")
include("gen/Button.jl")Regenerate any time kwxFFI is updated; commit the generated files alongside hand-written code.
Prerequisites: CMake 3.30+ and a C++23 compiler; Deno 1.40+.
Step 1 — Build kwxgen:
cmake -S extern/kwxFFI/tools/kwxgen -B build/kwxgen -G Ninja
cmake --build build/kwxgenStep 2 — Generate bindings (from a Makefile or your build script):
build/kwxgen/kwxgen generate \
--headers extern/kwxFFI/include \
--defs extern/kwxFFI/src/kwx_defs.cpp \
--lang typescript \
--out gen/Generated output (gen/):
kwx_ffi_gen.ts—Deno.dlopencall with all C symbol definitions (classes, free functions, events, keys, constants). Importlibfrom this module to call functions directly.kwx_constants_gen.ts— Eagerly-evaluated numeric exports for all events, keys, and constants.kwx_free_functions_gen.ts— TypeScript wrappers for non-class C functions.wx{Class}_gen.ts— One file per class with a TypeScript class wrapping the FFI calls.kwx_gen.ts— Master barrel re-export of every generated module.
Run with:
import { lib } from "./gen/kwx_ffi_gen.ts";
// Or import the barrel for the full class-based API
import "./gen/kwx_gen.ts";
// Run with: deno run --allow-ffi your_script.tsWhen kwxFFI adds new classes or changes signatures:
cmake --build build/kwxgen
build/kwxgen/kwxgen generate
--headers extern/kwxFFI/include
--defs extern/kwxFFI/src/kwx_defs.cpp
--lang
--out /
git add / git commit -m "Regenerate bindings against kwxFFI "
Use `verify` first to see what changed before committing:
```sh
build/kwxgen/kwxgen verify \
--headers extern/kwxFFI/include \
--defs extern/kwxFFI/src/kwx_defs.cpp \
--lang <your-lang> \
--dir <your-output-dir>/
| Category | Count |
|---|---|
| Classes | 572 |
| Class methods | 4,679 |
| Events | 315 |
| Key constants | 99 |
| Defined constants | 1,174 |
| Free functions | 23 |
kwxgen is a standalone C++23 program with no wxWidgets dependency:
cmake -S tools/kwxgen -B tools/kwxgen/build -G Ninja
cmake --build tools/kwxgen/buildkwxgen parse --headers <dir> --defs <file> [--out <file>]
Parses all kwxFFI headers and emits a JSON model of the entire FFI surface. If --out is omitted or set to -, JSON is written to stdout.
| Option | Description |
|---|---|
--headers <dir> |
Path to the kwxFFI include/ directory |
--defs <file> |
Path to src/kwx_defs.cpp |
--out <file> |
Output JSON file (default: stdout) |
kwxgen generate --headers <dir> --defs <file> --lang <lang> --out <dir>
Parses the headers and generates binding source files for the specified language.
| Option | Description |
|---|---|
--headers <dir> |
Path to the kwxFFI include/ directory |
--defs <file> |
Path to src/kwx_defs.cpp |
--lang <lang> |
Target language (see kwxgen langs) |
--out <dir> |
Output directory for generated files |
--libname <name> |
Runtime shared-lib name embedded in bindings (default: kwxFFI) |
kwxgen verify --headers <dir> --defs <file> --lang <lang> --dir <dir>
Checks that generated bindings in --dir are up to date with the current headers.
kwxgen diff --headers <dir> --manifest <file>
Compares the current headers against a saved manifest to show what has changed.
kwxgen langs
Prints the list of available language backends.