Skip to content

Commit

Permalink
readme: add build.zig gen step example
Browse files Browse the repository at this point in the history
  • Loading branch information
travisstaloch committed Nov 16, 2024
1 parent 2e4350f commit 9aae3c6
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,36 @@ CI tested weekly with latest zig version.

This project depends on packaged `flatc` compiler @v23.3.3, built with zig using [a fork of google/flatbuffers](https://github.com/travisstaloch/flatbuffers).

# Gen Steps
To auto generate code from a flatbuffers file in your build.zig see the example in [#18](https://github.com/travisstaloch/flatbufferz/pull/18).
# Gen Step
To generate code from a flatbuffers file in your build.zig:

```console
zig fetch --save git+https://github.com/travisstaloch/flatbufferz
```

```zig
const std = @import("std");
pub fn build(b: *std.Build) !void {
const exe = b.addExecutable(.{
// ...
});
const fbz_dep = b.dependency("flatbufferz", .{});
const gen_step = try @import("flatbufferz").GenStep.create(
b,
fbz_dep.artifact("flatc-zig"),
&.{"src/myschema.fbs"},
&.{},
"flatc-zig",
);
exe.root_module.addImport("generated", gen_step.module);
exe.root_module.addImport("flatbufferz", fbz_dep.module("flatbufferz"));
}
```


# Usage
Expand Down

0 comments on commit 9aae3c6

Please sign in to comment.