Arwalk/zig-protobuf
a protobuf 3 implementation for zig.
This repository, so far, only aims at implementing protocol buffers version 3.
This project is mature enough to be used in production.
json encoding/decoding is considered a beta feature.
There are 2 branches you can use for your development.
master
is the branch with current developments, working with the latest stable release of zig.zig-master
is a branch that merges the developments in master, but works with the latest-ish master version of zig.protobuf
to your build.zig.zon
. zig fetch --save "git+https://github.com/Arwalk/zig-protobuf#master"
protobuf
module. In your build.zig
's build function, add the dependency as module before
b.installArtifact(exe)
.pub fn build(b: *std.Build) !void {
// first create a build for the dependency
const protobuf_dep = b.dependency("protobuf", .{
.target = target,
.optimize = optimize,
});
// and lastly use the dependency as a module
exe.root_module.addImport("protobuf", protobuf_dep.module("protobuf"));
}
You can do this programatically as a compilation step for your application. The following snippet shows how to create a zig build gen-proto
command for your project.
const protobuf = @import("protobuf");
pub fn build(b: *std.Build) !void {
// first create a build for the dependency
const protobuf_dep = b.dependency("protobuf", .{
.target = target,
.optimize = optimize,
});
...
const gen_proto = b.step("gen-proto", "generates zig files from protocol buffer definitions");
const protoc_step = protobuf.RunProtocStep.create(protobuf_dep.builder, target, .{
// out directory for the generated zig files
.destination_directory = b.path("src/proto"),
.source_files = &.{
"protocol/all.proto",
},
.include_directories = &.{},
});
gen_proto.dependOn(&protoc_step.step);
}
The zig-protobuf logo is licensed under the Attribution 4.0 International (CC BY 4.0).
The logo is inspired by the official mascots of the Zig programming language, themselves licensed under the Attribution 4.0 International (CC BY 4.0)
Original art by vivisector.
If you're really bored, you can buy me a coffee here.