glfw: add Linux SDK / cross compilation support
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
7d5cd4bbcb
commit
b1581b684c
1 changed files with 33 additions and 5 deletions
|
|
@ -103,6 +103,17 @@ pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void
|
|||
},
|
||||
else => {
|
||||
// Assume Linux-like
|
||||
includeSdkLinuxX8664(b, step);
|
||||
|
||||
// TODO(slimsag): for now, Linux must be built with glibc, not musl:
|
||||
//
|
||||
// ```
|
||||
// ld.lld: error: cannot create a copy relocation for symbol stderr
|
||||
// thread 2004762 panic: attempt to unwrap error: LLDReportedFailure
|
||||
// ```
|
||||
step.target.abi = .gnu;
|
||||
lib.setTarget(step.target);
|
||||
|
||||
var general_sources = std.ArrayList([]const u8).init(&arena.allocator);
|
||||
const flag = switch (options.linux_window_manager) {
|
||||
.X11 => "-D_GLFW_X11",
|
||||
|
|
@ -202,14 +213,18 @@ fn linkGLFW(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void
|
|||
},
|
||||
else => {
|
||||
// Assume Linux-like
|
||||
// TODO(slimsag): create sdk-linux
|
||||
includeSdkLinuxX8664(b, step);
|
||||
switch (options.linux_window_manager) {
|
||||
.X11 => step.linkSystemLibrary("X11"),
|
||||
.X11 => {
|
||||
step.linkSystemLibrary("X11");
|
||||
step.linkSystemLibrary("xcb");
|
||||
step.linkSystemLibrary("Xau");
|
||||
step.linkSystemLibrary("Xdmcp");
|
||||
},
|
||||
.Wayland => step.linkSystemLibrary("wayland-client"),
|
||||
}
|
||||
if (options.vulkan) {
|
||||
step.linkSystemLibrary("vulkan");
|
||||
}
|
||||
// Note: no need to link against vulkan, GLFW finds it dynamically at runtime.
|
||||
// https://www.glfw.org/docs/3.3/vulkan_guide.html#vulkan_loader
|
||||
if (options.opengl) {
|
||||
step.linkSystemLibrary("GL");
|
||||
}
|
||||
|
|
@ -244,6 +259,19 @@ fn includeSdkMacOS(b: *Builder, step: *std.build.LibExeObjStep) void {
|
|||
b.sysroot = sdk_sysroot; // TODO(slimsag): leaks, b.sysroot doesn't get free'd by builder?
|
||||
}
|
||||
|
||||
fn includeSdkLinuxX8664(b: *Builder, step: *std.build.LibExeObjStep) void {
|
||||
const sdk_root_dir = getSdkRoot(b.allocator, "sdk-linux-x86_64") catch unreachable;
|
||||
defer b.allocator.free(sdk_root_dir);
|
||||
|
||||
var sdk_root_includes = std.fs.path.join(b.allocator, &.{ sdk_root_dir, "root/usr/include" }) catch unreachable;
|
||||
defer b.allocator.free(sdk_root_includes);
|
||||
step.addSystemIncludeDir(sdk_root_includes);
|
||||
|
||||
var sdk_root_libs = std.fs.path.join(b.allocator, &.{ sdk_root_dir, "root/usr/lib/x86_64-linux-gnu" }) catch unreachable;
|
||||
defer b.allocator.free(sdk_root_libs);
|
||||
step.addLibPath(sdk_root_libs);
|
||||
}
|
||||
|
||||
/// Caller owns returned memory.
|
||||
fn getSdkRoot(allocator: *std.mem.Allocator, comptime name: []const u8) ![]const u8 {
|
||||
// Find the directory where the SDK should be located. We'll consider two locations:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue