diff --git a/.gitignore b/.gitignore index dca0aad..5709099 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ t2-output .cxx build kk -vc \ No newline at end of file +vc +/zig-cache \ No newline at end of file diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..0225a18 --- /dev/null +++ b/build.zig @@ -0,0 +1,50 @@ +const std = @import("std"); + +const cflags: []const []const u8 = &.{ + "-Wall", + "-Wextra", + "-pedantic", + "-Wno-switch", + "-Wno-unused-function", + "-Wno-implicit-fallthrough", + "-std=c11", +}; + +pub fn build(b: *std.build.Builder) void { + // Standard release options allow the person running `zig build` to select + // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. + const mode = b.standardReleaseOptions(); + const target = b.standardTargetOptions(.{}); + + const lib = b.addStaticLibrary("minifb-zig-port", null); + lib.addCSourceFiles(&.{ + "src/MiniFB_common.c", + "src/MiniFB_internal.c", + "src/MiniFB_timer.c", + "src/windows/WinMiniFB.c", + }, cflags); + lib.addIncludeDir("src"); + lib.addIncludeDir("include"); + lib.linkSystemLibraryName("gdi32"); + lib.linkLibC(); + lib.setBuildMode(mode); + lib.install(); + + addExample(b, "noise", "tests/noise.c", lib, target, mode); + addExample(b, "multiple-windows", "tests/multiple_windows.c", lib, target, mode); + addExample(b, "input-events", "tests/input_events.c", lib, target, mode); + addExample(b, "hidpi", "tests/hidpi.c", lib, target, mode); +} + +fn addExample(b: *std.build.Builder, comptime name: []const u8, file: []const u8, lib: *std.build.LibExeObjStep, target: std.zig.CrossTarget, mode: std.builtin.Mode) void { + const exe = b.addExecutable(name, null); + exe.setBuildMode(mode); + exe.setTarget(target); + exe.linkLibrary(lib); + exe.addIncludeDir("include"); + exe.addCSourceFile(file, cflags); + exe.install(); + + const step_name = "run-" ++ name; + b.step("run-" ++ name, "Run " ++ name ++ " example").dependOn(&exe.run().step); +}