From ae3f20cb4bdeb6066f8147215254408d4b4a978c Mon Sep 17 00:00:00 2001 From: harkamal Date: Wed, 18 Dec 2024 17:59:09 +0530 Subject: [PATCH] add zig build system --- .github/workflows/ci.yml | 28 +++++++++++++++++++++------- .gitignore | 1 + build.zig | 31 +++++++++++++++++++++++++++++++ build.zig.zon | 5 +++++ 4 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 build.zig create mode 100644 build.zig.zon diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c84746..f6dfca6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.gitignore b/.gitignore index f86de0e..abcb31e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ main* !main.zig zig-cache/ .zig-cache/ +zig-out/ diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..407f7cc --- /dev/null +++ b/build.zig @@ -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); +} diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..dc51689 --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,5 @@ +.{ + .name = "zig-snappy", + .version = "0.0.1", + .paths = .{""}, +}