Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- uses: actions/checkout@v6
- uses: mlugg/setup-zig@v2
with:
version: 0.17.0-dev.956+2dca73595
version: 0.17.0-dev.1413+addc3c3b8
- name: Build all examples
run: zig build

Expand All @@ -46,6 +46,6 @@ jobs:
- uses: actions/checkout@v6
- uses: mlugg/setup-zig@v2
with:
version: 0.17.0-dev.956+2dca73595
version: 0.17.0-dev.1413+addc3c3b8
- name: Build all examples
run: zig build test --summary all
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Discord](https://img.shields.io/discord/1294761432922980392?logo=discord)](https://discord.gg/HNEszT7qSR)

## Installing
For in development zzz which uses [tardy/main](https://github.com/tardy-org/tardy/tree/main/), [secsock/main](https://github.com/tardy-org/secsock/tree/main/) and Zig `0.17.0-dev.956+2dca73595`
For in development zzz which uses [tardy/main](https://github.com/tardy-org/tardy/tree/main/), [secsock/main](https://github.com/tardy-org/secsock/tree/main/) and Zig `0.17.0-dev.1413+addc3c3b8`

```elvish
zig fetch --save 'git+https://github.com/tardy-org/zzz?ref=main#commit_hash'
Expand Down
49 changes: 31 additions & 18 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,29 @@ pub fn build(b: *std.Build) void {

zzz.addImport("secsock", secsock);

add_example(b, "basic", false, target, optimize, zzz);
add_example(b, "cookies", false, target, optimize, zzz);
add_example(b, "form", false, target, optimize, zzz);
add_example(b, "fs", false, target, optimize, zzz);
add_example(b, "middleware", false, target, optimize, zzz);
add_example(b, "sse", false, target, optimize, zzz);
add_example(b, "tls", true, target, optimize, zzz);

if (target.result.os.tag != .windows)
add_example(b, "unix", false, target, optimize, zzz);
for ([_][]const u8{
"basic",
"cookies",
"form",
"fs",
"middleware",
"sse",
"tls",
}) |name| add_example(
b,
name,
target,
optimize,
zzz,
);

if (target.result.os.tag != .windows) add_example(
b,
"unix",
target,
optimize,
zzz,
);

const tests = b.addTest(.{
.name = "tests",
Expand All @@ -43,8 +56,6 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
}),
});
tests.root_module.addImport("tardy", tardy);
tests.root_module.addImport("secsock", secsock);

const run_test = b.addRunArtifact(tests);
run_test.step.dependOn(&tests.step);
Expand All @@ -56,7 +67,6 @@ pub fn build(b: *std.Build) void {
fn add_example(
b: *std.Build,
name: []const u8,
link_libc: bool,
target: std.Build.ResolvedTarget,
optimize: std.builtin.OptimizeMode,
zzz_module: *std.Build.Module,
Expand All @@ -66,27 +76,30 @@ fn add_example(
.optimize = optimize,
.target = target,
.strip = false,
.link_libc = link_libc,
});
mod.addImport("zzz", zzz_module);

const example = b.addExecutable(.{
.name = name,
.root_module = mod,
// without llvm leads to error: undefined symbol: tardy_swap_frame
.use_llvm = true,
});

const install_artifact = b.addInstallArtifact(example, .{});
b.getInstallStep().dependOn(&install_artifact.step);

const build_step = b.step(b.fmt("{s}", .{name}), b.fmt("Build zzz example ({s})", .{name}));
const build_step = b.step(
b.fmt("{s}", .{name}),
b.fmt("Build zzz example ({s})", .{name}),
);
build_step.dependOn(&install_artifact.step);

const run_artifact = b.addRunArtifact(example);
run_artifact.step.dependOn(&install_artifact.step);

const run_step = b.step(b.fmt("run_{s}", .{name}), b.fmt("Run zzz example ({s})", .{name}));
const run_step = b.step(
b.fmt("run_{s}", .{name}),
b.fmt("Run zzz example ({s})", .{name}),
);
run_step.dependOn(&install_artifact.step);
run_step.dependOn(&run_artifact.step);
}
10 changes: 5 additions & 5 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
.name = .zzz,
.fingerprint = 0xc3273dca261a7ae0,
.version = "0.3.2-dev",
.minimum_zig_version = "0.17.0-dev.956+2dca73595",
.minimum_zig_version = "0.17.0-dev.1413+addc3c3b8",
.dependencies = .{
.tardy = .{
.url = "git+https://github.com/tardy-org/tardy?ref=main#1436624746f06f34ebb3a49fe8a931af8b316fbe",
.hash = "tardy-0.3.3-dev-69wrgt2fBQA2dlJcIbEeI2l5oAHY91FoOmA12EOjfizY",
.url = "git+https://github.com/tardy-org/tardy?ref=main#c03d2a4444ee39b78ca7592aa3b370c7198a05a6",
.hash = "tardy-0.3.3-dev-69wrgkq4BQBC0mpPpV5AWskM0aCChG7ZtMe4feSFSw3R",
},
.secsock = .{
.url = "git+https://github.com/tardy-org/secsock?ref=main#0fc315b11d86e34bb67c8bef41c01db1c41103d1",
.hash = "secsock-0.1.2-dev-p0qurcdLAQAOPCKieuk0ZVgHGoPBY9G4iqJvHDqw2OAV",
.url = "git+https://github.com/tardy-org/secsock?ref=main#035796324681e783f1e37c186dd11760e183f7f2",
.hash = "secsock-0.1.2-dev-p0qurS5LAQCO-FNsaCaYYNdK45kFD12UZEtUAVupTeoC",
},
},
.paths = .{
Expand Down
7 changes: 4 additions & 3 deletions examples/basic/main.zig
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const std = @import("std");

const zzz = @import("zzz");
const http = zzz.HTTP;
const http = zzz.http;
const tardy = zzz.tardy;
const Runtime = tardy.Runtime;
const Socket = tardy.net.Socket;
const Server = http.Server;
const Router = http.Router;
const Context = http.Context;
const Route = http.Route;
const Route = Router.Route;
const Respond = http.Respond;

const log = std.log.scoped(.@"examples/basic");
Expand Down Expand Up @@ -47,9 +47,10 @@ pub fn main(init: std.process.Init) !void {
router: *const Router,
socket: Socket,
};
const params: EntryParams = .{ .router = &router, .socket = socket };

try t.entry(
EntryParams{ .router = &router, .socket = socket },
params,
struct {
fn entry(rt: *Runtime, p: EntryParams) !void {
var server: Server = .init(.{
Expand Down
7 changes: 4 additions & 3 deletions examples/cookies/main.zig
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const std = @import("std");

const zzz = @import("zzz");
const http = zzz.HTTP;
const http = zzz.http;
const tardy = zzz.tardy;
const Runtime = tardy.Runtime;
const Socket = tardy.net.Socket;
const Server = http.Server;
const Router = http.Router;
const Context = http.Context;
const Route = http.Route;
const Route = Router.Route;
const Middleware = http.Middleware;
const Respond = http.Respond;
const Cookie = http.Cookie;
Expand Down Expand Up @@ -54,9 +54,10 @@ pub fn main(init: std.process.Init) !void {
router: *const Router,
socket: Socket,
};
const params: EntryParams = .{ .router = &router, .socket = socket };

try t.entry(
EntryParams{ .router = &router, .socket = socket },
params,
struct {
fn entry(rt: *Runtime, p: EntryParams) !void {
var server: Server = .init(.{
Expand Down
25 changes: 16 additions & 9 deletions examples/form/main.zig
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
const std = @import("std");

const zzz = @import("zzz");
const http = zzz.HTTP;
const http = zzz.http;
const tardy = zzz.tardy;
const Runtime = tardy.Runtime;
const Socket = tardy.net.Socket;
const Server = http.Server;
const Router = http.Router;
const Context = http.Context;
const Route = http.Route;
const Form = http.Form;
const Query = http.Query;
const Route = Router.Route;
const form = http.form;
const Form = form.Form;
const Query = form.Query;
const Respond = http.Respond;

const log = std.log.scoped(.@"examples/form");
Expand All @@ -35,7 +36,7 @@ fn base_handler(ctx: *const Context, _: void) !Respond {

return ctx.response.apply(.{
.status = .OK,
.mime = http.Mime.HTML,
.mime = .HTML,
.body = body,
});
}
Expand Down Expand Up @@ -71,7 +72,7 @@ fn generate_handler(ctx: *const Context, _: void) !Respond {

return ctx.response.apply(.{
.status = .OK,
.mime = http.Mime.TEXT,
.mime = .TEXT,
.body = body,
});
}
Expand All @@ -85,11 +86,16 @@ pub fn main(init: std.process.Init) !void {

var router: Router = try .init(init.gpa, &.{
Route.init("/").get({}, base_handler).layer(),
Route.init("/generate").get({}, generate_handler).post({}, generate_handler).layer(),
Route.init("/generate").get({}, generate_handler).post(
{},
generate_handler,
).layer(),
}, .{});
defer router.deinit(init.gpa);

var socket: Socket = try .init(init.io, .{ .tcp = .{ .host = host, .port = port } });
var socket: Socket = try .init(init.io, .{
.tcp = .{ .host = host, .port = port },
});
defer socket.close_blocking();
try socket.bind();
try socket.listen(4096);
Expand All @@ -98,9 +104,10 @@ pub fn main(init: std.process.Init) !void {
router: *const Router,
socket: Socket,
};
const params: EntryParams = .{ .router = &router, .socket = socket };

try t.entry(
EntryParams{ .router = &router, .socket = socket },
params,
struct {
fn entry(rt: *Runtime, p: EntryParams) !void {
var server: Server = .init(.{
Expand Down
21 changes: 11 additions & 10 deletions examples/fs/main.zig
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
const std = @import("std");

const zzz = @import("zzz");
const http = zzz.HTTP;
const http = zzz.http;
const tardy = zzz.tardy;
const Runtime = tardy.Runtime;
const Socket = tardy.net.Socket;
const Dir = tardy.fs.Dir;
const Server = http.Server;
const Router = http.Router;
const Context = http.Context;
const Route = http.Route;
const Route = Router.Route;
const Respond = http.Respond;
const FsDir = http.FsDir;
const Compression = http.Middlewares.Compression;
const FsDir = Router.FsDir;
const Compression = http.middleware.Compression;

const log = std.log.scoped(.@"examples/fs");

Expand Down Expand Up @@ -56,11 +56,6 @@ pub fn main(init: std.process.Init) !void {
}, .{});
defer router.deinit(init.gpa);

const EntryParams = struct {
router: *const Router,
socket: Socket,
};

var socket: Socket = try .init(
init.io,
.{ .tcp = .{ .host = host, .port = port } },
Expand All @@ -69,8 +64,14 @@ pub fn main(init: std.process.Init) !void {
try socket.bind();
try socket.listen(256);

const EntryParams = struct {
router: *const Router,
socket: Socket,
};
const params: EntryParams = .{ .router = &router, .socket = socket };

try t.entry(
EntryParams{ .router = &router, .socket = socket },
params,
struct {
fn entry(rt: *Runtime, p: EntryParams) !void {
var server: Server = .init(.{
Expand Down
30 changes: 15 additions & 15 deletions examples/middleware/main.zig
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
const std = @import("std");

const zzz = @import("zzz");
const http = zzz.HTTP;
const http = zzz.http;
const tardy = zzz.tardy;
const Runtime = tardy.Runtime;
const Socket = tardy.net.Socket;
const Server = http.Server;
const Router = http.Router;
const Context = http.Context;
const Route = http.Route;
const Next = http.Next;
const Route = Router.Route;
const Respond = http.Respond;
const Middleware = http.Middleware;
const Middleware = Router.Middleware;
const Next = Middleware.Next;

const log = std.log.scoped(.@"examples/middleware");

Expand Down Expand Up @@ -59,10 +59,6 @@ pub fn main(init: std.process.Init) !void {
const host: []const u8 = "0.0.0.0";
const port: u16 = 9862;

var gpa: std.heap.DebugAllocator(.{}) = .init;
const allocator = gpa.allocator();
defer _ = gpa.deinit();

var t: Tardy = try .init(init.gpa, init.io, .{ .threading = .single });
defer t.deinit();

Expand All @@ -75,20 +71,24 @@ pub fn main(init: std.process.Init) !void {
Route.init("/").post(num, root_handler).layer(),
Route.init("/fail").get(num, root_handler).layer(),
}, .{});
defer router.deinit(allocator);
defer router.deinit(init.gpa);

var socket: Socket = try .init(init.io, .{
.tcp = .{ .host = host, .port = port },
});
defer socket.close_blocking();

try socket.bind();
try socket.listen(256);

const EntryParams = struct {
router: *const Router,
socket: Socket,
};

var socket: Socket = try .init(init.io, .{ .tcp = .{ .host = host, .port = port } });
defer socket.close_blocking();
try socket.bind();
try socket.listen(256);
const params: EntryParams = .{ .router = &router, .socket = socket };

try t.entry(
EntryParams{ .router = &router, .socket = socket },
params,
struct {
fn entry(rt: *Runtime, p: EntryParams) !void {
var server: Server = .init(.{});
Expand Down
Loading
Loading