Skip to content

Commit

Permalink
add a build.zig and build.zig.zon file for use as Zig package
Browse files Browse the repository at this point in the history
  • Loading branch information
floooh committed Dec 7, 2024
1 parent f18438a commit 4a483bf
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ imgui-docking/
dear_bindings/
build/
src*/*.json
.zig-*
zig-*
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Build](https://github.com/floooh/dcimgui/actions/workflows/build.yml/badge.svg)](https://github.com/floooh/dcimgui/actions/workflows/build.yml)

An version-tagged all-in-one [Dear ImGui](https://github.com/ocornut/imgui)
source distribution repository for C and C++ coding with:
source distribution repository for C, C++ and Zig coding with:

- regular and docking flavours of Dear ImGui
- C bindings for both flavours (generated with the
Expand Down Expand Up @@ -29,3 +29,10 @@ To use the C++ API:

- for regular version: link with `imgui` and include `imgui.h`
- for the docking version: link with `imgui-docking` and include `imgui.h`

To use the Zig module:

- add a dependency to `git+https://github.com/floooh/dcimgui.git#[version]` to
your build.zig.zon
- ...and see https://github.com/floooh/sokol-zig-imgui-sample/blob/main/build.zig
for how to integrate the `cimgui` module
48 changes: 48 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const std = @import("std");
const builtin = @import("builtin");

pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const lib_cimgui = b.addStaticLibrary(.{
.name = "cimgui_clib",
.target = target,
.optimize = optimize,
.link_libc = true,
});
lib_cimgui.linkLibCpp();
lib_cimgui.addCSourceFiles(.{
.files = &.{
"src/cimgui.cpp",
"src/imgui_demo.cpp",
"src/imgui_draw.cpp",
"src/imgui_tables.cpp",
"src/imgui_widgets.cpp",
"src/imgui.cpp",
},
});

// make cimgui available as artifact, this allows to inject
// the Emscripten sysroot include path in another build.zig
b.installArtifact(lib_cimgui);

// translate-c the cimgui.h file
// NOTE: running this step with the host target is intended to avoid
// any Emscripten header search path shenanigans
const translateC = b.addTranslateC(.{
.root_source_file = b.path("src/cimgui.h"),
.target = b.host,
.optimize = optimize,
});

// build cimgui as module
const mod_cimgui = b.addModule("cimgui", .{
.root_source_file = translateC.getOutput(),
.target = target,
.optimize = optimize,
.link_libc = true,
.link_libcpp = true,
});
mod_cimgui.linkLibrary(lib_cimgui);
}
10 changes: 10 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.{
.name = "cimgui",
.version = "0.1.0",
.paths = .{
"src",
"src-docking",
"build.zig",
"build.zig.zon",
},
}

0 comments on commit 4a483bf

Please sign in to comment.