emu_ui/build.zig
2026-06-13 15:08:28 +02:00

69 lines
2.3 KiB
Zig

const std = @import("std");
const cimgui = @import("cimgui_zig");
const Renderer = cimgui.Renderer;
const Platform = cimgui.Platform;
fn addIncludePathsToTranslateC(translate_c: *std.Build.Step.TranslateC, lib: *std.Build.Step.Compile) void {
for (lib.root_module.include_dirs.items) |*included| {
switch (included.*) {
.path => translate_c.addIncludePath(included.path),
.config_header_step => translate_c.addConfigHeader(included.config_header_step),
.path_system => translate_c.addSystemIncludePath(included.path_system),
.other_step => addIncludePathsToTranslateC(translate_c, included.other_step),
else => unreachable,
}
}
}
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const translate_c = b.addTranslateC(.{
.root_source_file = b.path("src/c.h"),
.target = target,
.optimize = optimize,
});
translate_c.linkSystemLibrary("gl", .{ .needed = true, .preferred_link_mode = .static });
const cimgui_dep = b.dependency("cimgui_zig", .{
.target = target,
.optimize = optimize,
.platforms = &[_]Platform{.GLFW},
.renderers = &[_]Renderer{.OpenGL3},
// .docking = true, // Default value: false
// .no_renderer = true, // Default value: false. Comment `renderers` field if you use this one
// .no_platform = true, // Default value: false. Comment `platforms` field if you use this one
});
const cimgui_lib = cimgui_dep.artifact("cimgui");
addIncludePathsToTranslateC(translate_c, cimgui_lib);
const c_module = translate_c.createModule();
c_module.linkLibrary(cimgui_lib);
const exe = b.addExecutable(.{
.name = "emu_ui",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "imgui", .module = c_module },
},
}),
});
b.installArtifact(exe);
const run_step = b.step("run", "Run the app");
const run_cmd = b.addRunArtifact(exe);
run_step.dependOn(&run_cmd.step);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
}