From 44c6cd2d37504a54c37ca9890889d8c34ba3f332 Mon Sep 17 00:00:00 2001 From: InventorXtreme <43659737+InventorXtreme@users.noreply.github.com> Date: Thu, 11 Jul 2024 03:59:26 -0400 Subject: [PATCH] [build.zig] GLFW Platform Detection Support (#4150) * Zig Both Linux Desktop Platform Support * Formating and Default Fix Made formating fit within raylib standards and changed the default option to support both X11 and wayland on Linux. * caught one hiding tab --- src/build.zig | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/build.zig b/src/build.zig index 3b462de617fe..2da5cbd04d37 100644 --- a/src/build.zig +++ b/src/build.zig @@ -117,31 +117,29 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std. raylib.addLibraryPath(.{ .cwd_relative = "/usr/lib" }); raylib.addIncludePath(.{ .cwd_relative = "/usr/include" }); + if (options.linux_display_backend == .X11 or options.linux_display_backend == .Both) { - switch (options.linux_display_backend) { - .X11 => { raylib.defineCMacro("_GLFW_X11", null); raylib.linkSystemLibrary("X11"); - }, - .Wayland => { - raylib.defineCMacro("_GLFW_WAYLAND", null); - raylib.linkSystemLibrary("wayland-client"); - raylib.linkSystemLibrary("wayland-cursor"); - raylib.linkSystemLibrary("wayland-egl"); - raylib.linkSystemLibrary("xkbcommon"); - raylib.addIncludePath(b.path("src")); - waylandGenerate(b, raylib, "wayland.xml", "wayland-client-protocol"); - waylandGenerate(b, raylib, "xdg-shell.xml", "xdg-shell-client-protocol"); - waylandGenerate(b, raylib, "xdg-decoration-unstable-v1.xml", "xdg-decoration-unstable-v1-client-protocol"); - waylandGenerate(b, raylib, "viewporter.xml", "viewporter-client-protocol"); - waylandGenerate(b, raylib, "relative-pointer-unstable-v1.xml", "relative-pointer-unstable-v1-client-protocol"); - waylandGenerate(b, raylib, "pointer-constraints-unstable-v1.xml", "pointer-constraints-unstable-v1-client-protocol"); - waylandGenerate(b, raylib, "fractional-scale-v1.xml", "fractional-scale-v1-client-protocol"); - waylandGenerate(b, raylib, "xdg-activation-v1.xml", "xdg-activation-v1-client-protocol"); - waylandGenerate(b, raylib, "idle-inhibit-unstable-v1.xml", "idle-inhibit-unstable-v1-client-protocol"); - }, } + if (options.linux_display_backend == .Wayland or options.linux_display_backend == .Both) { + raylib.defineCMacro("_GLFW_WAYLAND", null); + raylib.linkSystemLibrary("wayland-client"); + raylib.linkSystemLibrary("wayland-cursor"); + raylib.linkSystemLibrary("wayland-egl"); + raylib.linkSystemLibrary("xkbcommon"); + raylib.addIncludePath(b.path("src")); + waylandGenerate(b, raylib, "wayland.xml", "wayland-client-protocol"); + waylandGenerate(b, raylib, "xdg-shell.xml", "xdg-shell-client-protocol"); + waylandGenerate(b, raylib, "xdg-decoration-unstable-v1.xml", "xdg-decoration-unstable-v1-client-protocol"); + waylandGenerate(b, raylib, "viewporter.xml", "viewporter-client-protocol"); + waylandGenerate(b, raylib, "relative-pointer-unstable-v1.xml", "relative-pointer-unstable-v1-client-protocol"); + waylandGenerate(b, raylib, "pointer-constraints-unstable-v1.xml", "pointer-constraints-unstable-v1-client-protocol"); + waylandGenerate(b, raylib, "fractional-scale-v1.xml", "fractional-scale-v1-client-protocol"); + waylandGenerate(b, raylib, "xdg-activation-v1.xml", "xdg-activation-v1-client-protocol"); + waylandGenerate(b, raylib, "idle-inhibit-unstable-v1.xml", "idle-inhibit-unstable-v1-client-protocol"); + } raylib.defineCMacro("PLATFORM_DESKTOP", null); } else { if (options.opengl_version == .auto) { @@ -253,7 +251,7 @@ pub const Options = struct { raygui: bool = false, platform_drm: bool = false, shared: bool = false, - linux_display_backend: LinuxDisplayBackend = .X11, + linux_display_backend: LinuxDisplayBackend = .Both, opengl_version: OpenglVersion = .auto, raygui_dependency_name: []const u8 = "raygui", @@ -284,6 +282,7 @@ pub const OpenglVersion = enum { pub const LinuxDisplayBackend = enum { X11, Wayland, + Both, }; pub fn build(b: *std.Build) !void {