Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Merge with upstream #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions apps/BootNode.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}
4 changes: 2 additions & 2 deletions apps/Node.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions apps/QueryNode.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}
8 changes: 4 additions & 4 deletions apps/RespNode.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
};
}
4 changes: 2 additions & 2 deletions apps/echo-bot.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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: std.Options = .{
// Set the log level to info
pub const log_level = .debug;
.log_level = .debug,
};

const savedata_fn = "savedata.tox";
Expand Down
4 changes: 2 additions & 2 deletions apps/local-test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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: std.Options = .{
// Set the log level to info
pub const log_level = .debug;
.log_level = .debug,
};

const localhost = "127.0.0.1";
Expand Down
37 changes: 13 additions & 24 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,26 @@ pub fn build(b: *Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const c_toxcore_dep = b.dependency(
"c-toxcore",
.{
.target = target,
.optimize = optimize,
.static = true,
.shared = false,
},
);
const libsodium_dep = b.dependency("libsodium", .{});
const c_toxcore_lib = c_toxcore_dep.artifact("toxcore");
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 = .{ .path = "src/tox.zig" },
.root_source_file = b.path("src/tox.zig"),
.target = target,
.optimize = optimize,
});
tox.addIncludePath(c_toxcore_dep.path("."));
tox.addImport("c-toxcore", dep.c_toxcore.module("c-toxcore"));
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"));
sodium.addIncludePath(dep.sodium.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,
});
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);

Expand All @@ -45,18 +39,13 @@ 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,
});
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);
Expand Down
16 changes: 9 additions & 7 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
.{
.name = "zig-toxcore-c",
.name = "c-toxcore-zig",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the rename?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, the original repository name at nodecum is c-toxcore-zig...
Should I rename the original one? This could mess things up or?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean how would github behave if I rename nodecum/c-toxcore-zig which is the origin of the fork of TokTok/zig-toxcore-c.

.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",
},
.@"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",
},
},
}
4 changes: 1 addition & 3 deletions src/friend.zig
Original file line number Diff line number Diff line change
@@ -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,

Expand Down
11 changes: 4 additions & 7 deletions src/tox.zig
Original file line number Diff line number Diff line change
@@ -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");

Expand Down Expand Up @@ -742,9 +739,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());
Expand Down
Loading
Loading