improve build.zig + use v0.14.0 idioms#21
improve build.zig + use v0.14.0 idioms#21mookums merged 24 commits intotardy-org:mainfrom Torbatti:main
Conversation
build.zig
Outdated
| inline for (std.meta.fields(Example)) |f| { | ||
|
|
||
| // skip .none and .all for building step | ||
| if (f.value == 1 or f.value == 0) { |
There was a problem hiding this comment.
I'd probably use the enum name here instead of the values.
| stat, | ||
| stream, | ||
|
|
||
| fn toString(ex: Example) []const u8 { |
There was a problem hiding this comment.
Instead of this, why not just use @tagName on the enum? You would get the same strings and avoid a bespoke conversion function.
There was a problem hiding this comment.
here are some advantages of using toString helper function instead of @tagName
- use nested paths and get a simpler enum field name
- put similar examples inside a single directory
using toString:
examples/echo/v1/ -> .echo_v1
examples/echo/v2/ -> .echo_v2
using @tagName
examples/echo_v1/ -> .echo_v1
examples/echo_v2/ -> .echo_v2
disadvantages :
may forget to add example to toString helper function
|
|
||
| // create a private example module | ||
| const example_mod = b.createModule(.{ | ||
| .root_source_file = b.path(b.fmt("examples/{s}/main.zig", .{options.example.toString()})), |
There was a problem hiding this comment.
@tagName(options.example)
build.zig
Outdated
| steps.install.dependOn(&install_artifact.step); | ||
|
|
||
| // Should not run all examples at the same time | ||
| if (options.allExamples) { |
There was a problem hiding this comment.
Should log that you can't run all examples at the same time.
| }); | ||
|
|
||
| const example_exe = b.addExecutable(.{ | ||
| .name = options.example.toString(), |
There was a problem hiding this comment.
@tagName(options.example)
| const AsyncKind = @import("src/aio/lib.zig").AsyncKind; | ||
| fn build_static_lib( | ||
| b: *std.Build, | ||
| steps: struct { |
There was a problem hiding this comment.
No reason to have this be a struct.
| // build/run a specific example | ||
| fn build_example_exe( | ||
| b: *std.Build, | ||
| steps: struct { |
There was a problem hiding this comment.
Honestly, I might prefer you just pass the types in like run_step or install_step instead of having inline structs
There was a problem hiding this comment.
having steps struct in every main build function makes it easier to read available steps and can infer to them using steps.[name] , even if there is only one step
can also be replaced by step_run and step_install for code reviewing sake like you mentioned
build.zig
Outdated
| options: struct { | ||
| tardy_mod: *std.Build.Module, | ||
| example: Example, | ||
| allExamples: bool, |
There was a problem hiding this comment.
allExamples -> all_examples
README.md
Outdated
| ``` | ||
|
|
||
| ## Example | ||
| ## Building and running example folder |
There was a problem hiding this comment.
Building and Running Examples
|
Most of it is pretty good, left a few comments of things that might be worth taking a look at. |
|
fixes part 1:
|
added build steps and build options
this will make finding what steps are used and what options are available easier
you only need zig build and zig build run
specifiy examples to build/run by using
-Dexample=[nameOfExample]optionadded static step to build tardy as a standalone lib
zig build statice2e test been ported
zig build test_e2e -Dasync=autounit tests been ported
zig build test_unitadded formatting checker test
zig build test_fmtzig build testwill now run unit tests and fmting testsdecoupled build example module and build example exe functions
replaced root_module with the new createMod and addImport introduced in v0.14.0
note: github actions wont compile any examples for os piplines / can be added via run step
zig build -Dexample=all