glfw: build: eliminate duplicative arena allocator
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
f911a0a22f
commit
668499b10a
1 changed files with 10 additions and 13 deletions
|
|
@ -37,13 +37,10 @@ pub const Options = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void {
|
pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void {
|
||||||
var arena = std.heap.ArenaAllocator.init(b.allocator);
|
|
||||||
defer arena.deinit();
|
|
||||||
|
|
||||||
const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target;
|
const target = (std.zig.system.NativeTargetInfo.detect(b.allocator, step.target) catch unreachable).target;
|
||||||
switch (target.os.tag) {
|
switch (target.os.tag) {
|
||||||
.windows => {
|
.windows => {
|
||||||
var sources = std.ArrayList([]const u8).init(&arena.allocator);
|
var sources = std.ArrayList([]const u8).init(b.allocator);
|
||||||
for ([_][]const u8{
|
for ([_][]const u8{
|
||||||
// Windows-specific sources
|
// Windows-specific sources
|
||||||
"upstream/glfw/src/win32_thread.c",
|
"upstream/glfw/src/win32_thread.c",
|
||||||
|
|
@ -64,14 +61,14 @@ pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void
|
||||||
"upstream/glfw/src/context.c",
|
"upstream/glfw/src/context.c",
|
||||||
"upstream/glfw/src/window.c",
|
"upstream/glfw/src/window.c",
|
||||||
}) |path| {
|
}) |path| {
|
||||||
var abs_path = std.fs.path.join(&arena.allocator, &.{ thisDir(), path }) catch unreachable;
|
var abs_path = std.fs.path.join(b.allocator, &.{ thisDir(), path }) catch unreachable;
|
||||||
sources.append(abs_path) catch unreachable;
|
sources.append(abs_path) catch unreachable;
|
||||||
}
|
}
|
||||||
step.addCSourceFiles(sources.items, &.{"-D_GLFW_WIN32"});
|
step.addCSourceFiles(sources.items, &.{"-D_GLFW_WIN32"});
|
||||||
},
|
},
|
||||||
.macos => {
|
.macos => {
|
||||||
includeSdkMacOS(b, step);
|
includeSdkMacOS(b, step);
|
||||||
var sources = std.ArrayList([]const u8).init(&arena.allocator);
|
var sources = std.ArrayList([]const u8).init(b.allocator);
|
||||||
for ([_][]const u8{
|
for ([_][]const u8{
|
||||||
// MacOS-specific sources
|
// MacOS-specific sources
|
||||||
"upstream/glfw/src/cocoa_joystick.m",
|
"upstream/glfw/src/cocoa_joystick.m",
|
||||||
|
|
@ -92,7 +89,7 @@ pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void
|
||||||
"upstream/glfw/src/context.c",
|
"upstream/glfw/src/context.c",
|
||||||
"upstream/glfw/src/window.c",
|
"upstream/glfw/src/window.c",
|
||||||
}) |path| {
|
}) |path| {
|
||||||
var abs_path = std.fs.path.join(&arena.allocator, &.{ thisDir(), path }) catch unreachable;
|
var abs_path = std.fs.path.join(b.allocator, &.{ thisDir(), path }) catch unreachable;
|
||||||
sources.append(abs_path) catch unreachable;
|
sources.append(abs_path) catch unreachable;
|
||||||
}
|
}
|
||||||
step.addCSourceFiles(sources.items, &.{"-D_GLFW_COCOA"});
|
step.addCSourceFiles(sources.items, &.{"-D_GLFW_COCOA"});
|
||||||
|
|
@ -110,7 +107,7 @@ pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void
|
||||||
step.target.abi = .gnu;
|
step.target.abi = .gnu;
|
||||||
step.setTarget(step.target);
|
step.setTarget(step.target);
|
||||||
|
|
||||||
var general_sources = std.ArrayList([]const u8).init(&arena.allocator);
|
var general_sources = std.ArrayList([]const u8).init(b.allocator);
|
||||||
const flag = switch (options.linux_window_manager) {
|
const flag = switch (options.linux_window_manager) {
|
||||||
.X11 => "-D_GLFW_X11",
|
.X11 => "-D_GLFW_X11",
|
||||||
.Wayland => "_D_GLFW_WAYLAND",
|
.Wayland => "_D_GLFW_WAYLAND",
|
||||||
|
|
@ -131,14 +128,14 @@ pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void
|
||||||
"upstream/glfw/src/context.c",
|
"upstream/glfw/src/context.c",
|
||||||
"upstream/glfw/src/window.c",
|
"upstream/glfw/src/window.c",
|
||||||
}) |path| {
|
}) |path| {
|
||||||
var abs_path = std.fs.path.join(&arena.allocator, &.{ thisDir(), path }) catch unreachable;
|
var abs_path = std.fs.path.join(b.allocator, &.{ thisDir(), path }) catch unreachable;
|
||||||
general_sources.append(abs_path) catch unreachable;
|
general_sources.append(abs_path) catch unreachable;
|
||||||
}
|
}
|
||||||
step.addCSourceFiles(general_sources.items, &.{flag});
|
step.addCSourceFiles(general_sources.items, &.{flag});
|
||||||
|
|
||||||
switch (options.linux_window_manager) {
|
switch (options.linux_window_manager) {
|
||||||
.X11 => {
|
.X11 => {
|
||||||
var x11_sources = std.ArrayList([]const u8).init(&arena.allocator);
|
var x11_sources = std.ArrayList([]const u8).init(b.allocator);
|
||||||
for ([_][]const u8{
|
for ([_][]const u8{
|
||||||
"upstream/glfw/src/x11_init.c",
|
"upstream/glfw/src/x11_init.c",
|
||||||
"upstream/glfw/src/x11_window.c",
|
"upstream/glfw/src/x11_window.c",
|
||||||
|
|
@ -146,19 +143,19 @@ pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void
|
||||||
"upstream/glfw/src/xkb_unicode.c",
|
"upstream/glfw/src/xkb_unicode.c",
|
||||||
"upstream/glfw/src/glx_context.c",
|
"upstream/glfw/src/glx_context.c",
|
||||||
}) |path| {
|
}) |path| {
|
||||||
var abs_path = std.fs.path.join(&arena.allocator, &.{ thisDir(), path }) catch unreachable;
|
var abs_path = std.fs.path.join(b.allocator, &.{ thisDir(), path }) catch unreachable;
|
||||||
x11_sources.append(abs_path) catch unreachable;
|
x11_sources.append(abs_path) catch unreachable;
|
||||||
}
|
}
|
||||||
step.addCSourceFiles(x11_sources.items, &.{flag});
|
step.addCSourceFiles(x11_sources.items, &.{flag});
|
||||||
},
|
},
|
||||||
.Wayland => {
|
.Wayland => {
|
||||||
var wayland_sources = std.ArrayList([]const u8).init(&arena.allocator);
|
var wayland_sources = std.ArrayList([]const u8).init(b.allocator);
|
||||||
for ([_][]const u8{
|
for ([_][]const u8{
|
||||||
"upstream/glfw/src/wl_monitor.c",
|
"upstream/glfw/src/wl_monitor.c",
|
||||||
"upstream/glfw/src/wl_window.c",
|
"upstream/glfw/src/wl_window.c",
|
||||||
"upstream/glfw/src/wl_init.c",
|
"upstream/glfw/src/wl_init.c",
|
||||||
}) |path| {
|
}) |path| {
|
||||||
var abs_path = std.fs.path.join(&arena.allocator, &.{ thisDir(), path }) catch unreachable;
|
var abs_path = std.fs.path.join(b.allocator, &.{ thisDir(), path }) catch unreachable;
|
||||||
wayland_sources.append(abs_path) catch unreachable;
|
wayland_sources.append(abs_path) catch unreachable;
|
||||||
}
|
}
|
||||||
step.addCSourceFiles(wayland_sources.items, &.{flag});
|
step.addCSourceFiles(wayland_sources.items, &.{flag});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue