1
0
Fork 0
mirror of https://github.com/zigzap/zap.git synced 2025-10-20 15:14:08 +00:00

improvements

This commit is contained in:
Rene Schallner 2023-01-12 19:06:45 +01:00
parent e50072ebe3
commit eaf501df30
2 changed files with 43 additions and 17 deletions

View file

@ -14,25 +14,51 @@ pub fn build(b: *std.build.Builder) !void {
var ensure_step = b.step("deps", "ensure external dependencies"); var ensure_step = b.step("deps", "ensure external dependencies");
ensure_step.makeFn = ensureDeps; ensure_step.makeFn = ensureDeps;
const example_run_step = b.step("run-example", "run the example"); inline for ([_]struct {
const example_step = b.step("example", "build the example"); name: []const u8,
src: []const u8,
}{
.{ .name = "hello", .src = "examples/hello/hello.zig" },
// .{ .name = "routes", .src = "examples/routes/routes.zig" },
// .{ .name = "serve", .src = "examples/serve/serve.zig" },
}) |excfg| {
const ex_name = excfg.name;
const ex_src = excfg.src;
const ex_build_desc = try std.fmt.allocPrint(
b.allocator,
"build the {s} example",
.{ex_name},
);
const ex_run_stepname = try std.fmt.allocPrint(
b.allocator,
"run-{s}",
.{ex_name},
);
const ex_run_stepdesc = try std.fmt.allocPrint(
b.allocator,
"run the {s} example",
.{ex_name},
);
const example_run_step = b.step(ex_run_stepname, ex_run_stepdesc);
const example_step = b.step(ex_name, ex_build_desc);
var example = b.addExecutable("example", "examples/hello/hello.zig"); var example = b.addExecutable(ex_name, ex_src);
example.setBuildMode(mode); example.setBuildMode(mode);
example.addPackage(zap); example.addPackage(zap);
example.addIncludePath("src/deps/facilio/libdump/all"); example.addIncludePath("src/deps/facilio/libdump/all");
_ = try addFacilio(example); _ = try addFacilio(example);
const example_run = example.run(); const example_run = example.run();
example_run_step.dependOn(&example_run.step); example_run_step.dependOn(&example_run.step);
// install the artifact - depending on the "example" // install the artifact - depending on the "example"
// only after the ensure step // only after the ensure step
// the step invoked via `zig build example` on the installed exe which // the step invoked via `zig build example` on the installed exe which
// itself depends on the "ensure" step // itself depends on the "ensure" step
const example_build_step = b.addInstallArtifact(example); const example_build_step = b.addInstallArtifact(example);
example.step.dependOn(ensure_step); example.step.dependOn(ensure_step);
example_step.dependOn(&example_build_step.step); example_step.dependOn(&example_build_step.step);
}
} }
fn logstep(msg: []const u8) void { fn logstep(msg: []const u8) void {

View file

@ -13,7 +13,7 @@ fn on_request(r: zap.SimpleRequest) void {
} }
pub fn main() !void { pub fn main() !void {
var listener: zap.SimpleHttpListener = zap.SimpleHttpListener.init(.{ var listener = zap.SimpleHttpListener.init(.{
.port = 3000, .port = 3000,
.on_request = on_request, .on_request = on_request,
.log = false, .log = false,