Skip to content

Commit

Permalink
zig build
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed May 11, 2023
1 parent d3634a3 commit 4c267c7
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 1 deletion.
22 changes: 22 additions & 0 deletions .github/workflows/zigbuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Zig Build

on: [push, pull_request]

jobs:
build:
strategy:
fail-fast: false
matrix:
runs-on: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0
- uses: goto-bus-stop/setup-zig@v2
with:
version: master

- name: Build Summary
run: zig build -DTests -DExamples -fsummary -freference-trace
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/build/
/doc/html/
/test/worksheet.cpp
/test/worksheet.cpp

/zig-cache/
/zig-out/
204 changes: 204 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
const std = @import("std");

// Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external
// runner.
pub fn build(b: *std.Build) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});

// Standard optimization options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});

// Option
const tests = b.option(bool, "Tests", "Build all tests [default: false]") orelse false;
const examples = b.option(bool, "Examples", "Build all examples [default: false]") orelse false;

const lib = b.addStaticLibrary(.{
.name = "hana",
.target = target,
.optimize = optimize,
});

lib.installHeadersDirectory("include/boost", "");

if (tests) {
buildTest(b, .{
.lib = lib,
.path = "test/builtin_array.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/comparable.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/lazy.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/logical.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/functional.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/group.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/index_if.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/minimal_product.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/monoid.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/orderable.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/searchable.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/repeat.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/euclidean_ring.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/ring.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/range/at.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/range/back.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/range/contains.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "test/range/laws.cpp",
});
}

if (examples) {
buildTest(b, .{
.lib = lib,
.path = "example/accessors.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "example/all.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "example/append.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "example/any.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "example/ap.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "example/cartesian_product.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "example/chain.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "example/cycle.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "example/lexicographical_compare.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "example/unpack.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "example/then.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "example/wandbox.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "example/zero.cpp",
});
buildTest(b, .{
.lib = lib,
.path = "example/zip.cpp",
});
}
}

fn buildTest(b: *std.Build, info: BuildInfo) void {
const test_exe = b.addExecutable(.{
.name = info.filename(),
.optimize = info.lib.optimize,
.target = info.lib.target,
});
test_exe.addIncludePath("include");
test_exe.addIncludePath("benchmark");
test_exe.addIncludePath("test/_include");
test_exe.addCSourceFile(info.path, cxxFlags);
test_exe.linkLibCpp();
b.installArtifact(test_exe);

const run_cmd = b.addRunArtifact(test_exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}

const run_step = b.step(
b.fmt("{s}", .{info.filename()}),
b.fmt("Run the {s} test", .{info.filename()}),
);
run_step.dependOn(&run_cmd.step);
}

const cxxFlags: []const []const u8 = &.{
"-Wall",
"-Wextra",
};

const BuildInfo = struct {
lib: *std.Build.CompileStep,
path: []const u8,

fn filename(self: BuildInfo) []const u8 {
var split = std.mem.split(u8, std.fs.path.basename(self.path), ".");
return split.first();
}
};
4 changes: 4 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.{
.name = "hana",
.version = "1.8.0",
}

0 comments on commit 4c267c7

Please sign in to comment.