I will murder someone for this

This commit is contained in:
2025-07-01 18:53:24 +02:00
parent eccbf800eb
commit 44bb1ec866
6 changed files with 86 additions and 7 deletions

View File

@@ -24,6 +24,45 @@ fn addEngineSources(c: *std.Build.Step.Compile) void {
});
}
const LuaVersion = enum {
lua52,
lua53,
lua54,
};
// For the test architecture, we specify the target Lua version we so desire.
// This can be checked for with Lua's _VERSION
fn compileTheRightLua(b: *std.Build, c: *std.Build.Step.Compile, version: LuaVersion) !void {
const alloc = b.allocator;
const dirName = @tagName(version);
const rootPath = try std.mem.join(alloc, std.fs.path.sep_str, &.{"foreign", dirName});
c.addIncludePath(b.path(rootPath));
// get all the .c files
var files = std.ArrayList([]const u8).init(alloc);
errdefer files.deinit();
var dir = try std.fs.cwd().openDir(rootPath, std.fs.Dir.OpenDirOptions {.iterate = true});
defer dir.close();
var iter = dir.iterate();
while(try iter.next()) |e| {
if(std.mem.startsWith(u8, e.name, "l") and std.mem.endsWith(u8, e.name, ".c") and !std.mem.eql(u8, e.name, "lua.c")) {
const name = try alloc.dupe(u8, e.name);
try files.append(name);
}
}
c.addCSourceFiles(.{
.root = b.path(rootPath),
.files = files.items,
});
}
pub fn build(b: *std.Build) void {
const os = builtin.target.os.tag;
@@ -72,21 +111,19 @@ pub fn build(b: *std.Build) void {
if (os == .windows) {
// use the msvc win64 dll versions and copy them to raylib/ and lua/
// get raylib from https://github.com/raysan5/raylib/releases
// get lua from https://luabinaries.sourceforge.net/
emulator.addIncludePath(b.path("lua/include"));
emulator.addIncludePath(b.path("raylib/include"));
emulator.addObjectFile(b.path("lua/lua54.lib"));
emulator.addObjectFile(b.path("raylib/lib/raylibdll.lib"));
} else {
emulator.linkSystemLibrary("lua");
emulator.linkSystemLibrary("raylib");
}
const luaVer = b.option(LuaVersion, "lua", "The version of Lua to use.") orelse LuaVersion.lua54;
emulator.addCSourceFiles(.{
.files = &.{
"src/testLuaArch.c",
"src/emulator.c",
},
});
compileTheRightLua(b, emulator, luaVer) catch unreachable;
// forces us to link in everything too
emulator.linkLibrary(engineStatic);