Przeglądaj źródła

Add macos support to zig build system (#2175)

pull/2177/head
Anders Holmberg 3 lat temu
committed by GitHub
rodzic
commit
71f2e2b1e4
Nie znaleziono w bazie danych klucza dla tego podpisu ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 29 dodań i 2 usunięć
  1. +16
    -1
      examples/build.zig
  2. +13
    -1
      src/build.zig

+ 16
- 1
examples/build.zig Wyświetl plik

@ -21,13 +21,20 @@ fn add_module(comptime module: []const u8, b: *std.build.Builder, target: std.zi
// zig's mingw headers do not include pthread.h
if (std.mem.eql(u8, "core_loading_thread", name) and target.getOsTag() == .windows) continue;
const exe = b.addExecutable(name, path);
const exe = b.addExecutable(name, null);
exe.addCSourceFile(path, switch (target.getOsTag()) {
.windows => &[_][]const u8{},
.linux => &[_][]const u8{},
.macos => &[_][]const u8{"-DPLATFORM_DESKTOP"},
else => @panic("Unsupported OS"),
});
exe.setTarget(target);
exe.setBuildMode(mode);
exe.linkLibC();
exe.addObjectFile(switch (target.getOsTag()) {
.windows => "../src/raylib.lib",
.linux => "../src/libraylib.a",
.macos => "../src/libraylib.a",
else => @panic("Unsupported OS"),
});
@ -49,6 +56,14 @@ fn add_module(comptime module: []const u8, b: *std.build.Builder, target: std.zi
exe.linkSystemLibrary("m");
exe.linkSystemLibrary("X11");
},
.macos => {
exe.linkFramework("Foundation");
exe.linkFramework("Cocoa");
exe.linkFramework("OpenGL");
exe.linkFramework("CoreAudio");
exe.linkFramework("CoreVideo");
exe.linkFramework("IOKit");
},
else => {
@panic("Unsupported OS");
},

+ 13
- 1
src/build.zig Wyświetl plik

@ -28,7 +28,6 @@ pub fn build(b: *std.build.Builder) void {
raylib.addCSourceFiles(&.{
"raudio.c",
"rcore.c",
"rglfw.c",
"rmodels.c",
"rshapes.c",
"rtext.c",
@ -38,18 +37,31 @@ pub fn build(b: *std.build.Builder) void {
switch (raylib.target.toTarget().os.tag) {
.windows => {
raylib.addCSourceFiles(&.{"rglfw.c"}, raylib_flags);
raylib.linkSystemLibrary("winmm");
raylib.linkSystemLibrary("gdi32");
raylib.linkSystemLibrary("opengl32");
raylib.addIncludeDir("external/glfw/deps/mingw");
},
.linux => {
raylib.addCSourceFiles(&.{"rglfw.c"}, raylib_flags);
raylib.linkSystemLibrary("GL");
raylib.linkSystemLibrary("rt");
raylib.linkSystemLibrary("dl");
raylib.linkSystemLibrary("m");
raylib.linkSystemLibrary("X11");
},
.macos => {
// On macos rglfw.c include Objective-C files.
const raylib_flags_extra_macos = &[_][]const u8{
"-ObjC",
};
raylib.addCSourceFiles(
&.{"rglfw.c"},
raylib_flags ++ raylib_flags_extra_macos,
);
raylib.linkFramework("Foundation");
},
else => {
@panic("Unsupported OS");
},

Ładowanie…
Anuluj
Zapisz