Add raygui build to build.zig

This commit is contained in:
haxsam 2026-04-16 16:50:42 +02:00
parent aa3cec841c
commit 0d11c17ba2
No known key found for this signature in database
2 changed files with 43 additions and 13 deletions

View File

@ -7,8 +7,8 @@ const emccOutputFile = "index.html";
pub const emsdk = struct {
const zemscripten = @import("zemscripten");
pub fn shell(raylib: *std.Build.Dependency) std.Build.LazyPath {
return raylib.path("src/shell.html");
pub fn shell(raylib_dep: *std.Build.Dependency) std.Build.LazyPath {
return raylib_dep.path("src/shell.html");
}
pub const FlagsOptions = struct {
@ -48,8 +48,9 @@ pub const emsdk = struct {
emcc_settings.put("MIN_WEBGL_VERSION", "2") catch unreachable;
emcc_settings.put("MAX_WEBGL_VERSION", "2") catch unreachable;
}
if (options.glfw3)
if (options.glfw3) {
emcc_settings.put("USE_GLFW", "3") catch unreachable;
}
const total_memory = std.fmt.allocPrint(allocator, "{d}", .{options.total_memory}) catch unreachable;
@ -481,17 +482,33 @@ fn compileRaylib(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.
return raylib;
}
pub fn addRaygui(b: *std.Build, raylib: *std.Build.Step.Compile, raygui_dep: *std.Build.Dependency, options: Options) void {
const raylib_dep = b.dependencyFromBuildZig(@This(), options);
var gen_step = b.addWriteFiles();
raylib.step.dependOn(&gen_step.step);
fn addRaygui(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, raylib: *std.Build.Step.Compile) void {
if (b.lazyDependency("raygui", .{
.target = target,
.optimize = optimize,
.link_libc = true,
})) |raygui_dep| {
var gen_step = b.addWriteFiles();
raylib.step.dependOn(&gen_step.step);
const raygui_c_path = gen_step.add("raygui.c", "#define RAYGUI_IMPLEMENTATION\n#include \"raygui.h\"\n");
raylib.root_module.addCSourceFile(.{ .file = raygui_c_path });
raylib.root_module.addIncludePath(raygui_dep.path("src"));
raylib.root_module.addIncludePath(raylib_dep.path("src"));
const raygui_c_path = gen_step.add("raygui.c", "#define RAYGUI_IMPLEMENTATION\n#include \"raygui.h\"\n");
raylib.root_module.addCSourceFile(.{ .file = raygui_c_path });
raylib.root_module.addIncludePath(raygui_dep.path("src"));
raylib.root_module.addIncludePath(b.path("src"));
raylib.installHeader(raygui_dep.path("src/raygui.h"), "raygui.h");
raylib.installHeader(raygui_dep.path("src/raygui.h"), "raygui.h");
const c = b.addTranslateC(.{
.root_source_file = raygui_dep.path("src/raygui.h"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
c.addIncludePath(b.path("src"));
const c_mod = c.createModule();
c_mod.linkLibrary(raylib);
b.modules.put(b.graph.arena, "raygui", c_mod) catch @panic("OOM");
}
}
pub const Options = struct {
@ -500,6 +517,7 @@ pub const Options = struct {
rshapes: bool = true,
rtext: bool = true,
rtextures: bool = true,
raygui: bool = false,
platform: PlatformBackend = .glfw,
linkage: std.builtin.LinkMode = .static,
linux_display_backend: LinuxDisplayBackend = .X11,
@ -519,6 +537,7 @@ pub const Options = struct {
.rtext = b.option(bool, "rtext", "Compile with text support") orelse defaults.rtext,
.rtextures = b.option(bool, "rtextures", "Compile with textures support") orelse defaults.rtextures,
.rshapes = b.option(bool, "rshapes", "Compile with shapes support") orelse defaults.rshapes,
.raygui = b.option(bool, "raygui", "Include raygui") orelse defaults.raygui,
.linkage = b.option(std.builtin.LinkMode, "linkage", "Compile as shared or static library") orelse defaults.linkage,
.linux_display_backend = b.option(LinuxDisplayBackend, "linux_display_backend", "Linux display backend to use") orelse defaults.linux_display_backend,
.opengl_version = b.option(OpenglVersion, "opengl_version", "OpenGL version to use") orelse defaults.opengl_version,
@ -593,8 +612,9 @@ fn translateCMod(
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const options: Options = .getOptions(b);
const lib = try compileRaylib(b, target, optimize, Options.getOptions(b));
const lib = try compileRaylib(b, target, optimize, options);
lib.installHeader(b.path("src/raylib.h"), "raylib.h");
lib.installHeader(b.path("src/rcamera.h"), "rcamera.h");
@ -608,6 +628,10 @@ pub fn build(b: *std.Build) !void {
translateCMod("raymath", b, target, optimize, lib);
translateCMod("rlgl", b, target, optimize, lib);
if (options.raygui) {
addRaygui(b, target, optimize, lib);
}
const examples = b.step("examples", "build/install all examples");
examples.dependOn(try addExamples("core", b, target, optimize, lib));
examples.dependOn(try addExamples("audio", b, target, optimize, lib));

View File

@ -11,6 +11,11 @@
.hash = "N-V-__8AALShqgXkvqYU6f__FrA22SMWmi2TXCJjNTO1m8XJ",
.lazy = true,
},
.raygui = .{
.url = "git+https://github.com/raysan5/raygui#3b2855842ab578a034f827c38cf8f62c042fc983",
.hash = "N-V-__8AAHvybwBw1kyBGn0BW_s1RqIpycNjLf_XbE-fpLUF",
.lazy = true,
},
.emsdk = .{
.url = "git+https://github.com/emscripten-core/emsdk#4.0.9",
.hash = "N-V-__8AAJl1DwBezhYo_VE6f53mPVm00R-Fk28NPW7P14EQ",
@ -18,6 +23,7 @@
.zemscripten = .{
.url = "git+https://github.com/zig-gamedev/zemscripten#3fa4b778852226c7346bdcc3c1486e875a9a6d02",
.hash = "zemscripten-0.2.0-dev-sRlDqApRAACspTbAZnuNKWIzfWzSYgYkb2nWAXZ-tqqt",
.lazy = true,
},
},