glfw: build fixes

This commit is contained in:
2026-10-15 01:25:27 +02:00
parent bb72c52c4a
commit 32c511dd08
2 changed files with 17 additions and 16 deletions

View File

@@ -3,16 +3,10 @@ const std = @import("std");
const CFLAGS: []const []const u8 = &.{
"-std=c99",
"-Wall",
"-Wextra",
};
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{
.whitelist = &.{
std.Target.Query.parse(.{ .arch_os_abi = "x86_64-windows" }) catch unreachable,
std.Target.Query.parse(.{ .arch_os_abi = "x86_64-linux" }) catch unreachable,
},
});
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const vm_dep = b.dependency("vecmath", .{ .target = target });
@@ -66,6 +60,8 @@ pub fn build(b: *std.Build) void {
switch (target.result.os.tag) {
.windows => {
mod.addCMacro("UNICODE", "");
mod.addCMacro("_UNICODE", "");
mod.addCMacro("_GLFW_WIN32", "");
mod.addCSourceFiles(.{
.files = &.{
@@ -82,6 +78,7 @@ pub fn build(b: *std.Build) void {
});
},
.linux => {
mod.addCMacro("_DEFAULT_SOURCE", "");
mod.addCMacro("_GLFW_X11", "");
mod.addCMacro("_GLFW_WAYLAND", "");
mod.addCSourceFiles(.{

View File

@@ -96,8 +96,8 @@ pub const Key = enum(c_int) {
BACKSLASH = 92,
RIGHT_BRACKET = 93,
GRAVE_ACCENT = 96,
WORLD_1 = 61,
WORLD_2 = 62,
WORLD_1 = 161,
WORLD_2 = 162,
// Function keys
@@ -182,7 +182,7 @@ pub const Modifiers = packed struct(c_int) {
super: bool = false,
caps_lock: bool = false,
num_lock: bool = false,
_pad6: u28 = 0,
_pad6: u26 = 0,
};
pub const MouseButton = enum(c_int) {
@@ -597,6 +597,10 @@ pub const Monitor = opaque {
};
pub const Window = opaque {
pub inline fn destroy(self: *Window) void {
import.glfwDestroyWindow(self);
}
pub inline fn shouldClose(self: *Window) bool {
return import.glfwWindowShouldClose(self).toBool();
}
@@ -1026,7 +1030,7 @@ pub const ErrorWithDescription = struct {
description: ?[*:0]const u8,
};
pub inline fn getError() ErrorCode {
pub inline fn getError() ErrorWithDescription {
var ret: ErrorWithDescription = undefined;
ret.error_code = import.glfwGetError(&ret.description);
return ret;
@@ -1073,8 +1077,8 @@ pub inline fn windowHintString(hint: WindowHint, value: [*:0]const u8) void {
import.glfwWindowHintString(hint, value);
}
pub inline fn createWindow(width: c_int, height: c_int, title: [*:0]const u8, monitor: ?*Monitor, share: ?*Window) ?*Window {
return import.glfwCreateWindow(width, height, title, monitor, share);
pub inline fn createWindow(size: vm.Vector2Int, title: [*:0]const u8, monitor: ?*Monitor, share: ?*Window) ?*Window {
return import.glfwCreateWindow(size.x, size.y, title, monitor, share);
}
pub inline fn pollEvents() void {
@@ -1094,7 +1098,7 @@ pub inline fn postEmptyEvent() void {
}
pub inline fn rawMouseMotionSupported() bool {
import.glfwRawMouseMotionSupported().toBool();
return import.glfwRawMouseMotionSupported().toBool();
}
pub inline fn getKeyName(key: Key, scancode: c_int) ?[*:0]const u8 {
@@ -1165,7 +1169,7 @@ pub inline fn vulkanSupported() bool {
return import.glfwVulkanSupported().toBool();
}
pub inline fn getRequiredInstanceExtensions() ?[*][*:0]const u8 {
pub inline fn getRequiredInstanceExtensions() ?[][*:0]const u8 {
var count: u32 = undefined;
if (import.glfwGetRequiredInstanceExtensions(&count)) |ptr| {
return ptr[0..count];
@@ -1187,7 +1191,7 @@ pub const CreateWindowSurfaceResult = struct {
surface: vk.SurfaceKHR,
};
pub inline fn createWindowSurface(instance: vk.Instance, window: *Window, allocator: ?*const vk.AllocationCallbacks) vk.Result {
pub inline fn createWindowSurface(instance: vk.Instance, window: *Window, allocator: ?*const vk.AllocationCallbacks) CreateWindowSurfaceResult {
var ret: CreateWindowSurfaceResult = undefined;
ret.result = import.glfwCreateWindowSurface(instance, window, allocator, &ret.surface);
return ret;