From f3f3c0b2f0eb04ab0cec07d42aa08faf5e6ca2a5 Mon Sep 17 00:00:00 2001 From: Speedy_Lex <78314533+speedy-lex@users.noreply.github.com> Date: Thu, 3 Jul 2025 13:09:34 +0200 Subject: [PATCH] Compile + static link raylib on all platforms --- .gitignore | 1 - .gitmodules | 3 +++ build.zig | 28 ++++++++++++++++++---------- foreign/raylib | 1 + 4 files changed, 22 insertions(+), 11 deletions(-) create mode 160000 foreign/raylib diff --git a/.gitignore b/.gitignore index 8b001d3..3cd73c0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,4 @@ zig-out/ !data/.gitkeep .vscode/ -raylib/ *.log diff --git a/.gitmodules b/.gitmodules index 4b7cc6b..6af15de 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ path = foreign/lua54 url = https://github.com/lua/lua branch = v5.4 +[submodule "foreign/raylib"] + path = foreign/raylib + url = https://github.com/raysan5/raylib diff --git a/build.zig b/build.zig index b84206d..3576248 100644 --- a/build.zig +++ b/build.zig @@ -31,6 +31,22 @@ const LuaVersion = enum { lua54, }; +fn compileRaylib(b: *std.Build, os: std.Target.Os.Tag, c: *std.Build.Step.Compile) void { + // TODO: find out how to send our target to this build cmd + const raylib = b.addSystemCommand(&.{ "zig", "build" }); + raylib.setCwd(b.path("foreign/raylib/")); + raylib.stdio = .inherit; + + c.step.dependOn(&raylib.step); + c.addIncludePath(b.path("foreign/raylib/zig-out/include/")); + c.addLibraryPath(b.path("foreign/raylib/zig-out/lib/")); + c.linkSystemLibrary("raylib"); + if (os == .windows) { + c.linkSystemLibrary("WinMM"); + c.linkSystemLibrary("GDI32"); + } +} + // For the test architecture, we specify the target Lua version we so desire. // This can be checked for with Lua's _VERSION @@ -110,16 +126,8 @@ pub fn build(b: *std.Build) void { }); emulator.linkLibC(); - if (os == .windows) { - // use the mingw-w64 version and copy files to raylib/ - // get raylib from https://github.com/raysan5/raylib/releases - emulator.addIncludePath(b.path("raylib/include")); - emulator.addObjectFile(b.path("raylib/lib/libraylib.a")); - emulator.linkSystemLibrary("GDI32"); - emulator.linkSystemLibrary("WinMM"); - } else { - emulator.linkSystemLibrary("raylib"); - } + compileRaylib(b, os, emulator); + const luaVer = b.option(LuaVersion, "lua", "The version of Lua to use.") orelse LuaVersion.lua54; emulator.addCSourceFiles(.{ .files = &.{ diff --git a/foreign/raylib b/foreign/raylib new file mode 160000 index 0000000..46f01e3 --- /dev/null +++ b/foreign/raylib @@ -0,0 +1 @@ +Subproject commit 46f01e315d07d0b1fedd1a3c388d1acaa9f6ccd6