From 3c22e9dac5efe7e012d252e2ccdbc8a4a7697ccd Mon Sep 17 00:00:00 2001 From: Tesseract22 Date: Fri, 8 Aug 2025 23:37:11 +0800 Subject: [PATCH] chore: update to latest zig version zig 0.15 introduced tons of breaking changes in the standard library, fix them. --- build.zig | 177 ++++++++++++++-------------------------- facil.io/build.zig | 37 +++++---- src/fio.zig | 84 +++++++++---------- src/request.zig | 8 +- src/tests/test_auth.zig | 4 +- src/zap.zig | 14 ++-- 6 files changed, 138 insertions(+), 186 deletions(-) diff --git a/build.zig b/build.zig index a3d2982..33ea909 100644 --- a/build.zig +++ b/build.zig @@ -1,6 +1,41 @@ const std = @import("std"); const build_facilio = @import("facil.io/build.zig").build_facilio; +// Basically a wrapper around some common params that you would pass around to create tests (zig made them very verbose lately, unfortunately), +// save these to a struct so you don't have to pass the same params all the time. +const TestSystem = struct { + b: *std.Build, + zap_module: *std.Build.Module, + target: std.Build.ResolvedTarget, + optimize: std.builtin.OptimizeMode, + combine_test_step: *std.Build.Step, + + pub fn addTest(self: TestSystem, root_src: []const u8, test_name: []const u8) void { + const tests_module = self.b.addModule(test_name, .{ + .root_source_file = self.b.path(root_src), + .target = self.target, + .optimize = self.optimize, + }); + const tests = self.b.addTest(.{ + .name = self.b.fmt("{s}_tests", .{test_name}), + .root_module = tests_module, + }); + tests.root_module.addImport("zap", self.zap_module); + + const step = self.b.step(self.b.fmt("test{s}", .{test_name}), self.b.fmt("Run {s} unit tests [REMOVE zig-cache!]", .{test_name})); + self.addRunInstallToStep(tests, step); + } + + fn addRunInstallToStep(self: TestSystem, tests: *std.Build.Step.Compile, step: *std.Build.Step) void { + const run_tests = self.b.addRunArtifact(tests); + const install_tests = self.b.addInstallArtifact(tests, .{}); + step.dependOn(&run_tests.step); + step.dependOn(&install_tests.step); + + self.combine_test_step.dependOn(step); + } +}; + pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); if (target.result.os.tag == .windows) { @@ -34,9 +69,7 @@ pub fn build(b: *std.Build) !void { // -- Docs const docs_obj = b.addObject(.{ .name = "zap", // name doesn't seem to matter - .root_source_file = b.path("src/zap.zig"), - .target = target, - .optimize = .Debug, + .root_module = zap_module, }); const install_docs = b.addInstallDirectory(.{ .install_dir = .prefix, @@ -95,13 +128,17 @@ pub fn build(b: *std.Build) !void { 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(.{ - .name = ex_name, + const exe_mod = b.addModule(ex_name, .{ .root_source_file = b.path(ex_src), .target = target, .optimize = optimize, }); + var example = b.addExecutable(.{ + .name = ex_name, + .root_module = exe_mod, + }); + example.root_module.addImport("zap", zap_module); // const example_run = example.run(); @@ -132,127 +169,34 @@ pub fn build(b: *std.Build) !void { // So, for now, we just force the exe to be built, so in order that // we can call it again when needed. + const test_step = b.step("test", "Run unit tests"); + const test_system = TestSystem {.b = b, .zap_module = zap_module, .target = target, .optimize = optimize, .combine_test_step = test_step}; // authentication tests - // - const auth_tests = b.addTest(.{ - .name = "auth_tests", - .root_source_file = b.path("src/tests/test_auth.zig"), - .target = target, - .optimize = optimize, - }); - auth_tests.root_module.addImport("zap", zap_module); - - const run_auth_tests = b.addRunArtifact(auth_tests); - const install_auth_tests = b.addInstallArtifact(auth_tests, .{}); - + test_system.addTest("src/tests/test_auth.zig", "auth"); // mustache tests - const mustache_tests = b.addTest(.{ - .name = "mustache_tests", - .root_source_file = b.path("src/tests/test_mustache.zig"), - .target = target, - .optimize = optimize, - }); - mustache_tests.root_module.addImport("zap", zap_module); - - const run_mustache_tests = b.addRunArtifact(mustache_tests); - const install_mustache_tests = b.addInstallArtifact(mustache_tests, .{}); - + test_system.addTest("src/tests/test_mustache.zig", "mustache"); // http paramters (qyery, body) tests - const httpparams_tests = b.addTest(.{ - .name = "http_params_tests", - .root_source_file = b.path("src/tests/test_http_params.zig"), - .target = target, - .optimize = optimize, - }); - - httpparams_tests.root_module.addImport("zap", zap_module); - - const run_httpparams_tests = b.addRunArtifact(httpparams_tests); + test_system.addTest("src/tests/test_http_params.zig", "http_params"); + // http paramters (qyery, body) tests + test_system.addTest("src/tests/test_sendfile.zig", "sendfile"); + test_system.addTest("src/tests/test_recvfile.zig", "recv"); + test_system.addTest("src/tests/test_recvfile_notype.zig", "recv_notype"); // TODO: for some reason, tests aren't run more than once unless // dependencies have changed. // So, for now, we just force the exe to be built, so in order that // we can call it again when needed. - const install_httpparams_tests = b.addInstallArtifact(httpparams_tests, .{}); - - // http paramters (qyery, body) tests - const sendfile_tests = b.addTest(.{ - .name = "sendfile_tests", - .root_source_file = b.path("src/tests/test_sendfile.zig"), - .target = target, - .optimize = optimize, - }); - - sendfile_tests.root_module.addImport("zap", zap_module); - const run_sendfile_tests = b.addRunArtifact(sendfile_tests); - const install_sendfile_tests = b.addInstallArtifact(sendfile_tests, .{}); - - const recvfile_tests = b.addTest(.{ - .name = "recv_tests", - .root_source_file = b.path("src/tests/test_recvfile.zig"), - .target = target, - .optimize = optimize, - }); - - recvfile_tests.root_module.addImport("zap", zap_module); - const run_recvfile_tests = b.addRunArtifact(recvfile_tests); - const install_recvfile_tests = b.addInstallArtifact(recvfile_tests, .{}); - - const recvfile_notype_tests = b.addTest(.{ - .name = "recv_tests", - .root_source_file = b.path("src/tests/test_recvfile_notype.zig"), - .target = target, - .optimize = optimize, - }); - - recvfile_notype_tests.root_module.addImport("zap", zap_module); - const run_recvfile_notype_tests = b.addRunArtifact(recvfile_notype_tests); - const install_recvfile_notype_tests = b.addInstallArtifact(recvfile_notype_tests, .{}); - - // test commands - const run_auth_test_step = b.step("test-authentication", "Run auth unit tests [REMOVE zig-cache!]"); - run_auth_test_step.dependOn(&run_auth_tests.step); - run_auth_test_step.dependOn(&install_auth_tests.step); - - const run_mustache_test_step = b.step("test-mustache", "Run mustache unit tests [REMOVE zig-cache!]"); - run_mustache_test_step.dependOn(&run_mustache_tests.step); - run_mustache_test_step.dependOn(&install_mustache_tests.step); - - const run_httpparams_test_step = b.step("test-httpparams", "Run http param unit tests [REMOVE zig-cache!]"); - run_httpparams_test_step.dependOn(&run_httpparams_tests.step); - run_httpparams_test_step.dependOn(&install_httpparams_tests.step); - - const run_sendfile_test_step = b.step("test-sendfile", "Run http param unit tests [REMOVE zig-cache!]"); - run_sendfile_test_step.dependOn(&run_sendfile_tests.step); - run_sendfile_test_step.dependOn(&install_sendfile_tests.step); - - const run_recvfile_test_step = b.step("test-recvfile", "Run http param unit tests [REMOVE zig-cache!]"); - run_recvfile_test_step.dependOn(&run_recvfile_tests.step); - run_recvfile_test_step.dependOn(&install_recvfile_tests.step); - - const run_recvfile_notype_test_step = b.step("test-recvfile_notype", "Run http param unit tests [REMOVE zig-cache!]"); - run_recvfile_notype_test_step.dependOn(&run_recvfile_notype_tests.step); - run_recvfile_notype_test_step.dependOn(&install_recvfile_notype_tests.step); - - // Similar to creating the run step earlier, this exposes a `test` step to - // the `zig build --help` menu, providing a way for the participant to request - // running the unit tests. - const test_step = b.step("test", "Run unit tests"); - test_step.dependOn(&run_auth_tests.step); - test_step.dependOn(&run_mustache_tests.step); - test_step.dependOn(&run_httpparams_tests.step); - test_step.dependOn(&run_sendfile_tests.step); - test_step.dependOn(&run_recvfile_tests.step); - test_step.dependOn(&run_recvfile_notype_tests.step); - + // // docserver - // - const docserver_exe = b.addExecutable(.{ - .name = "docserver", + const docserver_mod = b.addModule("docserver", .{ .root_source_file = b.path("./tools/docserver.zig"), .target = target, .optimize = optimize, }); + const docserver_exe = b.addExecutable(.{ + .name = "docserver", + .root_module = docserver_mod, + }); docserver_exe.root_module.addImport("zap", zap_module); var docserver_step = b.step("docserver", "Build docserver"); const docserver_build_step = b.addInstallArtifact(docserver_exe, .{}); @@ -271,12 +215,15 @@ pub fn build(b: *std.Build) !void { // // announceybot // - const announceybot_exe = b.addExecutable(.{ - .name = "announceybot", + const announceybot_mod = b.addModule("announceybot", .{ .root_source_file = b.path("./tools/announceybot.zig"), .target = target, .optimize = optimize, }); + const announceybot_exe = b.addExecutable(.{ + .name = "announceybot", + .root_module = announceybot_mod, + }); var announceybot_step = b.step("announceybot", "Build announceybot"); const announceybot_build_step = b.addInstallArtifact(announceybot_exe, .{}); announceybot_step.dependOn(&announceybot_build_step.step); diff --git a/facil.io/build.zig b/facil.io/build.zig index 179faca..6028378 100644 --- a/facil.io/build.zig +++ b/facil.io/build.zig @@ -7,10 +7,16 @@ pub fn build_facilio( optimize: std.builtin.OptimizeMode, use_openssl: bool, ) !*std.Build.Step.Compile { - const lib = b.addStaticLibrary(.{ - .name = "facil.io", + const mod = b.addModule("facil.io", .{ .target = target, .optimize = optimize, + .link_libc = true, + }); + + const lib = b.addLibrary(.{ + .name = "facil.io", + .root_module = mod, + .linkage = .dynamic }); // Generate flags @@ -32,17 +38,17 @@ pub fn build_facilio( try flags.append("-DHAVE_OPENSSL -DFIO_TLS_FOUND"); // Include paths - lib.addIncludePath(b.path(subdir ++ "/.")); - lib.addIncludePath(b.path(subdir ++ "/lib/facil")); - lib.addIncludePath(b.path(subdir ++ "/lib/facil/fiobj")); - lib.addIncludePath(b.path(subdir ++ "/lib/facil/cli")); - lib.addIncludePath(b.path(subdir ++ "/lib/facil/http")); - lib.addIncludePath(b.path(subdir ++ "/lib/facil/http/parsers")); + mod.addIncludePath(b.path(subdir ++ "/.")); + mod.addIncludePath(b.path(subdir ++ "/lib/facil")); + mod.addIncludePath(b.path(subdir ++ "/lib/facil/fiobj")); + mod.addIncludePath(b.path(subdir ++ "/lib/facil/cli")); + mod.addIncludePath(b.path(subdir ++ "/lib/facil/http")); + mod.addIncludePath(b.path(subdir ++ "/lib/facil/http/parsers")); if (use_openssl) - lib.addIncludePath(b.path(subdir ++ "/lib/facil/tls")); + mod.addIncludePath(b.path(subdir ++ "/lib/facil/tls")); // C source files - lib.addCSourceFiles(.{ + mod.addCSourceFiles(.{ .files = &.{ subdir ++ "/lib/facil/fio.c", subdir ++ "/lib/facil/fio_zig.c", @@ -65,7 +71,7 @@ pub fn build_facilio( }); if (use_openssl) { - lib.addCSourceFiles(.{ + mod.addCSourceFiles(.{ .files = &.{ subdir ++ "/lib/facil/tls/fio_tls_openssl.c", subdir ++ "/lib/facil/tls/fio_tls_missing.c", @@ -74,13 +80,10 @@ pub fn build_facilio( }); } - // link against libc - lib.linkLibC(); - - // link in libopenssl and libcrypto on demand + // link in modopenssl and libcrypto on demand if (use_openssl) { - lib.linkSystemLibrary("ssl"); - lib.linkSystemLibrary("crypto"); + mod.linkSystemLibrary("ssl", .{}); + mod.linkSystemLibrary("crypto", .{}); } b.installArtifact(lib); diff --git a/src/fio.zig b/src/fio.zig index c200ca5..c96633f 100644 --- a/src/fio.zig +++ b/src/fio.zig @@ -39,10 +39,10 @@ pub const struct_timespec = extern struct { tv_nsec: __syscall_slong_t, }; pub const struct_http_settings_s = extern struct { - on_request: ?*const fn ([*c]http_s) callconv(.C) void, - on_upgrade: ?*const fn ([*c]http_s, [*c]u8, usize) callconv(.C) void, - on_response: ?*const fn ([*c]http_s) callconv(.C) void, - on_finish: ?*const fn ([*c]struct_http_settings_s) callconv(.C) void, + on_request: ?*const fn ([*c]http_s) callconv(.c) void, + on_upgrade: ?*const fn ([*c]http_s, [*c]u8, usize) callconv(.c) void, + on_response: ?*const fn ([*c]http_s) callconv(.c) void, + on_finish: ?*const fn ([*c]struct_http_settings_s) callconv(.c) void, udata: ?*anyopaque, public_folder: [*c]const u8, public_folder_length: usize, @@ -124,7 +124,7 @@ pub const struct_fio_str_info_s = extern struct { }; pub const fio_str_info_s = struct_fio_str_info_s; pub extern fn http_send_body(h: [*c]http_s, data: ?*anyopaque, length: usize) c_int; -pub fn fiobj_each1(arg_o: FIOBJ, arg_start_at: usize, arg_task: ?*const fn (FIOBJ, ?*anyopaque) callconv(.C) c_int, arg_arg: ?*anyopaque) callconv(.C) usize { +pub fn fiobj_each1(arg_o: FIOBJ, arg_start_at: usize, arg_task: ?*const fn (FIOBJ, ?*anyopaque) callconv(.c) c_int, arg_arg: ?*anyopaque) callconv(.c) usize { const o = arg_o; const start_at = arg_start_at; const task = arg_task; @@ -160,7 +160,7 @@ pub extern fn fiobj_float_new(num: f64) FIOBJ; pub extern fn fiobj_num_new_bignum(num: isize) FIOBJ; pub extern fn fiobj_data_newstr() FIOBJ; -pub extern fn fiobj_data_newstr2(buffer: ?*anyopaque, length: usize, dealloc: ?*const fn (?*anyopaque) callconv(.C) void) FIOBJ; +pub extern fn fiobj_data_newstr2(buffer: ?*anyopaque, length: usize, dealloc: ?*const fn (?*anyopaque) callconv(.c) void) FIOBJ; pub extern fn fiobj_data_newtmpfile() FIOBJ; pub extern fn fiobj_data_newfd(fd: c_int) FIOBJ; pub extern fn fiobj_data_slice(parent: FIOBJ, offset: isize, length: usize) FIOBJ; @@ -222,14 +222,14 @@ pub extern fn fio_tls_accept(uuid: *u32, tls: ?*anyopaque, udata: ?*anyopaque) v /// were added using fio_tls_alpn_add). pub extern fn fio_tls_connect(uuid: *u32, tls: ?*anyopaque, udata: ?*anyopaque) void; -pub extern fn fiobj_free_wrapped(o: FIOBJ) callconv(.C) void; -pub fn fiobj_null() callconv(.C) FIOBJ { +pub extern fn fiobj_free_wrapped(o: FIOBJ) callconv(.c) void; +pub fn fiobj_null() callconv(.c) FIOBJ { return @as(FIOBJ, @bitCast(@as(c_long, FIOBJ_T_NULL))); } -pub fn fiobj_true() callconv(.C) FIOBJ { +pub fn fiobj_true() callconv(.c) FIOBJ { return @as(FIOBJ, @bitCast(@as(c_long, FIOBJ_T_TRUE))); } -pub fn fiobj_false() callconv(.C) FIOBJ { +pub fn fiobj_false() callconv(.c) FIOBJ { return @as(FIOBJ, @bitCast(@as(c_long, FIOBJ_T_FALSE))); } pub extern fn fiobj_str_new(str: [*c]const u8, len: usize) FIOBJ; @@ -281,20 +281,20 @@ pub const FIOBJ_T_UNKNOWN: c_int = 44; pub const fiobj_type_enum = u8; pub const fiobj_object_vtable_s = extern struct { class_name: [*c]const u8, - dealloc: ?*const fn (FIOBJ, ?*const fn (FIOBJ, ?*anyopaque) callconv(.C) void, ?*anyopaque) callconv(.C) void, - count: ?*const fn (FIOBJ) callconv(.C) usize, - is_true: ?*const fn (FIOBJ) callconv(.C) usize, - is_eq: ?*const fn (FIOBJ, FIOBJ) callconv(.C) usize, - each: ?*const fn (FIOBJ, usize, ?*const fn (FIOBJ, ?*anyopaque) callconv(.C) c_int, ?*anyopaque) callconv(.C) usize, - to_str: ?*const fn (FIOBJ) callconv(.C) fio_str_info_s, - to_i: ?*const fn (FIOBJ) callconv(.C) isize, - to_f: ?*const fn (FIOBJ) callconv(.C) f64, + dealloc: ?*const fn (FIOBJ, ?*const fn (FIOBJ, ?*anyopaque) callconv(.c) void, ?*anyopaque) callconv(.c) void, + count: ?*const fn (FIOBJ) callconv(.c) usize, + is_true: ?*const fn (FIOBJ) callconv(.c) usize, + is_eq: ?*const fn (FIOBJ, FIOBJ) callconv(.c) usize, + each: ?*const fn (FIOBJ, usize, ?*const fn (FIOBJ, ?*anyopaque) callconv(.c) c_int, ?*anyopaque) callconv(.c) usize, + to_str: ?*const fn (FIOBJ) callconv(.c) fio_str_info_s, + to_i: ?*const fn (FIOBJ) callconv(.c) isize, + to_f: ?*const fn (FIOBJ) callconv(.c) f64, }; pub const fiobj_object_header_s = extern struct { type: fiobj_type_enum, ref: u32, }; -pub fn fiobj_type_is(arg_o: FIOBJ, arg_type: fiobj_type_enum) callconv(.C) usize { +pub fn fiobj_type_is(arg_o: FIOBJ, arg_type: fiobj_type_enum) callconv(.c) usize { const o = arg_o; const @"type" = arg_type; while (true) { @@ -317,7 +317,7 @@ pub fn fiobj_type_is(arg_o: FIOBJ, arg_type: fiobj_type_enum) callconv(.C) usize } return @as(usize, @bitCast(@as(c_long, @intFromBool((((o != 0) and ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1))))) == @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 0)))))) and ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6))))) != @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6)))))) and (@as(c_int, @bitCast(@as(c_uint, @as([*c]fiobj_type_enum, @ptrCast(@alignCast(@as(?*anyopaque, @ptrFromInt(o & ~@as(usize, @bitCast(@as(c_long, @as(c_int, 7)))))))))[@as(c_uint, @intCast(@as(c_int, 0)))]))) == @as(c_int, @bitCast(@as(c_uint, @"type")))))))); } -pub fn fiobj_type(arg_o: FIOBJ) callconv(.C) fiobj_type_enum { +pub fn fiobj_type(arg_o: FIOBJ) callconv(.c) fiobj_type_enum { const o = arg_o; if (!(o != 0)) return @as(u8, @bitCast(@as(i8, @truncate(FIOBJ_T_NULL)))); if ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1))))) != 0) return @as(u8, @bitCast(@as(i8, @truncate(FIOBJ_T_NUMBER)))); @@ -332,7 +332,7 @@ pub extern const FIOBJECT_VTABLE_STRING: fiobj_object_vtable_s; pub extern const FIOBJECT_VTABLE_ARRAY: fiobj_object_vtable_s; pub extern const FIOBJECT_VTABLE_HASH: fiobj_object_vtable_s; pub extern const FIOBJECT_VTABLE_DATA: fiobj_object_vtable_s; -pub fn fiobj_type_vtable(arg_o: FIOBJ) callconv(.C) [*c]const fiobj_object_vtable_s { +pub fn fiobj_type_vtable(arg_o: FIOBJ) callconv(.c) [*c]const fiobj_object_vtable_s { const o = arg_o; while (true) { switch (@as(c_int, @bitCast(@as(c_uint, fiobj_type(o))))) { @@ -350,7 +350,7 @@ pub fn fiobj_type_vtable(arg_o: FIOBJ) callconv(.C) [*c]const fiobj_object_vtabl return null; } -pub fn fiobj_obj2num(o: FIOBJ) callconv(.C) isize { +pub fn fiobj_obj2num(o: FIOBJ) callconv(.c) isize { if ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1))))) != 0) { const sign: usize = if ((o & ~(~@as(usize, @bitCast(@as(c_long, @as(c_int, 0)))) >> @as(@import("std").math.Log2Int(usize), @intCast(1)))) != 0) ~(~@as(usize, @bitCast(@as(c_long, @as(c_int, 0)))) >> @as(@import("std").math.Log2Int(usize), @intCast(1))) | (~(~@as(usize, @bitCast(@as(c_long, @as(c_int, 0)))) >> @as(@import("std").math.Log2Int(usize), @intCast(1))) >> @as(@import("std").math.Log2Int(usize), @intCast(1))) else @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 0)))); return @as(isize, @bitCast(((o & (~@as(usize, @bitCast(@as(c_long, @as(c_int, 0)))) >> @as(@import("std").math.Log2Int(usize), @intCast(1)))) >> @as(@import("std").math.Log2Int(c_ulong), @intCast(1))) | sign)); @@ -358,7 +358,7 @@ pub fn fiobj_obj2num(o: FIOBJ) callconv(.C) isize { if (!(o != 0) or !(((o != 0) and ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1))))) == @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 0)))))) and ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6))))) != @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6))))))) return @as(isize, @bitCast(@as(c_long, @intFromBool(o == @as(c_ulong, @bitCast(@as(c_long, FIOBJ_T_TRUE))))))); return fiobj_type_vtable(o).*.to_i.?(o); } -pub fn fiobj_obj2float(o: FIOBJ) callconv(.C) f64 { +pub fn fiobj_obj2float(o: FIOBJ) callconv(.c) f64 { if ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1))))) != 0) return @as(f64, @floatFromInt(fiobj_obj2num(o))); // the below doesn't parse and we don't support ints here anyway // if (!(o != 0) or ((o & @bitCast(c_ulong, @as(c_long, @as(c_int, 6)))) == @bitCast(c_ulong, @as(c_long, @as(c_int, 6))))) return @intToFloat(f64, o == @bitCast(c_ulong, @as(c_long, FIOBJ_T_TRUE))); @@ -366,7 +366,7 @@ pub fn fiobj_obj2float(o: FIOBJ) callconv(.C) f64 { } pub extern fn fio_ltocstr(c_long) fio_str_info_s; -pub fn fiobj_obj2cstr(o: FIOBJ) callconv(.C) fio_str_info_s { +pub fn fiobj_obj2cstr(o: FIOBJ) callconv(.c) fio_str_info_s { if (!(o != 0)) { const ret: fio_str_info_s = fio_str_info_s{ .capa = @as(usize, @bitCast(@as(c_long, @as(c_int, 0)))), @@ -431,8 +431,8 @@ pub extern fn http_push_data(h: [*c]http_s, data: ?*anyopaque, length: usize, mi pub extern fn http_push_file(h: [*c]http_s, filename: FIOBJ, mime_type: FIOBJ) c_int; pub const struct_http_pause_handle_s = opaque {}; pub const http_pause_handle_s = struct_http_pause_handle_s; -pub extern fn http_pause(h: [*c]http_s, task: ?*const fn (?*http_pause_handle_s) callconv(.C) void) void; -pub extern fn http_resume(http: ?*http_pause_handle_s, task: ?*const fn ([*c]http_s) callconv(.C) void, fallback: ?*const fn (?*anyopaque) callconv(.C) void) void; +pub extern fn http_pause(h: [*c]http_s, task: ?*const fn (?*http_pause_handle_s) callconv(.c) void) void; +pub extern fn http_resume(http: ?*http_pause_handle_s, task: ?*const fn ([*c]http_s) callconv(.c) void, fallback: ?*const fn (?*anyopaque) callconv(.c) void) void; pub extern fn http_paused_udata_get(http: ?*http_pause_handle_s) ?*anyopaque; pub extern fn http_paused_udata_set(http: ?*http_pause_handle_s, udata: ?*anyopaque) ?*anyopaque; pub extern fn http_listen(port: [*c]const u8, binding: [*c]const u8, struct_http_settings_s) isize; @@ -443,11 +443,11 @@ pub extern fn http_hijack(h: [*c]http_s, leftover: [*c]fio_str_info_s) isize; pub const struct_ws_s = opaque {}; pub const ws_s = struct_ws_s; pub const websocket_settings_s = extern struct { - on_message: ?*const fn (?*ws_s, fio_str_info_s, u8) callconv(.C) void, - on_open: ?*const fn (?*ws_s) callconv(.C) void, - on_ready: ?*const fn (?*ws_s) callconv(.C) void, - on_shutdown: ?*const fn (?*ws_s) callconv(.C) void, - on_close: ?*const fn (isize, ?*anyopaque) callconv(.C) void, + on_message: ?*const fn (?*ws_s, fio_str_info_s, u8) callconv(.c) void, + on_open: ?*const fn (?*ws_s) callconv(.c) void, + on_ready: ?*const fn (?*ws_s) callconv(.c) void, + on_shutdown: ?*const fn (?*ws_s) callconv(.c) void, + on_close: ?*const fn (isize, ?*anyopaque) callconv(.c) void, udata: ?*anyopaque, }; @@ -465,8 +465,8 @@ pub const websocket_settings_s = extern struct { pub const websocket_subscribe_s_zigcompat = extern struct { ws: ?*ws_s, channel: fio_str_info_s, - on_message: ?*const fn (?*ws_s, fio_str_info_s, fio_str_info_s, ?*anyopaque) callconv(.C) void, - on_unsubscribe: ?*const fn (?*anyopaque) callconv(.C) void, + on_message: ?*const fn (?*ws_s, fio_str_info_s, fio_str_info_s, ?*anyopaque) callconv(.c) void, + on_unsubscribe: ?*const fn (?*anyopaque) callconv(.c) void, udata: ?*anyopaque, match: fio_match_fn, force_binary: u8, @@ -474,7 +474,7 @@ pub const websocket_subscribe_s_zigcompat = extern struct { }; /// 0 on failure -pub extern fn websocket_subscribe_zigcompat(websocket_subscribe_s_zigcompat) callconv(.C) usize; +pub extern fn websocket_subscribe_zigcompat(websocket_subscribe_s_zigcompat) callconv(.c) usize; pub extern fn http_upgrade2ws(http: [*c]http_s, websocket_settings_s) c_int; pub extern fn websocket_connect(url: [*c]const u8, settings: websocket_settings_s) c_int; @@ -504,19 +504,19 @@ pub const struct_fio_publish_args_s = extern struct { pub const http_sse_s = struct_http_sse_s; pub const struct_http_sse_s = extern struct { - on_open: ?*const fn ([*c]http_sse_s) callconv(.C) void, - on_ready: ?*const fn ([*c]http_sse_s) callconv(.C) void, - on_shutdown: ?*const fn ([*c]http_sse_s) callconv(.C) void, - on_close: ?*const fn ([*c]http_sse_s) callconv(.C) void, + on_open: ?*const fn ([*c]http_sse_s) callconv(.c) void, + on_ready: ?*const fn ([*c]http_sse_s) callconv(.c) void, + on_shutdown: ?*const fn ([*c]http_sse_s) callconv(.c) void, + on_close: ?*const fn ([*c]http_sse_s) callconv(.c) void, udata: ?*anyopaque, }; pub extern fn http_upgrade2sse(h: [*c]http_s, http_sse_s) c_int; pub extern fn http_sse_set_timout(sse: [*c]http_sse_s, timeout: u8) void; -pub const fio_match_fn = ?*const fn (fio_str_info_s, fio_str_info_s) callconv(.C) c_int; +pub const fio_match_fn = ?*const fn (fio_str_info_s, fio_str_info_s) callconv(.c) c_int; pub const struct_http_sse_subscribe_args = extern struct { channel: fio_str_info_s, - on_message: ?*const fn ([*c]http_sse_s, fio_str_info_s, fio_str_info_s, ?*anyopaque) callconv(.C) void, - on_unsubscribe: ?*const fn (?*anyopaque) callconv(.C) void, + on_message: ?*const fn ([*c]http_sse_s, fio_str_info_s, fio_str_info_s, ?*anyopaque) callconv(.c) void, + on_unsubscribe: ?*const fn (?*anyopaque) callconv(.c) void, udata: ?*anyopaque, match: fio_match_fn, }; @@ -564,7 +564,7 @@ pub extern fn http_gmtime(timer: time_t, tmbuf: [*c]struct_tm) [*c]struct_tm; pub extern fn http_date2rfc7231(target: [*c]u8, tmbuf: [*c]struct_tm) usize; pub extern fn http_date2rfc2109(target: [*c]u8, tmbuf: [*c]struct_tm) usize; pub extern fn http_date2rfc2822(target: [*c]u8, tmbuf: [*c]struct_tm) usize; -pub fn http_date2str(arg_target: [*c]u8, arg_tmbuf: [*c]struct_tm) callconv(.C) usize { +pub fn http_date2str(arg_target: [*c]u8, arg_tmbuf: [*c]struct_tm) callconv(.c) usize { const target = arg_target; const tmbuf = arg_tmbuf; return http_date2rfc7231(target, tmbuf); diff --git a/src/request.zig b/src/request.zig index 4129441..ad23fab 100644 --- a/src/request.zig +++ b/src/request.zig @@ -362,12 +362,14 @@ pub fn _internal_sendError(self: *const Request, err: anyerror, err_trace: ?std. var fba = std.heap.FixedBufferAllocator.init(&buf); var string = std.ArrayList(u8).init(fba.allocator()); var writer = string.writer(); + // TODO: fix this when 0.15 is released? + var new_api_adapter = writer.adaptToNewApi(); try writer.print("ERROR: {any}\n\n", .{err}); if (err_trace) |trace| { const debugInfo = try std.debug.getSelfDebugInfo(); const ttyConfig: std.io.tty.Config = .no_color; - try std.debug.writeStackTrace(trace, writer, debugInfo, ttyConfig); + try std.debug.writeStackTrace(trace, &new_api_adapter.new_interface, debugInfo, ttyConfig); } try self.sendBody(string.items); @@ -751,7 +753,7 @@ const CallbackContext_KV = struct { params: *std.ArrayList(HttpParamKV), last_error: ?anyerror = null, - pub fn callback(fiobj_value: fio.FIOBJ, context_: ?*anyopaque) callconv(.C) c_int { + pub fn callback(fiobj_value: fio.FIOBJ, context_: ?*anyopaque) callconv(.c) c_int { const ctx: *CallbackContext_KV = @as(*CallbackContext_KV, @ptrCast(@alignCast(context_))); // this is thread-safe, guaranteed by fio const fiobj_key: fio.FIOBJ = fio.fiobj_hash_key_in_loop(); @@ -780,7 +782,7 @@ const CallbackContext_StrKV = struct { params: *std.ArrayList(HttpParamStrKV), last_error: ?anyerror = null, - pub fn callback(fiobj_value: fio.FIOBJ, context_: ?*anyopaque) callconv(.C) c_int { + pub fn callback(fiobj_value: fio.FIOBJ, context_: ?*anyopaque) callconv(.c) c_int { const ctx: *CallbackContext_StrKV = @as(*CallbackContext_StrKV, @ptrCast(@alignCast(context_))); // this is thread-safe, guaranteed by fio const fiobj_key: fio.FIOBJ = fio.fiobj_hash_key_in_loop(); diff --git a/src/tests/test_auth.zig b/src/tests/test_auth.zig index 40c3326..ec87be2 100644 --- a/src/tests/test_auth.zig +++ b/src/tests/test_auth.zig @@ -154,7 +154,7 @@ pub const Endpoint = struct { pub fn get(_: *Endpoint, r: zap.Request) !void { r.sendBody(HTTP_RESPONSE) catch return; received_response = HTTP_RESPONSE; - std.time.sleep(1 * std.time.ns_per_s); + std.Thread.sleep(1 * std.time.ns_per_s); zap.stop(); } @@ -162,7 +162,7 @@ pub const Endpoint = struct { r.setStatus(.unauthorized); r.sendBody("UNAUTHORIZED ACCESS") catch return; received_response = "UNAUTHORIZED"; - std.time.sleep(1 * std.time.ns_per_s); + std.Thread.sleep(1 * std.time.ns_per_s); zap.stop(); } }; diff --git a/src/zap.zig b/src/zap.zig index 0bee72a..4e20ddd 100644 --- a/src/zap.zig +++ b/src/zap.zig @@ -116,7 +116,7 @@ pub const ContentType = enum { }; /// Used internally: facilio Http request callback function type -pub const FioHttpRequestFn = *const fn (r: [*c]fio.http_s) callconv(.C) void; +pub const FioHttpRequestFn = *const fn (r: [*c]fio.http_s) callconv(.c) void; /// Zap Http request callback function type. pub const HttpRequestFn = *const fn (Request) anyerror!void; @@ -169,7 +169,7 @@ pub const HttpListener = struct { // we could make it dynamic by passing a HttpListener via udata /// Used internally: the listener's facilio request callback - pub fn theOneAndOnlyRequestCallBack(r: [*c]fio.http_s) callconv(.C) void { + pub fn theOneAndOnlyRequestCallBack(r: [*c]fio.http_s) callconv(.c) void { if (the_one_and_only_listener) |l| { var req: Request = .{ .path = util.fio2str(r.*.path), @@ -196,7 +196,7 @@ pub const HttpListener = struct { } /// Used internally: the listener's facilio response callback - pub fn theOneAndOnlyResponseCallBack(r: [*c]fio.http_s) callconv(.C) void { + pub fn theOneAndOnlyResponseCallBack(r: [*c]fio.http_s) callconv(.c) void { if (the_one_and_only_listener) |l| { var req: Request = .{ .path = util.fio2str(r.*.path), @@ -219,7 +219,7 @@ pub const HttpListener = struct { } /// Used internally: the listener's facilio upgrade callback - pub fn theOneAndOnlyUpgradeCallBack(r: [*c]fio.http_s, target: [*c]u8, target_len: usize) callconv(.C) void { + pub fn theOneAndOnlyUpgradeCallBack(r: [*c]fio.http_s, target: [*c]u8, target_len: usize) callconv(.c) void { if (the_one_and_only_listener) |l| { var req: Request = .{ .path = util.fio2str(r.*.path), @@ -243,7 +243,7 @@ pub const HttpListener = struct { } /// Used internally: the listener's facilio finish callback - pub fn theOneAndOnlyFinishCallBack(s: [*c]fio.struct_http_settings_s) callconv(.C) void { + pub fn theOneAndOnlyFinishCallBack(s: [*c]fio.struct_http_settings_s) callconv(.c) void { if (the_one_and_only_listener) |l| { l.settings.on_finish.?(s) catch |err| { Logging.on_uncaught_error("HttpListener on_finish", err); @@ -288,7 +288,7 @@ pub const HttpListener = struct { // in debug2 and debug3 of hello example // std.debug.print("X\n", .{}); // TODO: still happening? - std.time.sleep(500 * std.time.ns_per_ms); + std.Thread.sleep(500 * std.time.ns_per_ms); var portbuf: [100]u8 = undefined; const printed_port = try std.fmt.bufPrintZ(&portbuf, "{d}", .{self.settings.port}); @@ -364,7 +364,7 @@ pub const LowLevel = struct { // in debug2 and debug3 of hello example // std.debug.print("X\n", .{}); // TODO: still happening? - std.time.sleep(500 * std.time.ns_per_ms); + std.Thread.sleep(500 * std.time.ns_per_ms); if (fio.http_listen(port, interface, x) == -1) { return error.ListenError;