diff --git a/examples/build.zig b/examples/build.zig index c05808bf..5c3a69d2 100644 --- a/examples/build.zig +++ b/examples/build.zig @@ -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"); }, diff --git a/src/build.zig b/src/build.zig index 6bdae0f9..76d4a661 100644 --- a/src/build.zig +++ b/src/build.zig @@ -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"); },