-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve build.zig + use v0.14.0 idioms #21
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allExamples -> all_examples
README.md
Outdated
``` | ||
|
||
## Example | ||
## Building and running example folder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 static
e2e test been ported
zig build test_e2e -Dasync=auto
unit tests been ported
zig build test_unit
added formatting checker test
zig build test_fmt
zig build test
will 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