authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-07 20:48:29 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-07 20:48:29 -07:00
logb9eee6396695f32b59a9eada10524e488c0d60c1
tree4f5d3be9689d1c3071d5d413e6a6c39e8998a28c
parent9153a5a3b11eec15482d9b610a607a55f7e67a35
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

update to zig 0.16.0


5 files changed, 37 insertions(+), 10 deletions(-)

README.md+1-1
...@@ -3,7 +3,7 @@...@@ -3,7 +3,7 @@
3![loc](https://sloc.xyz/github/nektro/zig-oauth2)3![loc](https://sloc.xyz/github/nektro/zig-oauth2)
4[![license](https://img.shields.io/github/license/nektro/zig-oauth2.svg)](https://github.com/nektro/zig-oauth2/blob/master/LICENSE)4[![license](https://img.shields.io/github/license/nektro/zig-oauth2.svg)](https://github.com/nektro/zig-oauth2/blob/master/LICENSE)
5[![nektro @ github sponsors](https://img.shields.io/badge/sponsors-nektro-purple?logo=github)](https://github.com/sponsors/nektro)5[![nektro @ github sponsors](https://img.shields.io/badge/sponsors-nektro-purple?logo=github)](https://github.com/sponsors/nektro)
6[![Zig](https://img.shields.io/badge/Zig-0.15-f7a41d)](https://ziglang.org/)6[![Zig](https://img.shields.io/badge/Zig-0.16-f7a41d)](https://ziglang.org/)
7[![Zigmod](https://img.shields.io/badge/Zigmod-latest-f7a41d)](https://github.com/nektro/zigmod)7[![Zigmod](https://img.shields.io/badge/Zigmod-latest-f7a41d)](https://github.com/nektro/zigmod)
88
9HTTP handler functions to allow you to easily add OAuth2 login support to your Zig application.9HTTP handler functions to allow you to easily add OAuth2 login support to your Zig application.
build.zig+1-1
...@@ -14,7 +14,7 @@ pub fn build(b: *std.Build) void {...@@ -14,7 +14,7 @@ pub fn build(b: *std.Build) void {
14 }),14 }),
15 });15 });
16 deps.addAllTo(tests);16 deps.addAllTo(tests);
17 tests.linkLibC();17 tests.root_module.link_libc = true;
18 tests.use_llvm = !disable_llvm;18 tests.use_llvm = !disable_llvm;
19 tests.use_lld = !disable_llvm;19 tests.use_lld = !disable_llvm;
20 b.getInstallStep().dependOn(&tests.step);20 b.getInstallStep().dependOn(&tests.step);
oauth2.zig+4-6
...@@ -9,6 +9,8 @@ const url = @import("url");...@@ -9,6 +9,8 @@ const url = @import("url");
9const http = @import("http");9const http = @import("http");
10const nio = @import("nio");10const nio = @import("nio");
11const json = @import("json");11const json = @import("json");
12const builtin = @import("builtin");
13const root = @import("root");
12const Base = @This();14const Base = @This();
1315
14pub const Provider = struct {16pub const Provider = struct {
...@@ -266,11 +268,6 @@ pub fn clientByProviderId(clients: []const Client, name: string) ?Client {...@@ -266,11 +268,6 @@ pub fn clientByProviderId(clients: []const Client, name: string) ?Client {
266}268}
267269
268pub fn Handlers(comptime T: type) type {270pub fn Handlers(comptime T: type) type {
269 comptime std.debug.assert(@hasDecl(T, "isLoggedIn"));
270 comptime std.debug.assert(@hasDecl(T, "doneUrl"));
271 comptime std.debug.assert(@hasDecl(T, "saveInfo"));
272 comptime std.debug.assert(@hasDecl(T, "callbackPath"));
273
274 return struct {271 return struct {
275 const Self = @This();272 const Self = @This();
276 pub var clients: []Client = &.{};273 pub var clients: []Client = &.{};
...@@ -298,8 +295,9 @@ pub fn Handlers(comptime T: type) type {...@@ -298,8 +295,9 @@ pub fn Handlers(comptime T: type) type {
298 const client = clientByProviderId(Self.clients, state) orelse return try fail(response_status, body_writer, "error: No handler found for provider: {s}\n", .{state});295 const client = clientByProviderId(Self.clients, state) orelse return try fail(response_status, body_writer, "error: No handler found for provider: {s}\n", .{state});
299 const code = query.get("code") orelse return try fail(response_status, body_writer, "", .{});296 const code = query.get("code") orelse return try fail(response_status, body_writer, "", .{});
300297
298 const io = if (!builtin.is_test) root.io else std.Options.debug_io;
301 var buf: [4096]u8 = @splat(0);299 var buf: [4096]u8 = @splat(0);
302 var http_client: std.http.Client = .{ .allocator = alloc };300 var http_client: std.http.Client = .{ .allocator = alloc, .io = io };
303 defer http_client.deinit();301 defer http_client.deinit();
304302
305 var params = url.SearchParams.init(alloc);303 var params = url.SearchParams.init(alloc);
test.zig+27-2
...@@ -1,7 +1,32 @@...@@ -1,7 +1,32 @@
1const std = @import("std");1const std = @import("std");
2const oauth2 = @import("oauth2");2const oauth2 = @import("oauth2");
3const nio = @import("nio");
4const http = @import("http");
5const json = @import("json");
36
4// TODO: how do we make this better?
5test {7test {
6 std.testing.refAllDeclsRecursive(oauth2);8 _ = &oauth2.Provider;
9 _ = &oauth2.Client;
10 std.testing.refAllDecls(oauth2.providers);
11 std.testing.refAllDecls(oauth2.dynamic_providers);
12 _ = &oauth2.providerById;
13 _ = &oauth2.clientByProviderId;
14 _ = &oauth2.pek_domain;
15}
16test {
17 const S = struct {
18 pub const callbackPath = "/-/callback";
19 pub const doneUrl = "/";
20
21 pub fn isLoggedIn(_: *http.ServerRequest, _: std.mem.Allocator) !bool {
22 return false;
23 }
24 pub fn saveInfo(_: *http.HeadersMap, _: std.mem.Allocator, _: oauth2.Provider, _: []const u8, _: []const u8, _: json.Document, _: json.Document) !void {
25 //
26 }
27 };
28 const H = oauth2.Handlers(S);
29 std.testing.refAllDecls(oauth2.Handlers(S));
30 _ = @TypeOf(H.login(undefined, nio.NullWriter{}, undefined, undefined, undefined, undefined, undefined));
31 _ = @TypeOf(H.callback(undefined, nio.NullWriter{}, undefined, undefined, undefined, undefined, undefined));
7}32}
zig.mod+4
...@@ -12,3 +12,7 @@ dependencies:...@@ -12,3 +12,7 @@ dependencies:
12 - src: git https://github.com/nektro/zig-net-http12 - src: git https://github.com/nektro/zig-net-http
13 - src: git https://github.com/nektro/zig-nio13 - src: git https://github.com/nektro/zig-nio
14 - src: git https://github.com/nektro/zig-json14 - src: git https://github.com/nektro/zig-json
15root_dependencies:
16 - src: git https://github.com/nektro/zig-nio
17 - src: git https://github.com/nektro/zig-net-http
18 - src: git https://github.com/nektro/zig-json