Skip to content

Commit

Permalink
updated CI
Browse files Browse the repository at this point in the history
  • Loading branch information
freylax committed Nov 17, 2024
1 parent acdc51b commit d3759b7
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 35 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -17,17 +18,22 @@ 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

lint:
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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ dkms.conf
*~

# zig output
zig-cache
zig-out
.zig-cache
zig-out
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
6 changes: 0 additions & 6 deletions README.org

This file was deleted.

2 changes: 1 addition & 1 deletion apps/BootNode.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down
55 changes: 39 additions & 16 deletions apps/local-test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
}

0 comments on commit d3759b7

Please sign in to comment.