From 93cb49e9328664303468ef3ba06f1263a90f8c91 Mon Sep 17 00:00:00 2001 From: robert y <6729524+freylax@users.noreply.github.com> Date: Tue, 1 Oct 2024 00:57:06 +0200 Subject: [PATCH 1/3] updated to zig master --- apps/BootNode.zig | 8 ++--- apps/Node.zig | 4 +-- apps/QueryNode.zig | 4 +-- apps/RespNode.zig | 8 ++--- apps/echo-bot.zig | 4 +-- apps/local-test.zig | 4 +-- build.zig | 21 ++++++----- build.zig.zon | 15 ++++---- src/tox.zig | 6 ++-- src/wrap.zig | 88 ++++++++++++++++++++++----------------------- 10 files changed, 82 insertions(+), 80 deletions(-) diff --git a/apps/BootNode.zig b/apps/BootNode.zig index 61c7ad2..89c6a53 100644 --- a/apps/BootNode.zig +++ b/apps/BootNode.zig @@ -34,19 +34,19 @@ fn run_(i: NodeInfo, keep_running: *bool) !void { _ = try bytesToHexBuf(&addr_bin, &addr_hex, .upper); log.debug("{s} startup, my address is: {s}", .{ i.name, addr_hex[0..] }); - while (@atomicLoad(bool, keep_running, .SeqCst)) { + while (@atomicLoad(bool, keep_running, .seq_cst)) { // log.debug("{s} iterate", .{i.name}); tox.iterate({}); - if (@atomicLoad(bool, keep_running, .SeqCst)) { + if (@atomicLoad(bool, keep_running, .seq_cst)) { std.time.sleep(tox.iterationInterval() * 1000 * 1000); } } } pub fn run(i: NodeInfo, keep_running: *bool, failed: *bool) void { - defer @atomicStore(bool, keep_running, false, .SeqCst); + defer @atomicStore(bool, keep_running, false, .seq_cst); run_(i, keep_running) catch |err| { log.err("{s}", .{@errorName(err)}); - @atomicStore(bool, failed, true, .SeqCst); + @atomicStore(bool, failed, true, .seq_cst); }; } diff --git a/apps/Node.zig b/apps/Node.zig index 98e2728..6441002 100644 --- a/apps/Node.zig +++ b/apps/Node.zig @@ -160,7 +160,7 @@ pub fn check( var falseValue: []const u8 = undefined; var wait = false; const t0 = std.time.milliTimestamp(); - while (@atomicLoad(bool, self.*.keep_running, .SeqCst)) { + while (@atomicLoad(bool, self.*.keep_running, .seq_cst)) { if (l.*.items.len > id) { if (@field(l.*.items[id], field)) |v| { if (std.mem.eql(u8, v, value)) { @@ -187,7 +187,7 @@ pub fn check( } return error.Timeout; } - if (@atomicLoad(bool, self.*.keep_running, .SeqCst) and wait) { + if (@atomicLoad(bool, self.*.keep_running, .seq_cst) and wait) { std.time.sleep(self.*.tox.iterationInterval() * 1000 * 1000); } self.*.tox.iterate(self); diff --git a/apps/QueryNode.zig b/apps/QueryNode.zig index f314cb3..4648b11 100644 --- a/apps/QueryNode.zig +++ b/apps/QueryNode.zig @@ -135,9 +135,9 @@ pub fn run( keep_running: *bool, failed: *bool, ) void { - defer @atomicStore(bool, keep_running, false, .SeqCst); + defer @atomicStore(bool, keep_running, false, .seq_cst); run_(allocator, query, boot, resp, keep_running) catch |err| { log.err("{s}", .{@errorName(err)}); - @atomicStore(bool, failed, true, .SeqCst); + @atomicStore(bool, failed, true, .seq_cst); }; } diff --git a/apps/RespNode.zig b/apps/RespNode.zig index 2bd2932..9b60939 100644 --- a/apps/RespNode.zig +++ b/apps/RespNode.zig @@ -32,9 +32,9 @@ fn run_( try node.bootstrap(boot.host, boot.port, boot.public_key); _ = try node.friendAddNoRequest(query.address); - while (@atomicLoad(bool, keep_running, .SeqCst)) { + while (@atomicLoad(bool, keep_running, .seq_cst)) { node.tox.iterate(&node); - if (@atomicLoad(bool, keep_running, .SeqCst)) { + if (@atomicLoad(bool, keep_running, .seq_cst)) { std.time.sleep(node.tox.iterationInterval() * 1000 * 1000); } } @@ -48,9 +48,9 @@ pub fn run( keep_running: *bool, failed: *bool, ) void { - defer @atomicStore(bool, keep_running, false, .SeqCst); + defer @atomicStore(bool, keep_running, false, .seq_cst); run_(allocator, query, boot, resp, keep_running) catch |err| { log.err("{s}", .{@errorName(err)}); - @atomicStore(bool, failed, true, .SeqCst); + @atomicStore(bool, failed, true, .seq_cst); }; } diff --git a/apps/echo-bot.zig b/apps/echo-bot.zig index 721e3f7..199f7cc 100644 --- a/apps/echo-bot.zig +++ b/apps/echo-bot.zig @@ -5,9 +5,9 @@ const sodium = @import("sodium"); const bytesToHexBuf = Tox.hex.bytesToHexBuf; const hexToBytes = std.fmt.hexToBytes; -pub const std_options = struct { +pub const std_options = .{ // Set the log level to info - pub const log_level = .debug; + .log_level = .debug, }; const savedata_fn = "savedata.tox"; diff --git a/apps/local-test.zig b/apps/local-test.zig index 3ce332a..4c2961a 100644 --- a/apps/local-test.zig +++ b/apps/local-test.zig @@ -4,9 +4,9 @@ const BootNode = @import("BootNode.zig"); const RespNode = @import("RespNode.zig"); const QueryNode = @import("QueryNode.zig"); -pub const std_options = struct { +pub const std_options = .{ // Set the log level to info - pub const log_level = .debug; + .log_level = .debug, }; const localhost = "127.0.0.1"; diff --git a/build.zig b/build.zig index c2cce11..9b25996 100644 --- a/build.zig +++ b/build.zig @@ -10,26 +10,26 @@ pub fn build(b: *Build) void { const optimize = b.standardOptimizeOption(.{}); const c_toxcore_dep = b.dependency( - "c-toxcore", + "build-c-toxcore-with-zig", .{ .target = target, .optimize = optimize, - .static = true, - .shared = false, + //.static = true, + //.shared = false, }, ); const libsodium_dep = b.dependency("libsodium", .{}); - const c_toxcore_lib = c_toxcore_dep.artifact("toxcore"); + const c_toxcore_lib = c_toxcore_dep.artifact("build-c-toxcore-with-zig"); const tox = b.addModule("tox", .{ - .root_source_file = .{ .path = "src/tox.zig" }, + .root_source_file = b.path("src/tox.zig"), }); - tox.addIncludePath(c_toxcore_dep.path(".")); + tox.addIncludePath(c_toxcore_dep.path("zig-out/include")); const sodium = b.addModule("sodium", .{ - .root_source_file = .{ .path = "src/sodium.zig" }, + .root_source_file = b.path("src/sodium.zig"), }); sodium.addIncludePath(libsodium_dep.path("src/libsodium/include")); const test_exe = b.addTest(.{ - .root_source_file = .{ .path = "src/tox.zig" }, + .root_source_file = b.path("src/tox.zig"), .target = target, .optimize = optimize, }); @@ -45,9 +45,8 @@ pub fn build(b: *Build) void { inline for (APPS) |app_name| { const app = b.addExecutable(.{ .name = app_name, - .root_source_file = .{ - .path = "apps" ++ std.fs.path.sep_str ++ app_name ++ ".zig", - }, + .root_source_file = b.path("apps" ++ std.fs.path.sep_str ++ app_name ++ ".zig"), + .target = target, .optimize = optimize, }); diff --git a/build.zig.zon b/build.zig.zon index 88607a2..b926765 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -3,13 +3,16 @@ .version = "0.0.1", .paths = .{""}, .dependencies = .{ + // versions used 1.0.18 .. 1.0.19 .. 1.0.20 .libsodium = .{ - .url = "https://github.com/jedisct1/libsodium/archive/56bef8abc59b6db7ce5a94ebce5d0843313d3ce2.tar.gz", - .hash = "1220af4c5faf5ab037d3e574d462d47a01796eabdf7c32e52220d4065922a2ed8f55", - }, - .@"c-toxcore" = .{ - .url = "https://github.com/nodecum/c-toxcore/archive/9f5eb26095e397c161778aad2f2b0d76dfda17ec.tar.gz", - .hash = "12203c61fa1d9e9b8eeb6c7591f68531463d557652fb6ea2df90eeb0a4e03685b998", + .url = "https://github.com/jedisct1/libsodium/archive/b4ad79202bf1ac6e40464f301e637acd3a5949c9.tar.gz", + .hash = "122079caf5b1e1b66c4ea0859debbcc076f8303950833076654e43e891dd2934d96c", + // .url = "https://github.com/jedisct1/libsodium/releases/download/1.0.20-RELEASE/libsodium-1.0.20.tar.gz", + }, + .@"build-c-toxcore-with-zig" = .{ + .path = "../build-c-toxcore-with-zig", + //.url = "https://github.com/nodecum/c-toxcore/archive/9f5eb26095e397c161778aad2f2b0d76dfda17ec.tar.gz", + //.hash = "12203c61fa1d9e9b8eeb6c7591f68531463d557652fb6ea2df90eeb0a4e03685b998", }, }, } diff --git a/src/tox.zig b/src/tox.zig index 5ed2a8d..dcaae88 100644 --- a/src/tox.zig +++ b/src/tox.zig @@ -742,9 +742,9 @@ pub fn setStatus(self: Tox, status: UserStatus) void { pub fn getStatus(self: Tox) UserStatus { return @enumFromInt(c.tox_self_get_status(self.handle)); } -//pub const std_options = struct { -// pub const log_level = .debug; -//}; +pub const std_options = .{ + .log_level = .debug, +}; test { std.testing.refAllDecls(@This()); diff --git a/src/wrap.zig b/src/wrap.zig index 0c5d159..5331355 100644 --- a/src/wrap.zig +++ b/src/wrap.zig @@ -6,7 +6,7 @@ const c = @cImport({ }); pub fn ErrSet(comptime ErrEnum: type) type { - const enum_fields = @typeInfo(ErrEnum).Enum.fields; + const enum_fields = @typeInfo(ErrEnum).@"enum".fields; // We count all enum fields which are not named 'Ok', // this will be the size of the new error set. comptime var n = 0; @@ -22,7 +22,7 @@ pub fn ErrSet(comptime ErrEnum: type) type { i += 1; } } - return @Type(Type{ .ErrorSet = &err_fields }); + return @Type(Type{ .error_set = &err_fields }); } fn getEnumValue( @@ -40,14 +40,14 @@ fn getEnumValue( /// this function returns an error if the c enum value 'cerr' /// which corresponds to an zig enum is not named 'Ok'. pub fn checkErr(cerr: anytype, comptime ErrEnum: type) ErrSet(ErrEnum)!void { - const enum_fields = @typeInfo(ErrEnum).Enum.fields; + const enum_fields = @typeInfo(ErrEnum).@"enum".fields; // let us find which enum field has the name 'Ok', // we check for this value first to have the normal case // be handled fast. const ok_value = getEnumValue("Ok", enum_fields); if (cerr == ok_value) return {}; const err_set_t = ErrSet(ErrEnum); - const err_set = @typeInfo(err_set_t).ErrorSet.?; + const err_set = @typeInfo(err_set_t).error_set.?; // now return errors inline for (err_set) |f| { // find the value for the name @@ -63,9 +63,9 @@ pub fn getResult( self: anytype, args: anytype, comptime err_enum: anytype, -) !@typeInfo(@TypeOf(fct)).Fn.return_type.? { +) !@typeInfo(@TypeOf(fct)).@"fn".return_type.? { // get the Error type - const Err = @typeInfo(@typeInfo(@TypeOf(fct)).Fn.params[args.len + 1].type.?).Pointer.child; + const Err = @typeInfo(@typeInfo(@TypeOf(fct)).@"fn".params[args.len + 1].type.?).pointer.child; var err: Err = 0; const result = @call(.auto, fct, .{self.handle} ++ args ++ .{&err}); try checkErr(err, err_enum); @@ -83,7 +83,7 @@ pub fn fillBuffer( if (buf.len < fill_len) return error.BufferTooSmall; // get the Error type - const Err = @typeInfo(@typeInfo(@TypeOf(fct)).Fn.params[args.len + 2].type.?).Pointer.child; + const Err = @typeInfo(@typeInfo(@TypeOf(fct)).@"fn".params[args.len + 2].type.?).pointer.child; var err: Err = 0; _ = @call(.auto, fct, .{self.handle} ++ args ++ .{ @as([*c]u8, @ptrCast(buf)), &err }); try checkErr(err, err_enum); @@ -103,21 +103,23 @@ fn CallbackHandle(comptime Args: []const type, comptime Context: type) type { for (Args, idx0..) |arg, i| { params[i] = .{ .type = arg, .is_generic = false, .is_noalias = false }; } - return @Type(Type{ .Fn = .{ - .calling_convention = .Unspecified, - .alignment = 0, - .is_generic = false, - .is_var_args = false, - .return_type = void, - .params = ¶ms, - } }); + return @Type(Type{ + .@"fn" = .{ + .calling_convention = .Unspecified, + //.alignment = 0, + .is_generic = false, + .is_var_args = false, + .return_type = void, + .params = ¶ms, + }, + }); } fn ZigToC(comptime T: type) type { const i = @typeInfo(T); return switch (i) { - .Enum => i.Enum.tag_type, - .Bool, .Int, .Float => T, + .@"enum" => i.@"enum".tag_type, + .bool, .int, .float => T, else => @compileError("unimplemented conversion for " ++ @typeName(T)), }; } @@ -128,10 +130,10 @@ fn cToZig(cv: anytype, comptime zy: type) zy { const zi = @typeInfo(zy); if (cy == zy) { return cv; - } else if (zi == .Pointer) { - const zpy = zi.Pointer.child; - if (zi.Pointer.size == .Slice) { - if (ci == .Struct and ci.Struct.is_tuple) { + } else if (zi == .pointer) { + const zpy = zi.pointer.child; + if (zi.pointer.size == .Slice) { + if (ci == .@"struct" and ci.@"struct".is_tuple) { // tuple of 2 args if (cv.len == 2) { // first argument @@ -141,23 +143,23 @@ fn cToZig(cv: anytype, comptime zy: type) zy { const cv1 = cv[1]; const cy1 = @TypeOf(cv1); const ci1 = @typeInfo(cy1); - if ((ci0 == .Pointer and ci0.Pointer.size == .C) and - (ci0.Pointer.child == zpy) and - ((ci1 == .Int) or (ci1 == .ComptimeInt))) + if ((ci0 == .pointer and ci0.pointer.size == .C) and + (ci0.pointer.child == zpy) and + ((ci1 == .int) or (ci1 == .comptime_int))) { // Pointer and length => slice return @as(zy, cv0[0..cv1]); } } } - } else if (zi.Pointer.size == .One) { + } else if (zi.pointer.size == .One) { return @as(zy, @ptrFromInt(@intFromPtr(cv))); - //if (ci == .Pointer and ci.Pointer.size == .C) { + //if (ci == .pointer and ci.pointer.size == .C) { // return @as(zy, @ptrFromInt(@intFromPtr(cv))); // } } - } else if (zi == .Enum) { - if (ci == .Int or ci == .ComptimeInt) { + } else if (zi == .@"enum") { + if (ci == .int or ci == .comptime_int) { return @as(zy, @enumFromInt(cv)); } } @@ -174,13 +176,13 @@ test "C to Zig" { fn CTypes(comptime args: anytype) []const type { const args_ty = @TypeOf(args); const args_ti = @typeInfo(args_ty); - if (!(args_ti == .Struct and args_ti.Struct.is_tuple)) { + if (!(args_ti == .@"struct" and args_ti.@"struct".is_tuple)) { @compileError("expected tuple argument, found " ++ @typeName(args_ty)); } comptime var n = 0; for (args) |a| { const a_ti = @typeInfo(@TypeOf(a)); - if (a_ti == .Struct and a_ti.Struct.is_tuple) { + if (a_ti == .@"struct" and a_ti.@"struct".is_tuple) { // we drop the first, this is the Zig type for (1..a.len) |i| { // plain types are the c arguments @@ -194,7 +196,7 @@ fn CTypes(comptime args: anytype) []const type { n = 0; for (args) |a| { const a_ti = @typeInfo(@TypeOf(a)); - if (a_ti == .Struct and a_ti.Struct.is_tuple) { + if (a_ti == .@"struct" and a_ti.@"struct".is_tuple) { // we drop the first, this is the Zig type for (1..a.len) |i| { const b = a[i]; @@ -215,14 +217,14 @@ fn CTypes(comptime args: anytype) []const type { fn ZigTypes(comptime args: anytype) []const type { const args_ty = @TypeOf(args); const args_ti = @typeInfo(args_ty); - if (!(args_ti == .Struct and args_ti.Struct.is_tuple)) { + if (!(args_ti == .@"struct" and args_ti.@"struct".is_tuple)) { @compileError("expected tuple argument, found " ++ @typeName(args_ty)); } comptime var Res: [args.len]type = undefined; inline for (args, 0..) |a, i| { const a_ty = @TypeOf(a); const a_ti = @typeInfo(a_ty); - if (a_ti == .Struct and a_ti.Struct.is_tuple) { + if (a_ti == .@"struct" and a_ti.@"struct".is_tuple) { // the first member of the tuple is the // argument for the zig call Res[i] = a[0]; @@ -240,7 +242,7 @@ fn zigValues( ) std.meta.Tuple(ZigTypes(args)) { const args_ty = @TypeOf(args); const args_ti = @typeInfo(args_ty); - if (!(args_ti == .Struct and args_ti.Struct.is_tuple)) { + if (!(args_ti == .@"struct" and args_ti.@"struct".is_tuple)) { @compileError("expected tuple argument, found " ++ @typeName(args_ty)); } @@ -250,13 +252,13 @@ fn zigValues( inline for (args, 0..) |a, i| { const a_ty = @TypeOf(a); const a_ti = @typeInfo(a_ty); - if (a_ti == .Struct and a_ti.Struct.is_tuple) { + if (a_ti == .@"struct" and a_ti.@"struct".is_tuple) { comptime var d: [a.len - 1]type = undefined; inline for (1..a.len, 0..) |j, k| { const b = a[j]; const b_ty = @TypeOf(b); const b_ti = @typeInfo(b); - if (b_ti == .Struct and b_ti.Struct.is_tuple) { + if (b_ti == .@"struct" and b_ti.@"struct".is_tuple) { d[k] = b[0]; } else if (b_ty == type) { d[k] = b; @@ -273,7 +275,7 @@ fn zigValues( if (b_ty == type) { tuple[k] = c_args[ci]; ci += 1; - } else if (b_ti == .Struct and b_ti.Struct.is_tuple) { + } else if (b_ti == .@"struct" and b_ti.@"struct".is_tuple) { tuple[k] = e_args[ei]; ei += 1; } @@ -312,26 +314,24 @@ pub fn setCallback( e_args: anytype, comptime hd: CallbackHandle(ZigTypes(Args), Ctx), ) void { - //const Ctx = @TypeOf(ctx); - const Ct = CTypes(Args); - const H = switch (Ct.len) { + const H = switch (CTypes(Args).len) { 1 => struct { - fn cb(_: ?*c.Tox, c0: Ct[0], cx: ?*anyopaque) callconv(.C) void { + fn cb(_: ?*c.Tox, c0: CTypes(Args)[0], cx: ?*anyopaque) callconv(.C) void { callHandle(Ctx, Args, hd, .{c0}, e_args, cx); } }, 2 => struct { - fn cb(_: ?*c.Tox, c0: Ct[0], c1: Ct[1], cx: ?*anyopaque) callconv(.C) void { + fn cb(_: ?*c.Tox, c0: CTypes(Args)[0], c1: CTypes(Args)[1], cx: ?*anyopaque) callconv(.C) void { callHandle(Ctx, Args, hd, .{ c0, c1 }, e_args, cx); } }, 3 => struct { - fn cb(_: ?*c.Tox, c0: Ct[0], c1: Ct[1], c2: Ct[2], cx: ?*anyopaque) callconv(.C) void { + fn cb(_: ?*c.Tox, c0: CTypes(Args)[0], c1: CTypes(Args)[1], c2: CTypes(Args)[2], cx: ?*anyopaque) callconv(.C) void { callHandle(Ctx, Args, hd, .{ c0, c1, c2 }, e_args, cx); } }, 4 => struct { - fn cb(_: ?*c.Tox, c0: Ct[0], c1: Ct[1], c2: Ct[2], c3: Ct[3], cx: ?*anyopaque) callconv(.C) void { + fn cb(_: ?*c.Tox, c0: CTypes(Args)[0], c1: CTypes(Args)[1], c2: CTypes(Args)[2], c3: CTypes(Args)[3], cx: ?*anyopaque) callconv(.C) void { callHandle(Ctx, Args, hd, .{ c0, c1, c2, c3 }, e_args, cx); } }, From 3c1cdd7159ca78d6153b7b39b0e006836c83468e Mon Sep 17 00:00:00 2001 From: robert y <6729524+freylax@users.noreply.github.com> Date: Thu, 3 Oct 2024 21:26:06 +0200 Subject: [PATCH 2/3] using c-toxcore module --- build.zig | 28 +++++++++------------------- build.zig.zon | 11 +++++------ src/friend.zig | 4 +--- src/tox.zig | 5 +---- src/wrap.zig | 4 +--- 5 files changed, 17 insertions(+), 35 deletions(-) diff --git a/build.zig b/build.zig index 9b25996..6e3d270 100644 --- a/build.zig +++ b/build.zig @@ -9,32 +9,26 @@ pub fn build(b: *Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const c_toxcore_dep = b.dependency( - "build-c-toxcore-with-zig", - .{ - .target = target, - .optimize = optimize, - //.static = true, - //.shared = false, - }, - ); - const libsodium_dep = b.dependency("libsodium", .{}); - const c_toxcore_lib = c_toxcore_dep.artifact("build-c-toxcore-with-zig"); + const dep = .{ + .c_toxcore = b.dependency("c-toxcore-build-with-zig", .{ .target = target, .optimize = optimize }), + .sodium = b.dependency("libsodium", .{ .target = target, .optimize = optimize }), + }; const tox = b.addModule("tox", .{ .root_source_file = b.path("src/tox.zig"), + .target = target, + .optimize = optimize, }); - tox.addIncludePath(c_toxcore_dep.path("zig-out/include")); + tox.addImport("c-toxcore", dep.c_toxcore.module("c-toxcore")); const sodium = b.addModule("sodium", .{ .root_source_file = b.path("src/sodium.zig"), }); - sodium.addIncludePath(libsodium_dep.path("src/libsodium/include")); + sodium.addIncludePath(dep.sodium.path("src/libsodium/include")); const test_exe = b.addTest(.{ .root_source_file = b.path("src/tox.zig"), .target = target, .optimize = optimize, }); - test_exe.linkLibrary(c_toxcore_lib); - //test_exe.installLibraryHeaders(c_toxcore_lib); + test_exe.root_module.addImport("c-toxcore", dep.c_toxcore.module("c-toxcore")); b.installArtifact(test_exe); const run_test = b.addRunArtifact(test_exe); @@ -46,16 +40,12 @@ pub fn build(b: *Build) void { const app = b.addExecutable(.{ .name = app_name, .root_source_file = b.path("apps" ++ std.fs.path.sep_str ++ app_name ++ ".zig"), - .target = target, .optimize = optimize, }); app.root_module.addImport("sodium", sodium); app.root_module.addImport("tox", tox); - app.linkLibrary(c_toxcore_lib); - //app.installLibraryHeaders(c_toxcore_lib); - var run = b.addRunArtifact(app); b.installArtifact(app); if (b.args) |args| run.addArgs(args); diff --git a/build.zig.zon b/build.zig.zon index b926765..cfeb71d 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,5 +1,5 @@ .{ - .name = "zig-toxcore-c", + .name = "c-toxcore-zig", .version = "0.0.1", .paths = .{""}, .dependencies = .{ @@ -7,12 +7,11 @@ .libsodium = .{ .url = "https://github.com/jedisct1/libsodium/archive/b4ad79202bf1ac6e40464f301e637acd3a5949c9.tar.gz", .hash = "122079caf5b1e1b66c4ea0859debbcc076f8303950833076654e43e891dd2934d96c", - // .url = "https://github.com/jedisct1/libsodium/releases/download/1.0.20-RELEASE/libsodium-1.0.20.tar.gz", }, - .@"build-c-toxcore-with-zig" = .{ - .path = "../build-c-toxcore-with-zig", - //.url = "https://github.com/nodecum/c-toxcore/archive/9f5eb26095e397c161778aad2f2b0d76dfda17ec.tar.gz", - //.hash = "12203c61fa1d9e9b8eeb6c7591f68531463d557652fb6ea2df90eeb0a4e03685b998", + .@"c-toxcore-build-with-zig" = .{ + // .path = "../c-toxcore-build-with-zig", + .url = "https://github.com/nodecum/c-toxcore-build-with-zig/archive/c37ca2a97f0f97404facd7ac18e981f8f6b421ee.tar.gz", + .hash = "1220bcb9ad0aec01e1448b67ffa2e8b2e37fd5a259f402d86bdae6172b2a98c8b89c", }, }, } diff --git a/src/friend.zig b/src/friend.zig index aafaef7..0da0135 100644 --- a/src/friend.zig +++ b/src/friend.zig @@ -1,10 +1,8 @@ ///! Friend list management const std = @import("std"); +const c = @import("c-toxcore"); const Friend = @This(); const Tox = @import("tox.zig"); -const c = @cImport({ - @cInclude("toxcore/tox.h"); -}); const wrap = @import("wrap.zig"); handle: *c.Tox, diff --git a/src/tox.zig b/src/tox.zig index dcaae88..b052b69 100644 --- a/src/tox.zig +++ b/src/tox.zig @@ -1,8 +1,5 @@ const std = @import("std"); - -const c = @cImport({ - @cInclude("toxcore/tox.h"); -}); +const c = @import("c-toxcore"); pub const hex = @import("../src/hex.zig"); diff --git a/src/wrap.zig b/src/wrap.zig index 5331355..e182fbd 100644 --- a/src/wrap.zig +++ b/src/wrap.zig @@ -1,9 +1,7 @@ // wrap utils const std = @import("std"); +const c = @import("c-toxcore"); const Type = std.builtin.Type; -const c = @cImport({ - @cInclude("toxcore/tox.h"); -}); pub fn ErrSet(comptime ErrEnum: type) type { const enum_fields = @typeInfo(ErrEnum).@"enum".fields; From c8704f45b429635e98bdd3b1e63328b3421ef8ff Mon Sep 17 00:00:00 2001 From: jfreegman Date: Sat, 16 Nov 2024 14:11:21 -0500 Subject: [PATCH 3/3] fix: use std.Options per latest Zig API --- apps/echo-bot.zig | 2 +- apps/local-test.zig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/echo-bot.zig b/apps/echo-bot.zig index 199f7cc..5da594d 100644 --- a/apps/echo-bot.zig +++ b/apps/echo-bot.zig @@ -5,7 +5,7 @@ const sodium = @import("sodium"); const bytesToHexBuf = Tox.hex.bytesToHexBuf; const hexToBytes = std.fmt.hexToBytes; -pub const std_options = .{ +pub const std_options: std.Options = .{ // Set the log level to info .log_level = .debug, }; diff --git a/apps/local-test.zig b/apps/local-test.zig index 4c2961a..3ef2722 100644 --- a/apps/local-test.zig +++ b/apps/local-test.zig @@ -4,7 +4,7 @@ const BootNode = @import("BootNode.zig"); const RespNode = @import("RespNode.zig"); const QueryNode = @import("QueryNode.zig"); -pub const std_options = .{ +pub const std_options: std.Options = .{ // Set the log level to info .log_level = .debug, };