This commit is contained in:
Dario48 2026-06-23 19:11:42 +02:00
commit 7e9790fc73
4 changed files with 231 additions and 0 deletions

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
result
zig-out/
zig-pkg/
.zig-cache/

87
build.zig Normal file
View file

@ -0,0 +1,87 @@
const std = @import("std");
pub const Backends = enum {
allegro5,
android,
dx10,
dx11,
dx12,
dx9,
glfw,
glut,
null,
opengl2,
opengl3,
sdl2,
sdl3,
sdlgpu3,
sdlrenderer2,
sdlrenderer3,
vulkan,
wgpu,
win32,
};
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const backends = b.option([]Backends, "backends", "which backends to use (compatibility of backends is not assured, the user is held responsible to check if the backends works togeather)") orelse &.{Backends.null};
const internal = b.option(bool, "internal", "also add the internal definitions") orelse false;
const linkage = b.option(std.builtin.LinkMode, "linkage", "how to link the lib");
const dear_bindings = b.dependency("dear_bindings", .{});
const imgui = b.dependency("imgui", .{});
const mod = b.addModule("imgui", .{
.optimize = optimize,
.target = target,
.link_libcpp = true,
});
mod.addCSourceFile(.{ .file = dear_bindings.path("dcimgui.cpp"), .language = .cpp });
mod.addCSourceFile(.{ .file = imgui.path("imgui.cpp"), .language = .cpp });
mod.addIncludePath(imgui.path("."));
mod.addIncludePath(dear_bindings.path("."));
if (internal) {
mod.addCSourceFile(.{ .file = dear_bindings.path("dcimgui_internal.cpp"), .language = .cpp });
mod.addCSourceFile(.{ .file = imgui.path("imgui_internal.cpp"), .language = .cpp });
}
mod.addIncludePath(imgui.path("backends"));
mod.addIncludePath(dear_bindings.path("backends"));
for (backends) |backend|
switch (backend) {
inline else => |e| {
const file = "imgui_impl_" ++ @tagName(e) ++ ".cpp";
mod.addCSourceFile(.{ .file = dear_bindings.path("backends/dc" ++ file), .language = .cpp });
mod.addCSourceFile(.{ .file = imgui.path("backends/" ++ file), .language = .cpp });
},
};
if (linkage) |l| {
const lib = b.addLibrary(.{
.name = "imgui_zig",
.root_module = mod,
.version = .{ .major = 1, .minor = 92, .patch = 8 },
.linkage = l,
});
b.installArtifact(lib);
} else {
const liba = b.addLibrary(.{
.name = "imgui_zig",
.root_module = mod,
.version = .{ .major = 1, .minor = 92, .patch = 8 },
.linkage = .static,
});
b.installArtifact(liba);
const libso = b.addLibrary(.{
.name = "imgui_zig",
.root_module = mod,
.version = .{ .major = 1, .minor = 92, .patch = 8 },
.linkage = .dynamic,
});
b.installArtifact(libso);
}
}

52
build.zig.zon Normal file
View file

@ -0,0 +1,52 @@
.{
// This is the default name used by packages depending on this one. For
// example, when a user runs `zig fetch --save <url>`, this field is used
// as the key in the `dependencies` table. Although the user can choose a
// different name, most users will stick with this provided value.
//
// It is redundant to include "zig" in this name because it is already
// within the Zig package namespace.
.name = .imgui_binds,
// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",
// Together with name, this represents a globally unique package
// identifier. This field is generated by the Zig toolchain when the
// package is first created, and then *never changes*. This allows
// unambiguous detection of one package being an updated version of
// another.
//
// When forking a Zig project, this id should be regenerated (delete the
// field and run `zig build`) if the upstream project is still maintained.
// Otherwise, the fork is *hostile*, attempting to take control over the
// original project's identity. Thus it is recommended to leave the comment
// on the following line intact, so that it shows up in code reviews that
// modify the field.
.fingerprint = 0x744ba2b7d4ec1195, // Changing this has security and trust implications.
// Tracks the earliest Zig version that the package considers to be a
// supported use case.
.minimum_zig_version = "0.16.0",
// This field is optional.
// Each dependency must either provide a `url` and `hash`, or a `path`.
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
// Once all dependencies are fetched, `zig build` no longer requires
// internet connectivity.
.dependencies = .{
.dear_bindings = .{
.url = "https://github.com/dearimgui/dear_bindings/releases/download/DearBindings_v0.21_ImGui_v1.92.8/DearBindings_v0.21_ImGui_v1.92.8.zip",
.hash = "N-V-__8AAFkdBAQBjXc2zsRuRkF3uh4Vk0CjB6BI4hOKZt2X",
},
.imgui = .{
.url = "https://github.com/ocornut/imgui/archive/refs/tags/v1.92.8.tar.gz",
.hash = "N-V-__8AAKBCdwB2ORnA19yAaaCihr6odBLQztrMOoCs8Q7s",
},
},
.paths = .{
"build.zig",
"build.zig.zon",
"src",
// For example...
//"LICENSE",
//"README.md",
},
}

88
flake.nix Normal file
View file

@ -0,0 +1,88 @@
{
description = "A Zig program using dear_imgui_zig";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
zig-flake = {
url = "github:silversquirl/zig-flake";
inputs.nixpkgs.follows = "nixpkgs";
};
# zls no longer needs the compat branch — it uses zig-flake directly
zls = {
url = "github:zigtools/zls/0.16.0";
inputs = {
nixpkgs.follows = "nixpkgs";
zig-flake.follows = "zig-flake";
};
};
};
outputs =
inputs@{
flake-parts,
nixpkgs,
zig-flake,
zls,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
imports = [
flake-parts.flakeModules.easyOverlay
];
perSystem =
{
system,
pkgs,
config,
...
}:
let
zigPkgs = zig-flake.packages.${system};
zlsPkg = zls.packages.${system}.zls;
pkg =
{
buildMode ? "fast",
}:
zigPkgs.default.makePackage {
pname = "imgui_binds";
version = "0.1.0";
src = ./.;
zigReleaseMode = buildMode;
nativeBuildInputs = with pkgs; [
pkg-config
];
};
in
{
overlayAttrs = {
inherit (config.packages) imgui_binds;
};
packages.imgui_binds = pkg { };
packages.debug = pkg {
buildMode = "debug";
};
packages.default = config.packages.imgui_binds;
devShells.default = pkgs.mkShellNoCC {
packages = [
zlsPkg
];
inputsFrom = [ config.packages.default ];
};
};
};
}