Skip to content

Commit

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

on: [push, pull_request]

jobs:
build:
strategy:
fail-fast: false
matrix:
targets:
- x86_64-linux-gnu
- x86_64-linux-musl
- x86-linux-gnu
- x86-linux-musl
- aarch64-linux-gnu
- aarch64-linux-musl
- riscv64-linux-musl
- mipsel-linux-musl
- mips-linux-musl
- powerpc64-linux-musl
- x86_64-macos
- aarch64-macos
- x86_64-windows
- x86-windows
- aarch64-windows

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0
- uses: goto-bus-stop/setup-zig@v2
with:
version: master

- name: Build Summary ${{ matrix.targets }}
run: zig build -DTests -DExamples --summary all -freference-trace -Dtarget=${{ matrix.targets }}
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 83a6a0d

Please sign in to comment.