glfw: correct Linux -> MacOS cross compilation (header includes)

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2021-07-10 16:07:34 -07:00
parent 182030df2d
commit d3abf7babb

View file

@ -74,6 +74,7 @@ pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void
lib.addCSourceFiles(sources.items, &.{});
},
.macos => {
includeSdkMacOS(b, lib);
var sources = std.ArrayList([]const u8).init(&arena.allocator);
for ([_][]const u8{
// MacOS-specific sources
@ -176,6 +177,22 @@ fn linkGLFW(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void
// TODO(slimsag): create sdk-windows
},
.macos => {
includeSdkMacOS(b, step);
step.linkFramework("Cocoa");
step.linkFramework("IOKit");
step.linkFramework("CoreFoundation");
if (options.opengl) {
step.linkFramework("OpenGL");
}
},
else => {
// Assume Linux-like
// TODO(slimsag): create sdk-linux
},
}
}
fn includeSdkMacOS(b: *Builder, step: *std.build.LibExeObjStep) void {
const sdk_root_dir = getSdkRoot(b.allocator, "sdk-macos-11.3") catch unreachable;
defer b.allocator.free(sdk_root_dir);
@ -195,21 +212,7 @@ fn linkGLFW(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void
// Presumably has something to do with https://github.com/ziglang/zig/issues/6996 - I think zld doesn't consider addLibPath/addFrameworkDir
// resolution as part of dependant libs: https://github.com/ziglang/zig/blob/2d855745f91852af92ad970feef96e55919993d3/src/link/MachO/Dylib.zig#L477-L483
var sdk_sysroot = std.fs.path.join(b.allocator, &.{ sdk_root_dir, "root/" }) catch unreachable;
//defer b.allocator.free(sdk_sysroot); // TODO(slimsag): memory management here is terrible
b.sysroot = sdk_sysroot;
step.linkFramework("Cocoa");
step.linkFramework("IOKit");
step.linkFramework("CoreFoundation");
if (options.opengl) {
step.linkFramework("OpenGL");
}
},
else => {
// Assume Linux-like
// TODO(slimsag): create sdk-linux
},
}
b.sysroot = sdk_sysroot; // TODO(slimsag): leaks, b.sysroot doesn't get free'd by builder?
}
// Caller owns returned memory.