initial commit - it's working
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
.idea/
|
||||
.zig-cache/
|
||||
zig-out/
|
88
build.zig
Normal file
88
build.zig
Normal file
@@ -0,0 +1,88 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn build(b: *std.Build) !void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const imgui_dep = b.dependency("imgui", .{});
|
||||
const cimgui_dep = b.dependency("cimgui", .{});
|
||||
|
||||
const luajit = try b.findProgram(&.{"luajit"}, &.{});
|
||||
|
||||
const gen = b.addSystemCommand(&.{luajit});
|
||||
gen.setCwd(cimgui_dep.path("generator/"));
|
||||
gen.addFileArg(cimgui_dep.path("generator/generator.lua"));
|
||||
gen.addArgs(&.{
|
||||
"zig cc",
|
||||
"comments internal noimstrv",
|
||||
"glfw",
|
||||
"vulkan",
|
||||
});
|
||||
_ = gen.captureStdOut(); // to quiet output
|
||||
|
||||
{
|
||||
const relpath = try std.fs.path.relative(
|
||||
b.allocator,
|
||||
cimgui_dep.path("generator").getPath(b),
|
||||
imgui_dep.path("").getPath(b),
|
||||
);
|
||||
defer b.allocator.free(relpath);
|
||||
gen.setEnvironmentVariable(
|
||||
"IMGUI_PATH",
|
||||
relpath,
|
||||
);
|
||||
}
|
||||
|
||||
const copy = b.addWriteFiles();
|
||||
copy.step.dependOn(&gen.step);
|
||||
_ = copy.addCopyDirectory(imgui_dep.path(""), "imgui", .{
|
||||
.include_extensions = &.{ ".h", ".cpp" },
|
||||
});
|
||||
_ = copy.addCopyFile(cimgui_dep.path("cimgui.h"), "cimgui.h");
|
||||
_ = copy.addCopyFile(cimgui_dep.path("cimgui.cpp"), "cimgui.cpp");
|
||||
_ = copy.addCopyFile(cimgui_dep.path("generator/output/cimgui_impl.h"), "cimgui_impl.h");
|
||||
|
||||
const cimgui = b.addSharedLibrary(.{
|
||||
.name = "cimgui",
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
cimgui.step.dependOn(©.step);
|
||||
cimgui.linkLibC();
|
||||
cimgui.linkLibCpp();
|
||||
cimgui.addIncludePath(copy.getDirectory());
|
||||
cimgui.addIncludePath(copy.getDirectory().path(b, "imgui"));
|
||||
cimgui.addCSourceFiles(.{
|
||||
.root = copy.getDirectory(),
|
||||
.files = &.{
|
||||
"cimgui.cpp",
|
||||
"imgui/imgui.cpp",
|
||||
"imgui/imgui_tables.cpp",
|
||||
"imgui/imgui_widgets.cpp",
|
||||
"imgui/imgui_demo.cpp",
|
||||
"imgui/imgui_draw.cpp",
|
||||
"imgui/backends/imgui_impl_glfw.cpp",
|
||||
"imgui/backends/imgui_impl_vulkan.cpp",
|
||||
},
|
||||
.flags = &.{
|
||||
"-DIMGUI_IMPL_VULKAN_NO_PROTOTYPES",
|
||||
},
|
||||
});
|
||||
cimgui.installHeader(copy.getDirectory().path(b, "cimgui.h"), "cimgui.h");
|
||||
cimgui.installHeader(copy.getDirectory().path(b, "cimgui_impl.h"), "cimgui_impl.h");
|
||||
|
||||
cimgui.linkSystemLibrary2("glfw3", .{
|
||||
.needed = true,
|
||||
.preferred_link_mode = .static,
|
||||
.use_pkg_config = .force,
|
||||
});
|
||||
|
||||
b.installArtifact(cimgui);
|
||||
|
||||
const zimgui_mod = b.addModule("zimgui", .{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.root_source_file = b.path("src/root.zig"),
|
||||
});
|
||||
zimgui_mod.linkLibrary(cimgui);
|
||||
}
|
19
build.zig.zon
Normal file
19
build.zig.zon
Normal file
@@ -0,0 +1,19 @@
|
||||
.{
|
||||
.name = "zimgui",
|
||||
.version = "0.0.0",
|
||||
.dependencies = .{
|
||||
.cimgui = .{
|
||||
.url = "https://github.com/cimgui/cimgui/archive/refs/tags/1.90.8dock.tar.gz",
|
||||
.hash = "12207ee69164f88f4b41ee5d44edf3835ec4dab0c0cd885799da67d56668f4a3d46b",
|
||||
},
|
||||
.imgui = .{
|
||||
.url = "https://github.com/ocornut/imgui/archive/refs/tags/v1.90.8-docking.tar.gz",
|
||||
.hash = "122065151b97161e25abb71c9df2fd9fba42aaca8c33d689a480b883d82411c8fabe",
|
||||
},
|
||||
},
|
||||
.paths = .{
|
||||
"build.zig",
|
||||
"build.zig.zon",
|
||||
"src",
|
||||
},
|
||||
}
|
28
demo/build.zig
Normal file
28
demo/build.zig
Normal file
@@ -0,0 +1,28 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn build(b: *std.Build) void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
// const cimgui = b.dependency("zimgui", .{}).artifact("cimgui");
|
||||
const zimgui = b.dependency("zimgui", .{});
|
||||
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "demo",
|
||||
.root_source_file = b.path("src/main.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
exe.root_module.addImport("zimgui", zimgui.module("zimgui"));
|
||||
exe.linkSystemLibrary2("glfw3", .{});
|
||||
b.installArtifact(exe);
|
||||
|
||||
const run_cmd = b.addRunArtifact(exe);
|
||||
run_cmd.step.dependOn(b.getInstallStep());
|
||||
if (b.args) |args| {
|
||||
run_cmd.addArgs(args);
|
||||
}
|
||||
|
||||
const run_step = b.step("run", "Run the app");
|
||||
run_step.dependOn(&run_cmd.step);
|
||||
}
|
12
demo/build.zig.zon
Normal file
12
demo/build.zig.zon
Normal file
@@ -0,0 +1,12 @@
|
||||
.{
|
||||
.name = "demo",
|
||||
.version = "0.0.0",
|
||||
.dependencies = .{
|
||||
.zimgui = .{ .path=".." },
|
||||
},
|
||||
.paths = .{
|
||||
"build.zig",
|
||||
"build.zig.zon",
|
||||
"src",
|
||||
},
|
||||
}
|
30
demo/src/main.zig
Normal file
30
demo/src/main.zig
Normal file
@@ -0,0 +1,30 @@
|
||||
const std = @import("std");
|
||||
|
||||
const im = @import("zimgui");
|
||||
|
||||
const c = @cImport({
|
||||
@cDefine("GLFW_INCLUDE_NONE", {});
|
||||
@cInclude("GLFW/glfw3.h");
|
||||
});
|
||||
|
||||
pub fn main() !void {
|
||||
im.init();
|
||||
defer im.deinit();
|
||||
|
||||
_ = c.glfwInit();
|
||||
defer c.glfwTerminate();
|
||||
|
||||
const w = c.glfwCreateWindow(1280, 720, "hello", null, null);
|
||||
defer c.glfwDestroyWindow(w);
|
||||
|
||||
while (c.glfwWindowShouldClose(w) != c.GLFW_TRUE) {
|
||||
c.glfwPollEvents();
|
||||
}
|
||||
}
|
||||
|
||||
test "simple test" {
|
||||
var list = std.ArrayList(i32).init(std.testing.allocator);
|
||||
defer list.deinit(); // try commenting this out and see if zig detects the memory leak!
|
||||
try list.append(42);
|
||||
try std.testing.expectEqual(@as(i32, 42), list.pop());
|
||||
}
|
17
src/root.zig
Normal file
17
src/root.zig
Normal file
@@ -0,0 +1,17 @@
|
||||
const std = @import("std");
|
||||
|
||||
const c = @cImport({
|
||||
@cDefine("CIMGUI_DEFINE_ENUMS_AND_STRUCTS", {});
|
||||
@cInclude("cimgui.h");
|
||||
@cInclude("cimgui_impl.h");
|
||||
});
|
||||
|
||||
pub fn init() void {
|
||||
_ = c.igCreateContext(null);
|
||||
std.debug.print("Context Created!\n", .{});
|
||||
}
|
||||
|
||||
pub fn deinit() void {
|
||||
_ = c.igDestroyContext(null);
|
||||
std.debug.print("Context Destroyed!\n", .{});
|
||||
}
|
15
zig-cimgui-tasks.md
Normal file
15
zig-cimgui-tasks.md
Normal file
@@ -0,0 +1,15 @@
|
||||
- Export `IMGUI_PATH` environment variable to downloaded package.
|
||||
- cd `generator` directory
|
||||
- `luajit generator.lua 'zig cc' 'comments internal noimstrv' glfw vulkan`
|
||||
- compile cimgui/cimgui.cpp, imgui/*.cpp, imgui/backends/*.cpp all together
|
||||
- install cimgui/cimgui.h, imgui/*.h, cimgui/generator/output/cimgui_impl.h
|
||||
|
||||
Zig needs to access cimgui.h and cimgui_impl.h
|
||||
|
||||
Set a custom loader. Instructions in imgui_impl_vulkan.h
|
||||
|
||||
- cdefine `IMGUI_IMPL_VULKAN_NO_PROTOTYPES`
|
||||
- call `ImGui_ImplVulkan_LoadFunctions` before `ImGui_ImplVulkan_Init`
|
||||
|
||||
not quite sure yet what the role of `ImGui_ImplVulkanH_Window.UseDynamicRendering` is
|
||||
|
Reference in New Issue
Block a user