Defining Golem Components in Zig
Creating a project
Golem's command line interface provides a set of predefined, Golem-specific templates to choose from as a starting point.
To get started from scratch, first create a new application using the Zig
template:
golem app new my-app zig
cd my-app
An application can consist of multiple components. Add a new component by choosing from one of the available templates. To see the list of available templates, run:
golem component new
Then create a new component using the chosen template:
golem component new zig my-component
Specification-first approach
Golem and the Zig (and C/C++) toolchain currently requires defining the component's interface using the WebAssembly Interface Type (WIT) format. See the official documentation of this format (opens in a new tab) for reference.
Each new project generated with golem
contains a wit
directory with at least one .wit
file defining a world
. This world can contain exports (exported functions and interfaces) and these exports will be the compiled Golem component's public API.
The first time a component is compiled (see the Building Components page for details), a couple of files (example.c
, example.h
and example_component_type.o
if the component name was example
) get generated in the src/bindings
directory. This module contains the C definitions of all the data types and interfaces defined in the WIT
file(s).
To implement the specification written in WIT, the Zig code must implement some of these generated exported functions defined in the generated header file.
As currently there is no Zig-specific binding generator, for more details, check the C/C++ guide for defining components.