diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a5d53fe..d1892da 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -4,9 +4,10 @@ name: ci # identify issues while no commits are being pushed. on: pull_request: - branches: [master] + branches: [master,main] schedule: - cron: "52 2 * * 0" + workflow_dispatch: # Cancel old PR builds when pushing new commits. concurrency: @@ -17,11 +18,14 @@ jobs: test: strategy: matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{matrix.os}} + name: Build and Install steps: - uses: actions/checkout@v4 - - uses: goto-bus-stop/setup-zig@v2 + - uses: mlugg/setup-zig@v1 + with: + version: 2024.10.0-mach - run: zig build test - run: zig build apps @@ -29,5 +33,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: goto-bus-stop/setup-zig@v2 + - uses: mlugg/setup-zig@v1 + with: + version: 2024.10.0-mach - run: zig fmt --check src/*.zig diff --git a/.gitignore b/.gitignore index bbfca55..6b73f0d 100644 --- a/.gitignore +++ b/.gitignore @@ -55,5 +55,5 @@ dkms.conf *~ # zig output -zig-cache -zig-out \ No newline at end of file +.zig-cache +zig-out diff --git a/README.md b/README.md index 8dba648..ba6648c 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,17 @@ # zig-toxcore-c +[![ci](https://github.com/nodecum/c-toxcore-zig/actions/workflows/ci.yaml/badge.svg)](https://github.com/nodecum/c-toxcore-zig/actions/workflows/ci.yaml) + Zig wrapper for c-toxcore library. -## build +## Building with zig 0.14.0 (2024.10.0-mach) +to install this zig version using [zvm](https://www.zvm.app) do + +> zvm vmu zig mach + +> zvm i 2024.10.0-mach + +## Build using [c-toxcore v0.2.19](https://github.com/TokTok/c-toxcore/releases/download/v0.2.19) + +> zig build install -``` -zig build run-local-test -``` diff --git a/README.org b/README.org deleted file mode 100644 index aa9d87c..0000000 --- a/README.org +++ /dev/null @@ -1,6 +0,0 @@ -* c-toxcore-zig -Zig wrapper for c-toxcore library. - -** build - -: zig build run-local-test diff --git a/apps/BootNode.zig b/apps/BootNode.zig index 89c6a53..75d85ed 100644 --- a/apps/BootNode.zig +++ b/apps/BootNode.zig @@ -32,7 +32,7 @@ fn run_(i: NodeInfo, keep_running: *bool) !void { var addr_bin: [Tox.address_size]u8 = undefined; try tox.getAddress(&addr_bin); _ = try bytesToHexBuf(&addr_bin, &addr_hex, .upper); - log.debug("{s} startup, my address is: {s}", .{ i.name, addr_hex[0..] }); + log.debug("{s} startup, my address is: {s}\nusing port:{d}", .{ i.name, addr_hex[0..], i.port }); while (@atomicLoad(bool, keep_running, .seq_cst)) { // log.debug("{s} iterate", .{i.name}); diff --git a/apps/local-test.zig b/apps/local-test.zig index 4c2961a..8a61381 100644 --- a/apps/local-test.zig +++ b/apps/local-test.zig @@ -44,27 +44,50 @@ const query = NodeInfo{ pub fn main() !void { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; const alloc = gpa.allocator(); + defer _ = gpa.deinit(); + + // Parse args into string array (error union needs 'try') + const args = try std.process.argsAlloc(alloc); + defer std.process.argsFree(alloc, args); + + // Get and print them! + std.debug.print("There are {d} args:\n", .{args.len}); + for (args) |arg| { + std.debug.print(" {s}\n", .{arg}); + } var keep_running = true; var failure = false; var threads: [3]std.Thread = undefined; - threads[0] = try std.Thread.spawn( - .{}, - BootNode.run, - .{ boot, &keep_running, &failure }, - ); - threads[1] = try std.Thread.spawn( - .{}, - RespNode.run, - .{ alloc, resp, boot, query, &keep_running, &failure }, - ); - threads[2] = try std.Thread.spawn( - .{}, - QueryNode.run, - .{ alloc, query, boot, resp, &keep_running, &failure }, - ); + var n: u32 = 0; + for (args) |arg| { + if (std.mem.eql(u8, arg, "boot")) { + threads[n] = try std.Thread.spawn( + .{}, + BootNode.run, + .{ boot, &keep_running, &failure }, + ); + n += 1; + } - for (threads) |t| { + if (std.mem.eql(u8, arg, "resp")) { + threads[n] = try std.Thread.spawn( + .{}, + RespNode.run, + .{ alloc, resp, boot, query, &keep_running, &failure }, + ); + n += 1; + } + if (std.mem.eql(u8, arg, "query")) { + threads[n] = try std.Thread.spawn( + .{}, + QueryNode.run, + .{ alloc, query, boot, resp, &keep_running, &failure }, + ); + n += 1; + } + } + for (threads[0..n]) |t| { t.join(); } if (failure) { diff --git a/build.zig.zon b/build.zig.zon index cfeb71d..1a5fbce 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -10,8 +10,8 @@ }, .@"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", + .url = "git+https://github.com/nodecum/c-toxcore-build-with-zig#028f9d8ee7e90a31c002baca286f642b44d5f917", + .hash = "122051a2419a34102ac1a95a9007e0f49748115eaf903cf88cfe468a81d5f14618d8", }, }, }