Skip to content

Commit

Permalink
Initial impl (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Jan 13, 2024
1 parent 6c899ec commit 09ce73d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
55 changes: 49 additions & 6 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,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/
Expand Down Expand Up @@ -391,11 +393,8 @@ 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
try cmds.append(b.fmt("-I{s}", .{b.pathJoin(&.{
rootPath(),
"src",
})}));
// sokol Include path
try cmds.append(b.fmt("-I{s}", .{b.pathJoin(&.{ rootPath(), "src" })}));

// example D file
for (options.sources) |src| {
Expand Down Expand Up @@ -429,7 +428,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");
Expand Down Expand Up @@ -531,3 +531,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;
}
8 changes: 8 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
}

0 comments on commit 09ce73d

Please sign in to comment.