README
¶
WGPUStatic
WGPUStatic is a Go language extension that statically binds WGPU/Native—the C
API implementation of the Rust-based wgpu-native—through
Hike/SXSO. Once the generated wrapper and static archive are available, an
application can link WGPU by simply running go build.
The project keeps the Go-facing WGPU interface close to the existing FFI-based
WebGPU binding. The wgpu package source is based on the source used by the Go
WebGPU FFI project, while native calls are provided by the Hike/SXSO-generated
internal/wgpunative package. The public package has no GoFFI dependency.
The main difference from the original FFI project is the native link model:
| Project | Go API and FFI | Native WGPU library |
|---|---|---|
| Original FFI project | Pure-Go FFI with the existing WGPU binding | Loaded dynamically at runtime |
| WGPUStatic | The same FFI-oriented WGPU binding sources | Rust wgpu-native linked into the executable as a static archive |
About WGPU
wgpu is a cross-platform, safe, pure-Rust
graphics API. It runs natively on Vulkan, Metal, Direct3D12, and OpenGL, and
can also run on WebGL2 and WebGPU through WebAssembly.
Its API is based on the WebGPU standard, but it is implemented as a fully native Rust library. The WGPU ecosystem is used as the graphics foundation for projects such as Firefox, Servo, and Deno.
WGPU-Native exposes this native implementation through a C API, making it possible to use WGPU from C and other languages. WGPUStatic uses that C API as the native boundary and links it statically into Go applications.
Architecture
Go application
│
├── wgpu package
│ └── Go WebGPU binding adapted for static native calls
│
├── internal/wgpunative
│ └── Hike declarations and native symbol stubs
│
└── internal/wgpunative_native
├── wgpunative_native_windows_amd64.syso
└── wgpunative_native_linux_amd64.syso
│
└── platform-specific libwgpu_native.a
│
└── Rust wgpu-native v29.0.1.1
The native repository is registered as the third_party/wgpu-native Git
submodule and is fixed to tag v29.0.1.1. Its Cargo configuration produces a
static library in addition to the shared-library target. The resulting archive
is copied into internal/wgpunative_native with a platform-specific .syso
extension so that the Go linker can include it in a Windows or Linux amd64
executable. The Windows and Linux archives are built for their respective
targets and are not interchangeable.
Features
| Feature | Description |
|---|---|
| FFI-compatible API | Reuses the WGPU package sources and API shape from the FFI-oriented Go binding |
| Native call path | Uses Hike/SXSO-generated wrappers rather than GoFFI |
| Static native archive | Links the Rust wgpu-native archive through a Go .syso object |
| Hike interface | Provides native declarations in internal/wgpunative/wgpunative.go.hike |
| Pinned native version | Uses wgpu-native tag v29.0.1.1 |
| Supported platforms | Windows amd64 and Linux amd64 |
| Triangle examples | Native Win32 and X11 event loops with a WGSL triangle renderer |
Requirements
- Go 1.25 or later
- Rust stable toolchain
- Rust targets
x86_64-pc-windows-gnullvmandx86_64-unknown-linux-gnu - MSYS2 UCRT64 clang and lld to build the Windows archive
- X11 development libraries to build and run Linux windowed examples
- cgo and a C compiler for Linux static-linking applications
- Hike compiler when regenerating the Hike interface files
WGPUStatic supports Windows amd64 and Linux amd64. The repository Makefile
automates the Windows GNU-target archive build. On Windows, select the Rust
compiler and Cargo explicitly when the MSYS2 installation appears earlier in
PATH than the Rust installation.
Build the native library
The repository root includes a Makefile that automates the Windows GNU
target build and copies the resulting archive into the Go static-link package:
make native-release
For a debug archive, use:
make native-debug
The Rust compiler, linker, and LLVM paths can be overridden when necessary:
make native-release `
RUSTC='C:/Users/your-user/.cargo/bin/rustc.exe' `
LINKER='C:/local/gnu/msys64/ucrt64/bin/clang.exe' `
LIBCLANG_PATH='C:/local/gnu/clang+llvm-18.1.8-x86_64-pc-windows-msvc/bin'
From third_party/wgpu-native, use the following PowerShell configuration:
$env:RUSTUP_TOOLCHAIN = "stable"
$env:RUSTC = "$env:USERPROFILE\.cargo\bin\rustc.exe"
$env:LIBCLANG_PATH = "C:\local\gnu\clang+llvm-18.1.8-x86_64-pc-windows-msvc\bin"
$env:CARGO_TARGET_X86_64_PC_WINDOWS_GNULLVM_LINKER = `
"C:\local\gnu\msys64\ucrt64\bin\clang.exe"
$env:RUSTFLAGS = "-C link-arg=-fuse-ld=lld"
$env:PATH = "C:\Users\$env:USERNAME\.cargo\bin;C:\local\gnu\clang+llvm-18.1.8-x86_64-pc-windows-msvc\bin;" + $env:PATH
rustup target add --toolchain stable x86_64-pc-windows-gnullvm
rustup run stable cargo clean
rustup run stable cargo build `
--release `
--target x86_64-pc-windows-gnullvm `
-j 1
The static archive is produced at:
third_party/wgpu-native/target/x86_64-pc-windows-gnullvm/release/libwgpu_native.a
Copy the archive to internal/wgpunative_native and use the .syso extension
expected by the Go linker:
Copy-Item `
third_party/wgpu-native/target/x86_64-pc-windows-gnullvm/release/libwgpu_native.a `
internal/wgpunative_native/wgpunative_native_windows_amd64.syso
Linux amd64
Build the Linux release archive from the repository root and copy it to the
Linux .syso carrier:
rustup target add x86_64-unknown-linux-gnu
cargo build \
--manifest-path third_party/wgpu-native/Cargo.toml \
--release \
--target x86_64-unknown-linux-gnu
cp third_party/wgpu-native/target/x86_64-unknown-linux-gnu/release/libwgpu_native.a \
internal/wgpunative_native/wgpunative_native_linux_amd64.syso
The Linux archive links system libraries (libm, libdl, and libpthread)
through the package's cgo linker flags. Linux windowed examples also require
X11 development libraries and an active X display.
Examples
Simple link check
cd examples\simple
$env:CGO_ENABLED = "1"
$env:CC = "C:\local\gnu\msys64\ucrt64\bin\clang.exe"
go run .
Triangle
The triangle example is a Go port of
third_party/wgpu-native/examples/triangle. It creates a native Win32 window,
selects an adapter, creates a WGSL render pipeline, runs the Windows event
loop, and presents a red triangle.
cd examples\triangle
$env:CGO_ENABLED = "1"
$env:CC = "C:\local\gnu\msys64\ucrt64\bin\clang.exe"
go run .
The example uses the repository's statically linked native archive through the
.syso carrier; it does not load wgpu_native.dll at runtime.
On Linux amd64, the same example uses X11. From examples/triangle, run:
go run .
It requires the Linux archive above, cgo, X11 development libraries, and an active X display.
Static linking status
The Rust archive and the .syso carrier are part of the static-link path. The
Hike declarations in internal/wgpunative provide the direct native symbols
needed by the Hike/SXSO integration.
The public wgpu package preserves the original API shape, but its static
native entry points are resolved by internal/wgpunative; no runtime DLL
loading or GoFFI call layer is used.
Repository layout
third_party/wgpu-native/ Pinned Rust WGPU native submodule
wgpu/ Go WebGPU binding based on the FFI project
internal/wgpunative/ Hike native interface declarations
internal/wgpunative_native/ Static archive carrier and link flags
examples/simple/ Static-link smoke test
examples/triangle/ Windows and Linux WGPU triangle examples
License
WGPUStatic is released under the MIT License. See LICENSE.
The project also incorporates or adapts material from the following projects; their respective licenses and notices remain applicable:
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
triangle-dll
command
|
|
|
internal
|
|
|
wgpunative
Code generated by hikec.
|
Code generated by hikec. |
|
wgpunative_native
Package wgpunative_native carries the statically linked wgpu-native archive.
|
Package wgpunative_native carries the statically linked wgpu-native archive. |
|
Package wgpu provides Zero-CGO WebGPU bindings for Go.
|
Package wgpu provides Zero-CGO WebGPU bindings for Go. |