expose raylib artifact

This commit is contained in:
Locria Cyber 2023-12-25 09:38:45 +00:00
parent 654fd4b99f
commit 183347adaf
No known key found for this signature in database
GPG Key ID: F8C16E5157A63006

View File

@ -16,11 +16,7 @@ pub fn link(
target: std.zig.CrossTarget, target: std.zig.CrossTarget,
optimize: std.builtin.Mode, optimize: std.builtin.Mode,
) void { ) void {
const raylib = b.dependency("raylib", .{ const lib = getRaylib(b, target, optimize);
.target = target,
.optimize = optimize,
});
const art = raylib.artifact("raylib");
const target_os = exe.target.toTarget().os.tag; const target_os = exe.target.toTarget().os.tag;
switch (target_os) { switch (target_os) {
@ -61,20 +57,26 @@ pub fn link(
}, },
} }
exe.linkLibrary(art); exe.linkLibrary(lib);
} }
pub fn getArtifact( var _raylib_lib_cache: ?*std.build.Step.Compile = null;
pub fn getRaylib(
b: *std.Build, b: *std.Build,
target: std.zig.CrossTarget, target: std.zig.CrossTarget,
optimize: std.builtin.Mode, optimize: std.builtin.Mode,
) *std.Build.Step.Compile { ) *std.Build.Step.Compile {
const raylib = b.dependency("raylib", .{ if (_raylib_lib_cache) |lib| return lib else {
.target = target, const raylib = b.dependency("raylib", .{
.optimize = optimize, .target = target,
}); .optimize = optimize,
});
return raylib.artifact("raylib"); const lib = raylib.artifact("raylib");
b.installArtifact(lib);
_raylib_lib_cache = lib;
return lib;
}
} }
// TODO: Make these not comptime. // TODO: Make these not comptime.
@ -187,12 +189,12 @@ pub fn build(b: *std.Build) !void {
const exe_lib = compileForEmscripten(b, ex.name, ex.path, target, optimize); const exe_lib = compileForEmscripten(b, ex.name, ex.path, target, optimize);
exe_lib.addModule("raylib", raylib); exe_lib.addModule("raylib", raylib);
exe_lib.addModule("raylib-math", raylib_math); exe_lib.addModule("raylib-math", raylib_math);
const raylib_artifact = getArtifact(b, target, optimize); const raylib_lib = getRaylib(b, target, optimize);
// Note that raylib itself isn't actually added to the exe_lib // Note that raylib itself isn't actually added to the exe_lib
// output file, so it also needs to be linked with emscripten. // output file, so it also needs to be linked with emscripten.
exe_lib.linkLibrary(raylib_artifact); exe_lib.linkLibrary(raylib_lib);
const link_step = try linkWithEmscripten(b, &[_]*std.Build.Step.Compile{ exe_lib, raylib_artifact }); const link_step = try linkWithEmscripten(b, &[_]*std.Build.Step.Compile{ exe_lib, raylib_lib });
link_step.addArg("--embed-file"); link_step.addArg("--embed-file");
link_step.addArg("resources/"); link_step.addArg("resources/");