glfw: reduce compilation units to bring iteration time down to ~90ms
This consistently shaves off about 40ms (~130ms -> ~90ms, 30% reduction) from build times when iterating. On Windows, I suspect the result will be much greater due to slow filesystem perf there and the fact that this reduces the # of files read. This was originally brought to my attention as a possibility by @meshula in hexops/dawn#2, the way this works is by reducing compilation units so that C headers only need to be read/parsed/interpreted once rather than once per individual C source file we are compiling. Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
c552148d0b
commit
3ec74222e6
9 changed files with 57 additions and 103 deletions
113
glfw/build.zig
113
glfw/build.zig
|
|
@ -56,61 +56,13 @@ fn buildLibrary(b: *Builder, step: *std.build.LibExeObjStep, options: Options) *
|
||||||
// TODO(build-system): pass system SDK options through
|
// TODO(build-system): pass system SDK options through
|
||||||
system_sdk.include(b, step, .{});
|
system_sdk.include(b, step, .{});
|
||||||
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;
|
||||||
|
const include_glfw_src = "-I" ++ thisDir() ++ "/upstream/glfw/src";
|
||||||
switch (target.os.tag) {
|
switch (target.os.tag) {
|
||||||
.windows => {
|
.windows => lib.addCSourceFile(thisDir() ++ "/src/sources_windows.c", &.{ "-D_GLFW_WIN32", include_glfw_src }),
|
||||||
var sources = std.ArrayList([]const u8).init(b.allocator);
|
.macos => lib.addCSourceFiles(&.{
|
||||||
for ([_][]const u8{
|
thisDir() ++ "/src/sources_macos.m",
|
||||||
// Windows-specific sources
|
thisDir() ++ "/src/sources_macos.c",
|
||||||
"upstream/glfw/src/win32_thread.c",
|
}, &.{ "-D_GLFW_COCOA", include_glfw_src }),
|
||||||
"upstream/glfw/src/wgl_context.c",
|
|
||||||
"upstream/glfw/src/win32_init.c",
|
|
||||||
"upstream/glfw/src/win32_monitor.c",
|
|
||||||
"upstream/glfw/src/win32_time.c",
|
|
||||||
"upstream/glfw/src/win32_joystick.c",
|
|
||||||
"upstream/glfw/src/win32_window.c",
|
|
||||||
|
|
||||||
// General sources
|
|
||||||
"upstream/glfw/src/monitor.c",
|
|
||||||
"upstream/glfw/src/init.c",
|
|
||||||
"upstream/glfw/src/vulkan.c",
|
|
||||||
"upstream/glfw/src/input.c",
|
|
||||||
"upstream/glfw/src/osmesa_context.c",
|
|
||||||
"upstream/glfw/src/egl_context.c",
|
|
||||||
"upstream/glfw/src/context.c",
|
|
||||||
"upstream/glfw/src/window.c",
|
|
||||||
}) |path| {
|
|
||||||
const abs_path = std.fs.path.join(b.allocator, &.{ thisDir(), path }) catch unreachable;
|
|
||||||
sources.append(abs_path) catch unreachable;
|
|
||||||
}
|
|
||||||
lib.addCSourceFiles(sources.items, &.{"-D_GLFW_WIN32"});
|
|
||||||
},
|
|
||||||
.macos => {
|
|
||||||
var sources = std.ArrayList([]const u8).init(b.allocator);
|
|
||||||
for ([_][]const u8{
|
|
||||||
// MacOS-specific sources
|
|
||||||
"upstream/glfw/src/cocoa_joystick.m",
|
|
||||||
"upstream/glfw/src/cocoa_init.m",
|
|
||||||
"upstream/glfw/src/cocoa_window.m",
|
|
||||||
"upstream/glfw/src/cocoa_time.c",
|
|
||||||
"upstream/glfw/src/cocoa_monitor.m",
|
|
||||||
"upstream/glfw/src/nsgl_context.m",
|
|
||||||
"upstream/glfw/src/posix_thread.c",
|
|
||||||
|
|
||||||
// General sources
|
|
||||||
"upstream/glfw/src/monitor.c",
|
|
||||||
"upstream/glfw/src/init.c",
|
|
||||||
"upstream/glfw/src/vulkan.c",
|
|
||||||
"upstream/glfw/src/input.c",
|
|
||||||
"upstream/glfw/src/osmesa_context.c",
|
|
||||||
"upstream/glfw/src/egl_context.c",
|
|
||||||
"upstream/glfw/src/context.c",
|
|
||||||
"upstream/glfw/src/window.c",
|
|
||||||
}) |path| {
|
|
||||||
const abs_path = std.fs.path.join(b.allocator, &.{ thisDir(), path }) catch unreachable;
|
|
||||||
sources.append(abs_path) catch unreachable;
|
|
||||||
}
|
|
||||||
lib.addCSourceFiles(sources.items, &.{"-D_GLFW_COCOA"});
|
|
||||||
},
|
|
||||||
else => {
|
else => {
|
||||||
// TODO(future): for now, Linux must be built with glibc, not musl:
|
// TODO(future): for now, Linux must be built with glibc, not musl:
|
||||||
//
|
//
|
||||||
|
|
@ -121,60 +73,17 @@ fn buildLibrary(b: *Builder, step: *std.build.LibExeObjStep, options: Options) *
|
||||||
step.target.abi = .gnu;
|
step.target.abi = .gnu;
|
||||||
lib.setTarget(step.target);
|
lib.setTarget(step.target);
|
||||||
|
|
||||||
var general_sources = std.ArrayList([]const u8).init(b.allocator);
|
var 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",
|
||||||
};
|
};
|
||||||
for ([_][]const u8{
|
sources.append(thisDir() ++ "/src/sources_linux.c") catch unreachable;
|
||||||
// General Linux-like sources
|
|
||||||
"upstream/glfw/src/posix_time.c",
|
|
||||||
"upstream/glfw/src/posix_thread.c",
|
|
||||||
"upstream/glfw/src/linux_joystick.c",
|
|
||||||
|
|
||||||
// General sources
|
|
||||||
"upstream/glfw/src/monitor.c",
|
|
||||||
"upstream/glfw/src/init.c",
|
|
||||||
"upstream/glfw/src/vulkan.c",
|
|
||||||
"upstream/glfw/src/input.c",
|
|
||||||
"upstream/glfw/src/osmesa_context.c",
|
|
||||||
"upstream/glfw/src/egl_context.c",
|
|
||||||
"upstream/glfw/src/context.c",
|
|
||||||
"upstream/glfw/src/window.c",
|
|
||||||
}) |path| {
|
|
||||||
const abs_path = std.fs.path.join(b.allocator, &.{ thisDir(), path }) catch unreachable;
|
|
||||||
general_sources.append(abs_path) catch unreachable;
|
|
||||||
}
|
|
||||||
lib.addCSourceFiles(general_sources.items, &.{flag});
|
|
||||||
|
|
||||||
switch (options.linux_window_manager) {
|
switch (options.linux_window_manager) {
|
||||||
.X11 => {
|
.X11 => sources.append(thisDir() ++ "/src/sources_linux_x11.c") catch unreachable,
|
||||||
var x11_sources = std.ArrayList([]const u8).init(b.allocator);
|
.Wayland => sources.append(thisDir() ++ "/src/sources_linux_wayland.c") catch unreachable,
|
||||||
for ([_][]const u8{
|
|
||||||
"upstream/glfw/src/x11_init.c",
|
|
||||||
"upstream/glfw/src/x11_window.c",
|
|
||||||
"upstream/glfw/src/x11_monitor.c",
|
|
||||||
"upstream/glfw/src/xkb_unicode.c",
|
|
||||||
"upstream/glfw/src/glx_context.c",
|
|
||||||
}) |path| {
|
|
||||||
const abs_path = std.fs.path.join(b.allocator, &.{ thisDir(), path }) catch unreachable;
|
|
||||||
x11_sources.append(abs_path) catch unreachable;
|
|
||||||
}
|
|
||||||
lib.addCSourceFiles(x11_sources.items, &.{flag});
|
|
||||||
},
|
|
||||||
.Wayland => {
|
|
||||||
var wayland_sources = std.ArrayList([]const u8).init(b.allocator);
|
|
||||||
for ([_][]const u8{
|
|
||||||
"upstream/glfw/src/wl_monitor.c",
|
|
||||||
"upstream/glfw/src/wl_window.c",
|
|
||||||
"upstream/glfw/src/wl_init.c",
|
|
||||||
}) |path| {
|
|
||||||
const abs_path = std.fs.path.join(b.allocator, &.{ thisDir(), path }) catch unreachable;
|
|
||||||
wayland_sources.append(abs_path) catch unreachable;
|
|
||||||
}
|
|
||||||
lib.addCSourceFiles(wayland_sources.items, &.{flag});
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
lib.addCSourceFiles(sources.items, &.{ flag, "-I" ++ thisDir() ++ "/upstream/glfw/src" });
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
linkGLFWDependencies(b, lib, options);
|
linkGLFWDependencies(b, lib, options);
|
||||||
|
|
|
||||||
|
|
@ -293,7 +293,6 @@ pub const Hints = struct {
|
||||||
else => unreachable,
|
else => unreachable,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
9
glfw/src/sources_all.c
Normal file
9
glfw/src/sources_all.c
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
// General sources
|
||||||
|
#include "monitor.c"
|
||||||
|
#include "init.c"
|
||||||
|
#include "vulkan.c"
|
||||||
|
#include "input.c"
|
||||||
|
#include "osmesa_context.c"
|
||||||
|
#include "egl_context.c"
|
||||||
|
#include "context.c"
|
||||||
|
#include "window.c"
|
||||||
6
glfw/src/sources_linux.c
Normal file
6
glfw/src/sources_linux.c
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#include "sources_all.c"
|
||||||
|
|
||||||
|
// General Linux-like sources
|
||||||
|
#include "posix_time.c"
|
||||||
|
#include "posix_thread.c"
|
||||||
|
#include "linux_joystick.c"
|
||||||
4
glfw/src/sources_linux_wayland.c
Normal file
4
glfw/src/sources_linux_wayland.c
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
// General Linux-like sources
|
||||||
|
#include "wl_monitor.c"
|
||||||
|
#include "wl_window.c"
|
||||||
|
#include "wl_init.c"
|
||||||
6
glfw/src/sources_linux_x11.c
Normal file
6
glfw/src/sources_linux_x11.c
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
// General Linux-like sources
|
||||||
|
#include "x11_init.c"
|
||||||
|
#include "x11_window.c"
|
||||||
|
#include "x11_monitor.c"
|
||||||
|
#include "xkb_unicode.c"
|
||||||
|
#include "glx_context.c"
|
||||||
5
glfw/src/sources_macos.c
Normal file
5
glfw/src/sources_macos.c
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
#include "sources_all.c"
|
||||||
|
|
||||||
|
// MacOS-specific sources
|
||||||
|
#include "cocoa_time.c"
|
||||||
|
#include "posix_thread.c"
|
||||||
6
glfw/src/sources_macos.m
Normal file
6
glfw/src/sources_macos.m
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
// MacOS-specific sources
|
||||||
|
#include "cocoa_joystick.m"
|
||||||
|
#include "cocoa_init.m"
|
||||||
|
#include "cocoa_window.m"
|
||||||
|
#include "cocoa_monitor.m"
|
||||||
|
#include "nsgl_context.m"
|
||||||
10
glfw/src/sources_windows.c
Normal file
10
glfw/src/sources_windows.c
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
#include "sources_all.c"
|
||||||
|
|
||||||
|
// Windows-specific sources
|
||||||
|
#include "win32_thread.c"
|
||||||
|
#include "wgl_context.c"
|
||||||
|
#include "win32_init.c"
|
||||||
|
#include "win32_monitor.c"
|
||||||
|
#include "win32_time.c"
|
||||||
|
#include "win32_joystick.c"
|
||||||
|
#include "win32_window.c"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue