this repo has no description

build: setup imgui

altagos.dev 5500e1f4 32f1a8e6

verified
+68 -26
+1 -1
.tangled/workflows/build.yml
··· 18 18 mise exec zig -- zig build test --summary all 19 19 - name: Build ReleaseSafe 20 20 command: | 21 - mise exec zig -- zig build -Doptimize=ReleaseSafe 21 + mise exec zig -- zig build -Doptimize=ReleaseSafe -Ddocking
+63 -25
build.zig
··· 1 1 const std = @import("std"); 2 2 const Build = std.Build; 3 + 3 4 const sokol = @import("sokol"); 5 + const cimgui = @import("cimgui"); 4 6 5 7 const Options = struct { 6 - mod: *Build.Module, 8 + mod_ft: *Build.Module, 9 + mod_exe: *Build.Module, 7 10 dep_sokol: *Build.Dependency, 11 + dep_cimgui: *Build.Dependency, 12 + cimgui_clib_name: []const u8, 8 13 }; 9 14 10 15 pub fn build(b: *std.Build) !void { 11 16 const target = b.standardTargetOptions(.{}); 12 17 const optimize = b.standardOptimizeOption(.{}); 18 + 19 + const opt_docking = b.option(bool, "docking", "Build with docking support") orelse false; 20 + 21 + const cimgui_conf = cimgui.getConfig(opt_docking); 13 22 14 23 const dep_sokol = b.dependency("sokol", .{ 15 24 .target = target, 16 25 .optimize = optimize, 26 + .with_sokol_imgui = true, 27 + }); 28 + const dep_cimgui = b.dependency("cimgui", .{ 29 + .target = target, 30 + .optimize = optimize, 17 31 }); 18 32 19 - const mod = b.addModule("ft", .{ 33 + dep_sokol.artifact("sokol_clib").addIncludePath(dep_cimgui.path(cimgui_conf.include_dir)); 34 + 35 + const mod_ft = b.addModule("ft", .{ 20 36 .root_source_file = b.path("src/root.zig"), 21 37 .target = target, 22 38 }); ··· 26 42 .target = target, 27 43 .optimize = optimize, 28 44 .imports = &.{ 29 - .{ .name = "ft", .module = mod }, 30 - .{ .name = "sokol", .module = dep_sokol.module("sokol") }, 45 + .{ .name = "ft", .module = mod_ft }, 46 + .{ 47 + .name = "sokol", 48 + .module = dep_sokol.module("sokol"), 49 + }, 50 + .{ 51 + .name = cimgui_conf.module_name, 52 + .module = dep_cimgui.module(cimgui_conf.module_name), 53 + }, 31 54 // .{ .name = "shader", .module = try createShaderModule(b, dep_sokol) }, 32 55 }, 33 56 }); 34 57 35 - const opts = Options{ .mod = mod_exe, .dep_sokol = dep_sokol }; 58 + const options_mod_exe = b.addOptions(); 59 + options_mod_exe.addOption(bool, "docking", opt_docking); 60 + mod_exe.addOptions("build_options", options_mod_exe); 61 + 62 + const opts = Options{ 63 + .mod_ft = mod_ft, 64 + .mod_exe = mod_exe, 65 + .dep_sokol = dep_sokol, 66 + .dep_cimgui = dep_cimgui, 67 + .cimgui_clib_name = cimgui_conf.clib_name, 68 + }; 36 69 if (target.result.cpu.arch.isWasm()) { 37 70 try buildWeb(b, opts); 38 71 } else { 39 72 try buildNative(b, opts); 40 - 41 - const mod_tests = b.addTest(.{ 42 - .name = "mod tests", 43 - .root_module = mod, 44 - }); 45 - const run_mod_tests = b.addRunArtifact(mod_tests); 46 - 47 - const exe_tests = b.addTest(.{ 48 - .name = "exe tests", 49 - .root_module = mod_exe, 50 - }); 51 - const run_exe_tests = b.addRunArtifact(exe_tests); 52 - 53 - const test_step = b.step("test", "Run tests"); 54 - test_step.dependOn(&run_mod_tests.step); 55 - test_step.dependOn(&run_exe_tests.step); 56 73 } 57 74 } 58 75 59 76 fn buildNative(b: *Build, opts: Options) !void { 60 77 const exe = b.addExecutable(.{ 61 78 .name = "factorio_toolbox", 62 - .root_module = opts.mod, 79 + .root_module = opts.mod_exe, 63 80 }); 64 81 65 82 b.installArtifact(exe); ··· 73 90 if (b.args) |args| { 74 91 run_cmd.addArgs(args); 75 92 } 93 + 94 + const mod_tests = b.addTest(.{ 95 + .name = "mod tests", 96 + .root_module = opts.mod_ft, 97 + }); 98 + const run_mod_tests = b.addRunArtifact(mod_tests); 99 + 100 + const exe_tests = b.addTest(.{ 101 + .name = "exe tests", 102 + .root_module = opts.mod_exe, 103 + }); 104 + const run_exe_tests = b.addRunArtifact(exe_tests); 105 + 106 + const test_step = b.step("test", "Run tests"); 107 + test_step.dependOn(&run_mod_tests.step); 108 + test_step.dependOn(&run_exe_tests.step); 76 109 } 77 110 78 111 fn buildWeb(b: *Build, opts: Options) !void { 79 112 const lib = b.addLibrary(.{ 80 113 .name = "factorio_toolbox", 81 - .root_module = opts.mod, 114 + .root_module = opts.mod_exe, 82 115 }); 83 116 84 117 const emsdk = opts.dep_sokol.builder.dependency("emsdk", .{}); 118 + 119 + const emsdk_incl_path = emsdk.path("upstream/emscripten/cache/sysroot/include"); 120 + opts.dep_cimgui.artifact(opts.cimgui_clib_name).addSystemIncludePath(emsdk_incl_path); 121 + opts.dep_cimgui.artifact(opts.cimgui_clib_name).step.dependOn(&opts.dep_sokol.artifact("sokol_clib").step); 122 + 85 123 const link_step = try sokol.emLinkStep(b, .{ 86 124 .lib_main = lib, 87 - .target = opts.mod.resolved_target.?, 88 - .optimize = opts.mod.optimize.?, 125 + .target = opts.mod_exe.resolved_target.?, 126 + .optimize = opts.mod_exe.optimize.?, 89 127 .emsdk = emsdk, 90 128 .use_webgl2 = true, 91 129 .use_emmalloc = true,
+4
build.zig.zon
··· 8 8 .url = "git+https://github.com/floooh/sokol-zig.git#76d4afd25adfae9666d76a0d324cdb70ad178a88", 9 9 .hash = "sokol-0.1.0-pb1HK3TYLgCx8lOxdLVWIVDcAzacxO8YDfyw2Er-_2nN", 10 10 }, 11 + .cimgui = .{ 12 + .url = "git+https://github.com/floooh/dcimgui.git#d5fb4e3d27b79062dc5981db3631dadc4f204654", 13 + .hash = "cimgui-0.1.0-44Clkd6YlAAYULKHDwsDX9EPmka-VAVEjUl-o6ve307E", 14 + }, 11 15 }, 12 16 .paths = .{ 13 17 "build.zig",