Przeglądaj źródła

[build] only include rglfw.c for glfw platform

It looks like raylib doesn't require rglfw.c if you're using the RGFW
backend.  I'm guessing the same is true for SDL but I haven't tested.
Excluding this one file brings the raylib library down from 6.9 MB to
6.3 MB for RGFW.

However, one of the examples requires the symbols from rglfw.c,
to accomodate this I added a function that will check whether raylib has
already included rglfw and if not include it for that one example.
pull/4864/head
Jonathan Marler 3 dni temu
rodzic
commit
508ca5c80f
1 zmienionych plików z 20 dodań i 1 usunięć
  1. +20
    -1
      build.zig

+ 20
- 1
build.zig Wyświetl plik

@ -179,7 +179,11 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
raylib.addIncludePath(b.path("src/platforms"));
switch (target.result.os.tag) {
.windows => {
try c_source_files.append("src/rglfw.c");
switch (options.platform) {
.glfw => try c_source_files.append("src/rglfw.c"),
.rgfw, .sdl, .drm => {},
}
raylib.linkSystemLibrary("winmm");
raylib.linkSystemLibrary("gdi32");
raylib.linkSystemLibrary("opengl32");
@ -480,6 +484,9 @@ fn addExamples(
if (std.mem.eql(u8, name, "rlgl_standalone")) {
exe.addIncludePath(b.path("src"));
exe.addIncludePath(b.path("src/external/glfw/include"));
if (!hasCSource(raylib.root_module, "rglfw.c")) {
exe.addCSourceFile(.{ .file = b.path("src/rglfw.c"), .flags = &.{} });
}
}
if (std.mem.eql(u8, name, "raylib_opengl_interop")) {
exe.addIncludePath(b.path("src/external"));
@ -532,3 +539,15 @@ fn addExamples(
}
return all;
}
fn hasCSource(module: *std.Build.Module, name: []const u8) bool {
for (module.link_objects.items) |o| switch (o) {
.c_source_file => |c| if (switch (c.file) {
.src_path => |s| std.ascii.endsWithIgnoreCase(s.sub_path, name),
.generated, .cwd_relative, .dependency => false,
}) return true,
.c_source_files => |s| for (s.files) |c| if (std.ascii.endsWithIgnoreCase(c, name)) return true,
else => {},
};
return false;
}

Ładowanie…
Anuluj
Zapisz