Skip to content

Commit a49d52c

Browse files
committed
Initial impl (#10)
1 parent 9151b2b commit a49d52c

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

build.zig

+47-1
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ pub fn build(b: *Build) !void {
239239
b.getInstallStep().dependOn(&ldc.step);
240240
}
241241
buildShaders(b);
242+
const ll = buildImgui(b, .{ .target = target, .optimize = optimize });
243+
b.installArtifact(ll);
242244
}
243245

244246
// a separate step to compile shaders, expects the shader compiler in ../sokol-tools-bin/
@@ -434,7 +436,8 @@ fn ldcBuild(b: *Build, lib_sokol: *CompileStep, options: DCompileStep) !*RunStep
434436
break;
435437
}
436438

437-
// link flags
439+
// linker flags
440+
438441
// GNU LD
439442
if (options.target.result.os.tag == .linux and !options.zig_cc) {
440443
try cmds.append("-L--no-as-needed");
@@ -538,3 +541,46 @@ const DCompileStep = struct {
538541
fn packagePath(b: *Build, package: *Build.Dependency) []const u8 {
539542
return package.path("").getPath(b);
540543
}
544+
545+
fn buildImgui(b: *Build, options: struct { target: Build.ResolvedTarget, optimize: std.builtin.OptimizeMode }) *CompileStep {
546+
const imgui_cpp = b.dependency("imgui", .{});
547+
const imgui_cpp_dir = imgui_cpp.path("").getPath(b);
548+
const cimgui = b.dependency("cimgui", .{});
549+
// const cimgui_dir = cimgui.path("").getPath(b);
550+
551+
const lib = b.addStaticLibrary(.{
552+
.name = "imgui",
553+
.target = options.target,
554+
.optimize = options.optimize,
555+
});
556+
lib.addIncludePath(imgui_cpp.path(""));
557+
lib.addIncludePath(cimgui.path(""));
558+
lib.addCSourceFiles(.{
559+
.files = &.{
560+
b.pathJoin(&.{ imgui_cpp_dir, "imgui.cpp" }),
561+
b.pathJoin(&.{ imgui_cpp_dir, "imgui_draw.cpp" }),
562+
b.pathJoin(&.{ imgui_cpp_dir, "imgui_demo.cpp" }),
563+
b.pathJoin(&.{ imgui_cpp_dir, "imgui_widgets.cpp" }),
564+
b.pathJoin(&.{ imgui_cpp_dir, "imgui_tables.cpp" }),
565+
// b.pathJoin(&.{ cimgui_dir, "cimgui.cpp" }),
566+
},
567+
.flags = &.{
568+
"-Wall",
569+
"-Wformat",
570+
"-Wpedantic",
571+
"-Wextra",
572+
"-fno-exceptions",
573+
"-fno-rtti",
574+
},
575+
});
576+
lib.root_module.sanitize_c = false;
577+
578+
// https://github.com/ziglang/zig/issues/5312
579+
if (lib.rootModuleTarget().abi != .msvc) {
580+
// llvm-libcxx + llvm-libunwind + os-libc
581+
lib.linkLibCpp();
582+
} else {
583+
lib.linkLibC();
584+
}
585+
return lib;
586+
}

build.zig.zon

+8
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,13 @@
1212
// .url = "git+https://github.com/BindBC/bindbc-imgui#63cf88e1ab3981794d2e17d2c4a30d1ac340b148",
1313
// .hash = "1220194ac6476adaed11b30299a8abdd593eb7ae6d368bf6832d7fe6a604f12cae4f",
1414
// },
15+
.cimgui = .{
16+
.url = "git+https://github.com/cimgui/cimgui#831f155f605c0ef3ad2e2bc20dae298cdb6f5779",
17+
.hash = "1220abb48ac358308cc4db0603dc92dcc1452b9a99026c7dbca0766f88424a4725c6",
18+
},
19+
.imgui = .{
20+
.url = "git+https://github.com/ocornut/imgui#6228c2e1ec7ef21ca1809579c055ed34540dedb0",
21+
.hash = "12205a78270c1c77b8996639cb35adb6b63265aa31143f51ee207cb4fe90afc7d55d",
22+
},
1523
},
1624
}

0 commit comments

Comments
 (0)