Skip to content

Commit

Permalink
updated to zig v0.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Jan 26, 2024
1 parent 3a47858 commit 393ebe6
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 20 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/zig.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Zig Build

on: [push, pull_request]
on: [push]

jobs:
build:
Expand All @@ -21,19 +21,17 @@ jobs:
- x86_64-macos
- aarch64-macos
- x86_64-windows
# - x86_64-windows-msvc
- x86_64-windows-msvc
- x86-windows
- aarch64-windows

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

- name: Build Summary ${{ matrix.targets }}
run: zig build -DTests --summary all -freference-trace -Dtarget=${{ matrix.targets }}
79 changes: 64 additions & 15 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ pub fn build(b: *std.Build) void {
.target = target,
.optimize = optimize,
});
lib.addCSourceFiles(src, &.{
"-Wall",
"-Wextra",
lib.addCSourceFiles(.{
.files = src,
.flags = &.{
"-Wall",
"-Wextra",
},
});
lib.addIncludePath(Path.relative("include"));
if (optimize == .Debug or optimize == .ReleaseSafe)
lib.bundle_compiler_rt = true
else
lib.strip = true;
lib.root_module.strip = true;
if (lib.linkage == .static)
lib.pie = true;
if (target.getAbi() != .msvc)
if (lib.rootModuleTarget().abi != .msvc)
lib.linkLibCpp() // static-linking LLVM-libcxx (all platforms)
else
lib.linkLibC();
Expand All @@ -50,79 +53,117 @@ pub fn build(b: *std.Build) void {

if (tests) {
buildTest(b, .{
.optimize = optimize,
.target = target,
.lib = lib,
.path = "test/args-test.cc",
});
buildTest(b, .{
.optimize = optimize,
.target = target,
.lib = lib,
.path = "test/core-test.cc",
.path = "test/base-test.cc",
});
buildTest(b, .{
.optimize = optimize,
.target = target,
.lib = lib,
.path = "test/unicode-test.cc",
});
buildTest(b, .{
.optimize = optimize,
.target = target,
.lib = lib,
.path = "test/assert-test.cc",
});
buildTest(b, .{
.optimize = optimize,
.target = target,
.lib = lib,
.path = "test/std-test.cc",
});
buildTest(b, .{
.optimize = optimize,
.target = target,
.lib = lib,
.path = "test/xchar-test.cc",
});
buildTest(b, .{
.optimize = optimize,
.target = target,
.lib = lib,
.path = "test/ostream-test.cc",
});
buildTest(b, .{
.optimize = optimize,
.target = target,
.lib = lib,
.path = "test/printf-test.cc",
});
buildTest(b, .{
.optimize = optimize,
.target = target,
.lib = lib,
.path = "test/scan-test.cc",
});
buildTest(b, .{
.optimize = optimize,
.target = target,
.lib = lib,
.path = "test/ranges-test.cc",
});
buildTest(b, .{
.optimize = optimize,
.target = target,
.lib = lib,
.path = "test/color-test.cc",
});
buildTest(b, .{
.optimize = optimize,
.target = target,
.lib = lib,
.path = "test/chrono-test.cc",
});
buildTest(b, .{
.optimize = optimize,
.target = target,
.lib = lib,
.path = "test/compile-test.cc",
});
buildTest(b, .{
.optimize = optimize,
.target = target,
.lib = lib,
.path = "test/compile-fp-test.cc",
});
buildTest(b, .{
.optimize = optimize,
.target = target,
.lib = lib,
.path = "test/format-test.cc",
});
buildTest(b, .{
.optimize = optimize,
.target = target,
.lib = lib,
.path = "test/os-test.cc",
});
buildTest(b, .{
.optimize = optimize,
.target = target,
.lib = lib,
.path = "test/noexception-test.cc",
});
buildTest(b, .{
.optimize = optimize,
.target = target,
.lib = lib,
.path = "test/posix-mock-test.cc",
});
// don't work
// buildTest(b, .{
// .optimize = optimize,
// .target = target,
// .lib = lib,
// .path = "test/module-test.cc",
// });
Expand All @@ -132,22 +173,28 @@ pub fn build(b: *std.Build) void {
fn buildTest(b: *std.Build, info: BuildInfo) void {
const test_exe = b.addExecutable(.{
.name = info.filename(),
.optimize = info.lib.optimize,
.target = info.lib.target,
.optimize = info.optimize,
.target = info.target,
});
test_exe.addIncludePath(Path.relative("include"));
test_exe.addIncludePath(Path.relative("test"));
test_exe.addIncludePath(Path.relative("test/gtest"));
test_exe.addCSourceFile(.{ .file = Path.relative(info.path), .flags = &.{} });
test_exe.addCSourceFiles(test_src, &.{
"-Wall",
"-Wextra",
"-Wno-deprecated-declarations",
test_exe.addCSourceFile(.{
.file = Path.relative(info.path),
.flags = &.{},
});
test_exe.addCSourceFiles(.{
.files = test_src,
.flags = &.{
"-Wall",
"-Wextra",
"-Wno-deprecated-declarations",
},
});
test_exe.defineCMacro("_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING", "1");
test_exe.defineCMacro("GTEST_HAS_PTHREAD", "0");
test_exe.linkLibrary(info.lib);
if (test_exe.target.getAbi() != .msvc)
if (test_exe.rootModuleTarget().abi != .msvc)
test_exe.linkLibCpp()
else
test_exe.linkLibC();
Expand Down Expand Up @@ -179,10 +226,12 @@ const test_src: []const []const u8 = &.{

const BuildInfo = struct {
lib: *std.Build.Step.Compile,
optimize: std.builtin.OptimizeMode,
target: std.Build.ResolvedTarget,
path: []const u8,

fn filename(self: BuildInfo) []const u8 {
var split = std.mem.split(u8, std.fs.path.basename(self.path), ".");
var split = std.mem.splitSequence(u8, std.fs.path.basename(self.path), ".");
return split.first();
}
};

0 comments on commit 393ebe6

Please sign in to comment.