host

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

README

Standalone host

github.com/moriyoshi/gpui-go/host owns native startup, the Sable transport, platform loop and coordinated shutdown. Import client and scene directly for applications with their own transport/host.

err := host.Run(context.Background(), func(ctx context.Context, app *client.Client) error {
    window, err := app.OpenWindow(ctx, client.WindowOptions{
        Title: "Hello", Width: 560, Height: 420,
    }, scene.Div(1, scene.Text(2, "Hello, GPUI!")))
    if err != nil { return err }
    _ = window
    return app.DispatchEvents(ctx)
})

Call Run from main, once per process. Native builds lock the startup thread during package initialization because AppKit requires the process main thread. The application callback runs on a goroutine and must honor cancellation. Shutdown releases pending Rust requests and waits for active transport calls before freeing Sable.

Existing build commands and tags are unchanged: gpui,sable_extern_lib,sable_portable selects the native backend; gpui_headless additionally selects the headless protocol backend. Builds without gpui or gpui_prebuilt return ErrNativeUnavailable. Use the Makefile, which supplies the archive/framework flags and forces relinking after archive changes.

All native calls go through internal/nativeshim. gpui_prebuilt, which implies gpui, with CGO_ENABLED=0 replaces the cgo link with a published per-platform module, so a consumer needs neither Rust nor a C toolchain. This package imports github.com/moriyoshi/gpui-go/prebuilt under that tag, which registers the module for the target platform; on an unsupported platform, Run returns an error. See the publication guide.

The root gpui.Run forwards to this package and shares the same error identity and single-use runtime guard. The separately opted-in editor.Run remains its own Sable owner; the two hosts cannot run together in one process. Moving startup does not enable generic embedding of the GPL editor.

Documentation

Overview

Package host owns the standalone GPUI/Sable runtime and platform loop. Import client and scene instead when an application supplies its own host.

Index

Constants

This section is empty.

Variables

View Source
var ErrNativeUnavailable = errors.New("gpui: build with make run, or with -tags gpui,sable_extern_lib,sable_portable and the Rust static library")

Functions

func Run

func Run(ctx context.Context, application func(context.Context, *client.Client) error) error

Run enters the desktop event loop on the main OS thread. Invoke it from main, once per process. The callback runs on a goroutine and must return when ctx is canceled. Returning from the callback requests application quit. The gpui_headless build tag runs the same protocol without a display.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL