FORGE KUI / docs

Integrate the Go SDK

Windows x64 Full Profile with Go 1.22+ and the package build script.

Version 3.61.7

Run a packaged program first

After extraction, run hello_world from bin, then rebuild the quickstarts. The Go SDK uses CGO and LLVM Clang. Its clang_go_cgo.py adapter handles MSVC-target Clang flags; avoid mixing in MinGW runtime libraries.

powershell
pwsh -File build.ps1 -Configuration Release -Output bin
.\bin\kui_go_hello_world.exe

Initialization and resources

Call kui.Load() before kui.Init(). Use UI APIs on the initialization thread. Close owning objects such as Window and Document promptly, usually with defer. Do not rely on Go GC to time native resource release. Use PostTask to bring worker results back to the UI thread.

Runtime scope

Go connects to existing core DOM, Lua, graphics, media and extension features. 3D requires kui_ext_3d.dll and media requires the appropriate backend. The current GA scope is Windows x64; it does not establish same-version Linux or macOS availability.

A complete window entry point

This source comes directly from the SDK hello_world example. Build within the package workspace, keeping its modules and helper folders; copying this file alone does not provide its dependencies.

go
package main

import (
	"log"

	kui "github.com/kui-engine/kui-go/v3"
	"github.com/kui-engine/kui-go/v3/examples/internal/exampleutil"
)

func main() {
	if err := kui.Load(exampleutil.RuntimePath()); err != nil {
		log.Fatal(err)
	}
	if err := kui.Init(); err != nil {
		log.Fatal(err)
	}
	defer kui.Shutdown()

	window, err := kui.NewWindow(kui.WindowProps{Title: "KUI Go SDK", Width: 960, Height: 640, Centered: true})
	if err != nil {
		log.Fatal(err)
	}
	defer window.Close()
	document, err := window.Document()
	if err != nil {
		log.Fatal(err)
	}
	defer document.Close()
	if err := document.LoadHTML(`<main style="padding:48px;font-family:sans-serif"><h1>Go SDK 已接入 KUI</h1><p>此程序仅通过公开 C ABI 工作。</p></main>`); err != nil {
		log.Fatal(err)
	}
	if err := window.Show(); err != nil {
		log.Fatal(err)
	}
	if _, err := kui.Run(); err != nil {
		log.Fatal(err)
	}
}

Before building

Use the symptom to narrow the cause before editing.

Before building
SymptomCheck and action
Binding or native library missingBuild in the SDK workspace and point to the binding’s packaged native directory.
Startup error or frozen UICheck runtime versions, keep UI calls on the initialization thread and avoid blocking the event loop.
Worker result cannot safely update UIDispatch through the binding’s main-thread entry point and confirm the window is still alive.