Skip to content

Commit 883800c

Browse files
committed
zig: 2025 day 1
1 parent 84092c1 commit 883800c

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

.github/workflows/ci-2025-zig.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: CI 2025 Zig
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- "2025-zig-*"
8+
paths:
9+
- "2025/zig/**"
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
name: Build and Test
15+
steps:
16+
- uses: actions/checkout@v3
17+
18+
- uses: mlugg/setup-zig@v2
19+
with:
20+
version: 0.15.1
21+
22+
- run: zig build test
23+
working-directory: ./2025/zig

2025/zig/.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.zig-cache/
2+
3+
# Created by https://www.toptal.com/developers/gitignore/api/zig
4+
# Edit at https://www.toptal.com/developers/gitignore?templates=zig
5+
6+
### zig ###
7+
# Zig programming language
8+
9+
zig-cache/
10+
zig-out/
11+
build/
12+
build-*/
13+
docgen_tmp/
14+
15+
# End of https://www.toptal.com/developers/gitignore/api/zig

2025/zig/build.zig

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const std = @import("std");
2+
3+
pub fn build(b: *std.Build) void {
4+
const target = b.standardTargetOptions(.{});
5+
const optimize = b.standardOptimizeOption(.{});
6+
const day_filter = b.option(u8, "day", "Specific day to test (1-25)");
7+
8+
const test_step = b.step("test", "Run all tests");
9+
10+
for (1..26) |day| {
11+
if (day_filter) |d| {
12+
if (d != day) continue;
13+
}
14+
15+
const path = b.fmt("src/day{d:0>2}.zig", .{day});
16+
17+
if (std.fs.cwd().access(path, .{})) {
18+
const day_tests = b.addTest(.{
19+
.root_module = b.createModule(.{
20+
.root_source_file = b.path(path),
21+
.target = target,
22+
.optimize = optimize,
23+
}),
24+
});
25+
test_step.dependOn(&b.addRunArtifact(day_tests).step);
26+
} else |_| {}
27+
}
28+
}

2025/zig/src/day01.zig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const std = @import("std");
2+
3+
fn part1() u64 {
4+
return 42;
5+
}
6+
7+
test "part 1" {
8+
try std.testing.expectEqual(42, part1());
9+
}

0 commit comments

Comments
 (0)