diff --git a/build.zig b/build.zig index 7a40ea6..0f1a64c 100644 --- a/build.zig +++ b/build.zig @@ -241,6 +241,8 @@ pub fn build(b: *Build) !void { b.getInstallStep().dependOn(&ldc.step); } buildShaders(b); + const ll = buildImgui(b, .{ .target = target, .optimize = optimize }); + b.installArtifact(ll); } // a separate step to compile shaders, expects the shader compiler in ../sokol-tools-bin/ @@ -394,7 +396,7 @@ fn DCompileStep(b: *Build, lib_sokol: *CompileStep, options: LDCOptions) !*RunSt // automatically finds needed library files and builds try cmds.append("-i"); - // sokol D files and include path + // sokol Include path try cmds.append(b.fmt("-I{s}", .{b.pathJoin(&.{ rootPath(), "src" })})); // example D file @@ -429,7 +431,8 @@ fn DCompileStep(b: *Build, lib_sokol: *CompileStep, options: LDCOptions) !*RunSt break; } - // link flags + // linker flags + // GNU LD if (options.target.result.os.tag == .linux and !options.zig_cc) { try cmds.append("-L--no-as-needed"); @@ -536,3 +539,46 @@ const LDCOptions = struct { return null; } }; + +fn buildImgui(b: *Build, options: struct { target: Build.ResolvedTarget, optimize: std.builtin.OptimizeMode }) *CompileStep { + const imgui_cpp = b.dependency("imgui", .{}); + const imgui_cpp_dir = imgui_cpp.path("").getPath(b); + const cimgui = b.dependency("cimgui", .{}); + // const cimgui_dir = cimgui.path("").getPath(b); + + const lib = b.addStaticLibrary(.{ + .name = "imgui", + .target = options.target, + .optimize = options.optimize, + }); + lib.addIncludePath(imgui_cpp.path("")); + lib.addIncludePath(cimgui.path("")); + lib.addCSourceFiles(.{ + .files = &.{ + b.pathJoin(&.{ imgui_cpp_dir, "imgui.cpp" }), + b.pathJoin(&.{ imgui_cpp_dir, "imgui_draw.cpp" }), + b.pathJoin(&.{ imgui_cpp_dir, "imgui_demo.cpp" }), + b.pathJoin(&.{ imgui_cpp_dir, "imgui_widgets.cpp" }), + b.pathJoin(&.{ imgui_cpp_dir, "imgui_tables.cpp" }), + // b.pathJoin(&.{ cimgui_dir, "cimgui.cpp" }), + }, + .flags = &.{ + "-Wall", + "-Wformat", + "-Wpedantic", + "-Wextra", + "-fno-exceptions", + "-fno-rtti", + }, + }); + lib.root_module.sanitize_c = false; + + // https://github.com/ziglang/zig/issues/5312 + if (lib.rootModuleTarget().abi != .msvc) { + // llvm-libcxx + llvm-libunwind + os-libc + lib.linkLibCpp(); + } else { + lib.linkLibC(); + } + return lib; +} diff --git a/build.zig.zon b/build.zig.zon index f181c60..85ee106 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -12,5 +12,13 @@ // .url = "git+https://github.com/BindBC/bindbc-imgui#63cf88e1ab3981794d2e17d2c4a30d1ac340b148", // .hash = "1220194ac6476adaed11b30299a8abdd593eb7ae6d368bf6832d7fe6a604f12cae4f", // }, + .cimgui = .{ + .url = "git+https://github.com/cimgui/cimgui#831f155f605c0ef3ad2e2bc20dae298cdb6f5779", + .hash = "1220abb48ac358308cc4db0603dc92dcc1452b9a99026c7dbca0766f88424a4725c6", + }, + .imgui = .{ + .url = "git+https://github.com/ocornut/imgui#6228c2e1ec7ef21ca1809579c055ed34540dedb0", + .hash = "12205a78270c1c77b8996639cb35adb6b63265aa31143f51ee207cb4fe90afc7d55d", + }, }, }