From e8d3deacdcee657475cafba500607ab5ca05b189 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Fri, 12 Jan 2024 14:18:38 -0700 Subject: [PATCH] update zig: fix never mutated vars, use new build system API --- build.zig | 14 +++++++++----- build.zig.zon | 4 ++-- src/Window.zig | 6 +++--- src/main.zig | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/build.zig b/build.zig index a0fddd8..fc0b04d 100644 --- a/build.zig +++ b/build.zig @@ -6,9 +6,10 @@ pub fn build(b: *Build) !void { const optimize = b.standardOptimizeOption(.{}); const target = b.standardTargetOptions(.{}); - _ = b.addModule("mach-glfw", .{ - .source_file = .{ .path = "src/main.zig" }, + const module = b.addModule("mach-glfw", .{ + .root_source_file = .{ .path = "src/main.zig" }, }); + module.addIncludePath(b.dependency("glfw", .{}).path("include")); const lib = b.addStaticLibrary(.{ .name = "mach-glfw", @@ -34,10 +35,13 @@ pub fn build(b: *Build) !void { test_step.dependOn(&b.addRunArtifact(main_tests).step); } -pub fn link(b: *std.Build, step: *std.build.CompileStep) void { +pub fn link(b: *std.Build, step: *std.Build.Step.Compile) void { + const target_triple: []const u8 = step.rootModuleTarget().zigTriple(b.allocator) catch @panic("OOM"); + const cpu_opts: []const u8 = step.root_module.resolved_target.?.query.serializeCpuAlloc(b.allocator) catch @panic("OOM"); const glfw_dep = b.dependency("glfw", .{ - .target = step.target, - .optimize = step.optimize, + .target = target_triple, + .cpu = cpu_opts, + .optimize = step.root_module.optimize.?, }); @import("glfw").link(glfw_dep.builder, step); step.linkLibrary(glfw_dep.artifact("glfw")); diff --git a/build.zig.zon b/build.zig.zon index 593e5cb..8a9a71b 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -12,8 +12,8 @@ }, .dependencies = .{ .glfw = .{ - .url = "https://pkg.machengine.org/glfw/49d153ebfc4f45eacc757ec2b063decbf5bb1779.tar.gz", - .hash = "122020d1ba277ff9e4b5ffff3e3bf4a3c98eeaec821e2a497d031070b05f7814b91f", + .url = "https://github.com/der-teufel-programming/glfw/archive/523dc59dc16ceabd7665b38aabf969e330decaf6.tar.gz", + .hash = "1220dbfb5484019e82fb064090afbe09c83b2d6ab80aac11ceb43a37af78a792cf52", }, }, } diff --git a/src/Window.zig b/src/Window.zig index f7fccbf..90d6f4f 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -2222,7 +2222,7 @@ test "hint int" { } defer glfw.terminate(); - var focused: i32 = 1; + const focused: i32 = 1; hint(.focused, focused); defaultHints(); @@ -2363,8 +2363,8 @@ test "setIcon" { defer window.destroy(); // Create an all-red icon image. - var width: u32 = 48; - var height: u32 = 48; + const width: u32 = 48; + const height: u32 = 48; const icon = try Image.init(allocator, width, height, width * height * 4); var x: u32 = 0; var y: u32 = 0; diff --git a/src/main.zig b/src/main.zig index 30be587..c4d21d3 100644 --- a/src/main.zig +++ b/src/main.zig @@ -520,7 +520,7 @@ pub fn basicTest() !void { }; defer window.destroy(); - var start = std.time.milliTimestamp(); + const start = std.time.milliTimestamp(); while (std.time.milliTimestamp() < start + 1000 and !window.shouldClose()) { c.glfwPollEvents(); }