From fe8e98e75349526f4a6356ef04c789bd8767c8f9 Mon Sep 17 00:00:00 2001 From: kayomn Date: Sun, 28 May 2023 01:26:41 +0000 Subject: [PATCH] Fix CI test stage --- build.zig | 32 ++++++++++++++++++++++++-------- source/test.zig | 3 +++ 2 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 source/test.zig diff --git a/build.zig b/build.zig index fa792d2..079b6d2 100755 --- a/build.zig +++ b/build.zig @@ -1,9 +1,9 @@ const std = @import("std"); -pub fn build(builder: *std.Build) void { - const coral_module = builder.createModule(.{.source_file = .{.path = "./source/coral/coral.zig"}}); +pub fn build(b: *std.Build) void { + const coral_module = b.createModule(.{.source_file = .{.path = "./source/coral/coral.zig"}}); - const ona_module = builder.createModule(.{ + const ona_module = b.createModule(.{ .source_file = .{.path = "./source/ona/ona.zig"}, .dependencies = &.{ @@ -14,13 +14,16 @@ pub fn build(builder: *std.Build) void { }, }); - // Ona Runner. + const cross_target = b.standardTargetOptions(.{}); + const optimize_mode = std.builtin.Mode.Debug; + + // Ona runner. { - const ona_exe = builder.addExecutable(.{ + const ona_exe = b.addExecutable(.{ .name = "ona-runner", .root_source_file = .{.path = "./source/runner.zig"}, - .target = builder.standardTargetOptions(.{}), - .optimize = .Debug, + .target = cross_target, + .optimize = optimize_mode, }); ona_exe.addModule("coral", coral_module); @@ -29,6 +32,19 @@ pub fn build(builder: *std.Build) void { // ona_exe.addIncludeDir("./ext"); ona_exe.linkSystemLibrary("SDL2"); ona_exe.linkLibC(); - builder.installArtifact(ona_exe); + b.installArtifact(ona_exe); + } + + // Test step. + { + const exe_tests = b.addTest(.{ + .root_source_file = .{.path = "source/test.zig"}, + .target = cross_target, + .optimize = optimize_mode, + }); + + const test_step = b.step("test", "Run unit tests"); + + test_step.dependOn(&exe_tests.step); } } diff --git a/source/test.zig b/source/test.zig new file mode 100644 index 0000000..0d8561f --- /dev/null +++ b/source/test.zig @@ -0,0 +1,3 @@ +const _coral = @import("coral"); + +const _ona = @import("ona");