Skip to content

Commit

Permalink
add zig build system
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech committed Dec 18, 2024
1 parent 5209bc7 commit ae3f20c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
28 changes: 21 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,29 @@ on: [push, pull_request]
name: CI

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Zig
uses: korandoru/setup-zig@v1
with:
zig-version: 0.13.0

- name: Lint
run: zig fmt --check *.zig

test:
name: test
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
- uses: actions/checkout@v2

- name: Zig test
uses: goto-bus-stop/setup-zig@v2
with:
version: 0.13.0
- run: zig test snappy.zig
- name: Set up Zig
uses: korandoru/setup-zig@v1
with:
version: 0.13.0

- name: Test
run: zig build test --summary all
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ main*
!main.zig
zig-cache/
.zig-cache/
zig-out/
31 changes: 31 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const Builder = @import("std").Build;

pub fn build(b: *Builder) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const mod = b.addModule("snappy.zig", Builder.Module.CreateOptions{
.root_source_file = b.path("snappy.zig"),
.target = target,
.optimize = optimize,
});
_ = mod;

const lib = b.addStaticLibrary(.{
.name = "snappy",
.root_source_file = .{ .cwd_relative = "snappy.zig" },
.optimize = optimize,
.target = target,
});
b.installArtifact(lib);

const tests = b.addTest(.{
.root_source_file = .{ .cwd_relative = "snappy.zig" },
.optimize = optimize,
.target = target,
});

const run_tests = b.addRunArtifact(tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_tests.step);
}
5 changes: 5 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.{
.name = "zig-snappy",
.version = "0.0.1",
.paths = .{""},
}

0 comments on commit ae3f20c

Please sign in to comment.