From e2da0ca9dbc96cdb94952056879f6d22c431c041 Mon Sep 17 00:00:00 2001 From: Jon Mayo Date: Wed, 2 Jul 2025 11:41:55 -0700 Subject: [PATCH] Update for zig 0.15.0 --- build.zig | 47 +++++++++++++++++++++++++++++++++++------------ build.zig.zon | 15 +++++++++------ 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/build.zig b/build.zig index 445b98d..91a900c 100644 --- a/build.zig +++ b/build.zig @@ -1,31 +1,54 @@ -const Builder = @import("std").build.Builder; +const std = @import("std"); -pub fn build(b: *Builder) void { +pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const exe = b.addExecutable(.{ - .name = "sdl-zig-demo", - .root_source_file = .{ .path = "src/main.zig" }, - .target = target, - .optimize = optimize, + .name = "sdl_zig_demo", + .root_module = b.createModule(.{ + .root_source_file = b.path("src/main.zig"), + .target = target, + .optimize = optimize, + }), }); - if (target.isNativeOs() and target.getOsTag() == .linux) { + + if (target.result.os.tag == .linux) { // The SDL package doesn't work for Linux yet, so we rely on system // packages for now. exe.linkSystemLibrary("SDL2"); exe.linkLibC(); } else { - const sdl_dep = b.dependency("sdl", .{ - .optimize = .ReleaseFast, + const sdl_dep = b.lazyDependency("SDL", .{ + .optimize = .ReleaseSafe, .target = target, }); - exe.linkLibrary(sdl_dep.artifact("SDL2")); + + if (sdl_dep) |sdl| { + exe.linkLibrary(sdl.artifact("SDL2")); + } } b.installArtifact(exe); - const run = b.step("run", "Run the demo"); + const run_step = b.step("run", "Run the app"); + const run_cmd = b.addRunArtifact(exe); - run.dependOn(&run_cmd.step); + run_step.dependOn(&run_cmd.step); + + run_cmd.step.dependOn(b.getInstallStep()); + + if (b.args) |args| { + run_cmd.addArgs(args); + } + + const exe_tests = b.addTest(.{ + .root_module = exe.root_module, + }); + + const run_exe_tests = b.addRunArtifact(exe_tests); + + const test_step = b.step("test", "Run tests"); + test_step.dependOn(&run_exe_tests.step); + } diff --git a/build.zig.zon b/build.zig.zon index fdb7536..089f4d8 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,17 +1,20 @@ .{ - .name = "sdl-zig-demo", + .fingerprint = 0xd536f9a26dace7fd, + .name = .sdl_zig_demo, .version = "0.0.0", + .minimum_zig_version = "0.15.0", .dependencies = .{ - .sdl = .{ - .url = "https://github.com/andrewrk/SDL/archive/3eb87f0f5b8d815d5a608b732e1d77f0876712d9.tar.gz", - .hash = "12206de2e590f0866e7d96a5e60dd352ec28c7006c7a883c9ede84e25b6c61c7c088", + .SDL = .{ + .url = "git+https://github.com/allyourcodebase/SDL?ref=main#005c64130effb6019c42769d3a277180bdbeb0b2", + .hash = "SDL-2.32.6-JToi32yUEgFuZPcB2O6IbBHHsP2Ul8QuRYh488w2VnMy", + .lazy = true, }, }, .paths = .{ - "LICENSE", - "README.md", "build.zig", "build.zig.zon", "src", + "LICENSE", + "README.md", }, }