瀏覽代碼

Merge branch 'master' of https://github.com/raysan5/raylib

Ray 1 年之前
父節點
當前提交
fdf9ac66da
共有 1 個文件被更改,包括 54 次插入1 次删除
  1. 54 1
      src/build.zig

+ 54 - 1
src/build.zig

@@ -115,10 +115,34 @@ pub fn addRaylib(b: *std.Build, target: anytype, optimize: std.builtin.OptimizeM
                 raylib.linkSystemLibrary("rt");
                 raylib.linkSystemLibrary("rt");
                 raylib.linkSystemLibrary("dl");
                 raylib.linkSystemLibrary("dl");
                 raylib.linkSystemLibrary("m");
                 raylib.linkSystemLibrary("m");
-                raylib.linkSystemLibrary("X11");
+
                 raylib.addLibraryPath(.{ .path = "/usr/lib" });
                 raylib.addLibraryPath(.{ .path = "/usr/lib" });
                 raylib.addIncludePath(.{ .path = "/usr/include" });
                 raylib.addIncludePath(.{ .path = "/usr/include" });
 
 
+                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(.{ .path = srcdir });
+                        try waylandGenerate(gpa, "wayland.xml", "wayland-client-protocol");
+                        try waylandGenerate(gpa, "xdg-shell.xml", "xdg-shell-client-protocol");
+                        try waylandGenerate(gpa, "xdg-decoration-unstable-v1.xml", "xdg-decoration-unstable-v1-client-protocol");
+                        try waylandGenerate(gpa, "viewporter.xml", "viewporter-client-protocol");
+                        try waylandGenerate(gpa, "relative-pointer-unstable-v1.xml", "relative-pointer-unstable-v1-client-protocol");
+                        try waylandGenerate(gpa, "pointer-constraints-unstable-v1.xml", "pointer-constraints-unstable-v1-client-protocol");
+                        try waylandGenerate(gpa, "fractional-scale-v1.xml", "fractional-scale-v1-client-protocol");
+                        try waylandGenerate(gpa, "xdg-activation-v1.xml", "xdg-activation-v1-client-protocol");
+                        try waylandGenerate(gpa, "idle-inhibit-unstable-v1.xml", "idle-inhibit-unstable-v1-client-protocol");
+                    },
+                }
+
                 raylib.defineCMacro("PLATFORM_DESKTOP", null);
                 raylib.defineCMacro("PLATFORM_DESKTOP", null);
             } else {
             } else {
                 raylib.linkSystemLibrary("GLESv2");
                 raylib.linkSystemLibrary("GLESv2");
@@ -201,6 +225,12 @@ pub const Options = struct {
     raygui: bool = false,
     raygui: bool = false,
     platform_drm: bool = false,
     platform_drm: bool = false,
     shared: bool = false,
     shared: bool = false,
+    linux_display_backend: LinuxDisplayBackend = .X11,
+};
+
+pub const LinuxDisplayBackend = enum {
+    X11,
+    Wayland,
 };
 };
 
 
 pub fn build(b: *std.Build) !void {
 pub fn build(b: *std.Build) !void {
@@ -245,6 +275,8 @@ const srcdir = struct {
     }
     }
 }.getSrcDir();
 }.getSrcDir();
 
 
+const waylandDir = srcdir ++ "/external/glfw/deps/wayland";
+
 fn getOsTagVersioned(target: anytype) std.Target.Os.Tag {
 fn getOsTagVersioned(target: anytype) std.Target.Os.Tag {
     if (comptime builtin.zig_version.minor >= 12) {
     if (comptime builtin.zig_version.minor >= 12) {
         return target.result.os.tag;
         return target.result.os.tag;
@@ -273,6 +305,27 @@ fn addCSourceFilesVersioned(
     }
     }
 }
 }
 
 
+fn waylandGenerate(allocator: std.mem.Allocator, comptime protocol: []const u8, comptime basename: []const u8) !void {
+    _ = try std.process.Child.run(.{
+        .allocator = allocator,
+        .argv = &[_][]const u8{
+            "wayland-scanner",
+            "client-header",
+            waylandDir ++ "/" ++ protocol,
+            srcdir ++ "/" ++ basename ++ ".h",
+        },
+    });
+    _ = try std.process.Child.run(.{
+        .allocator = allocator,
+        .argv = &[_][]const u8{
+            "wayland-scanner",
+            "private-code",
+            waylandDir ++ "/" ++ protocol,
+            srcdir ++ "/" ++ basename ++ "-code.h",
+        },
+    });
+}
+
 fn join2(allocator: std.mem.Allocator, path1: []const u8, path2: []const u8) ![]u8 {
 fn join2(allocator: std.mem.Allocator, path1: []const u8, path2: []const u8) ![]u8 {
     const joinedPath = try std.fs.path.join(allocator, &[_][]const u8{ path1, path2 });
     const joinedPath = try std.fs.path.join(allocator, &[_][]const u8{ path1, path2 });
     return joinedPath;
     return joinedPath;