diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | build.zig | 39 | ||||
-rw-r--r-- | build.zig.zon | 13 | ||||
-rw-r--r-- | src/Window.zig | 9 | ||||
-rw-r--r-- | src/input.zig | 12 |
5 files changed, 35 insertions, 40 deletions
diff --git a/.gitignore b/.gitignore index e73c965..3389c86 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -zig-cache/ +.zig-cache/ zig-out/ diff --git a/build.zig b/build.zig index c9f6cb9..f0172b8 100644 --- a/build.zig +++ b/build.zig @@ -1,5 +1,5 @@ // Build recipe -// Copyright (C) 2021-2023 Nguyễn Gia Phong +// Copyright (C) 2021-2023, 2025 Nguyễn Gia Phong // // This file is part of gfz. // @@ -17,46 +17,27 @@ // along with gfz. If not, see <https://www.gnu.org/licenses/>. const Build = @import("std").Build; -const Compile = Build.Step.Compile; - -/// Link given library, executable, or object with shared libraries. -pub fn link(compile: *Compile) void { - compile.linkSystemLibrary("glfw"); - compile.linkSystemLibrary("c"); -} pub fn build(b: *Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const lib = b.addStaticLibrary(.{ - .name = "gfz", - .root_source_file = .{ .path = "src/gfz.zig" }, + const module = b.addModule("gfz", .{ + .root_source_file = b.path("src/gfz.zig"), .target = target, .optimize = optimize, }); - link(lib); + module.linkSystemLibrary("glfw", .{}); + module.linkSystemLibrary("c", .{}); - var main_tests = b.addTest(.{ - .root_source_file = .{ .path = "src/gfz.zig" }, - .target = target, - .optimize = optimize, - }); - main_tests.linkLibrary(lib); - b.step("test", "Run library tests").dependOn(&main_tests.step); + const tests = b.addTest(.{ .root_module = module }); + b.step("test", "Run library tests").dependOn(&b.addRunArtifact(tests).step); const example = b.addExecutable(.{ .name = "gfz-context", - .root_source_file = .{ .path = "examples/context.zig" }, + .root_source_file = b.path("examples/context.zig"), .target = target, .optimize = optimize, }); - example.addModule("gfz", b.createModule(.{ - .source_file = .{ .path = "src/gfz.zig" }, - })); - link(example); - const run_example = b.addRunArtifact(example); - run_example.step.dependOn(b.getInstallStep()); - if (b.args) |args| - run_example.addArgs(args); - b.step("example", "Run example").dependOn(&run_example.step); + example.root_module.addImport("gfz", module); + b.step("example", "Run example").dependOn(&b.addRunArtifact(example).step); } diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..a4973ac --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,13 @@ +.{ + .name = .gfz, + .fingerprint = 0x31ae50b4386040dd, + .version = "0.1.0", + .minimum_zig_version = "0.14.0", + .paths = .{ + "COPYING", + "README.md", + "build.zig", + "build.zig.zon", + "src", + }, +} diff --git a/src/Window.zig b/src/Window.zig index d5bb8e7..6771e21 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -44,13 +44,13 @@ fn fnCast(comptime DestType: type, comptime fun: anytype) DestType { c.GLFWcursorposfun => struct { pub fn callback(window: ?*Impl, xpos: f64, ypos: f64) callconv(.C) void { - fun(@fieldParentPtr(Self, "pimpl", &window.?).*, xpos, ypos); + fun(@as(*const Self, @fieldParentPtr("pimpl", &window.?)).*, xpos, ypos); } }, c.GLFWkeyfun => struct { pub fn callback(window: ?*Impl, key: c_int, scancode: c_int, action: c_int, mods: c_int) callconv(.C) void { - fun(@fieldParentPtr(Self, "pimpl", &window.?).*, + fun(@as(*const Self, @fieldParentPtr("pimpl", &window.?)).*, @enumFromInt(key), scancode, @enumFromInt(action), Mods.fromInt(mods)); } @@ -58,7 +58,7 @@ fn fnCast(comptime DestType: type, comptime fun: anytype) DestType { c.GLFWmousebuttonfun => struct { pub fn callback(window: ?*Impl, button: c_int, action: c_int, mods: c_int) callconv(.C) void { - fun(@fieldParentPtr(Self, "pimpl", &window.?).*, + fun(@as(*const Self, @fieldParentPtr("pimpl", &window.?)).*, @enumFromInt(button), @enumFromInt(action), Mods.fromInt(mods)); } @@ -66,7 +66,8 @@ fn fnCast(comptime DestType: type, comptime fun: anytype) DestType { c.GLFWwindowsizefun => struct { pub fn callback(window: ?*Impl, width: c_int, height: c_int) callconv(.C) void { - fun(@fieldParentPtr(Self, "pimpl", &window.?).*, width, height); + fun(@as(*const Self, @fieldParentPtr("pimpl", &window.?)).*, + width, height); } }, else => unreachable, diff --git a/src/input.zig b/src/input.zig index 31fda2e..2b22c9c 100644 --- a/src/input.zig +++ b/src/input.zig @@ -22,7 +22,7 @@ const endian = @import("builtin").target.cpu.arch.endian(); const c = @import("cimport.zig"); const std = @import("std"); -const keys = [_][]const u8{ +const keys = [_][:0]const u8{ // Printable keys "SPACE", "APOSTROPHE", "COMMA", "MINUS", "PERIOD", "SLASH", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "SEMICOLON", "EQUAL", @@ -45,7 +45,7 @@ const keys = [_][]const u8{ }; /// Keyboard key enumeration: https://www.glfw.org/docs/latest/group__keys.html -pub const Key = @Type(.{ .Enum = .{ +pub const Key = @Type(.{ .@"enum" = .{ .tag_type = c_int, .fields = blk: { var fields: [keys.len]EnumField = undefined; @@ -85,8 +85,8 @@ pub const Mods = packed struct { const integer: MaskInt = @intCast(mask); return @bitCast(Mask{ .integer = switch (endian) { - .Big => @bitReverse(integer), - .Little => integer, + .big => @bitReverse(integer), + .little => integer, }, }); } @@ -95,8 +95,8 @@ pub const Mods = packed struct { pub fn toInt(self: Mods) c_int { const integer = @as(Mask, @bitCast(self)).integer; return @intCast(switch (endian) { - .Big => @bitReverse(integer), - .Little => integer, + .big => @bitReverse(integer), + .little => integer, }); } }; |