Skip to content
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
# Cheers!
# -andrewrk

.zig-cache/
.zig-out/
zig-cache/
zig-out/
/release/
Expand Down
35 changes: 20 additions & 15 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
const std = @import("std");
const builtin = @import("builtin");

const mach_core = @import("mach_core");
const mach = @import("mach");

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

const use_freetype = b.option(bool, "use_freetype", "Use Freetype") orelse false;

const mach_core_dep = b.dependency("mach_core", .{
const mach_dep = b.dependency("mach", .{
.target = target,
.optimize = optimize,
});

const module = b.addModule("zig-imgui", .{
.root_source_file = .{ .path = "src/imgui.zig" },
.root_source_file = b.path("src/imgui.zig"),
.imports = &.{
.{ .name = "mach-core", .module = mach_core_dep.module("mach-core") },
.{ .name = "mach", .module = mach_dep.module("mach") },
},
});

Expand All @@ -38,11 +38,11 @@ pub fn build(b: *std.Build) !void {

try files.appendSlice(&.{
"src/cimgui.cpp",
imgui_dep.path("imgui.cpp").getPath(b),
imgui_dep.path("imgui_widgets.cpp").getPath(b),
imgui_dep.path("imgui_tables.cpp").getPath(b),
imgui_dep.path("imgui_draw.cpp").getPath(b),
imgui_dep.path("imgui_demo.cpp").getPath(b),
imgui_dep.builder.path("imgui.cpp").getPath(b),
imgui_dep.builder.path("imgui_widgets.cpp").getPath(b),
imgui_dep.builder.path("imgui_tables.cpp").getPath(b),
imgui_dep.builder.path("imgui_draw.cpp").getPath(b),
imgui_dep.builder.path("imgui_demo.cpp").getPath(b),
});

if (use_freetype) {
Expand All @@ -56,16 +56,21 @@ pub fn build(b: *std.Build) !void {
}

lib.addIncludePath(imgui_dep.path("."));
lib.addCSourceFiles(.{
.files = files.items,
.flags = flags.items,
});

for (files.items, 0..) |file, i| {
if (i == 0) {
lib.addCSourceFile(.{ .file = b.path(file), .flags = flags.items });
} else {
lib.addCSourceFile(.{ .file = .{ .cwd_relative = file }, .flags = flags.items });
}
}

b.installArtifact(lib);

// Example
const build_options = b.addOptions();

const app = try mach_core.App.init(b, mach_core_dep.builder, .{
const app = try mach.CoreApp.init(b, mach_dep.builder, .{
.name = "mach-imgui-example",
.src = "examples/example_mach.zig",
.target = target,
Expand All @@ -83,7 +88,7 @@ pub fn build(b: *std.Build) !void {
// Generator
const generator_exe = b.addExecutable(.{
.name = "mach-imgui-generator",
.root_source_file = .{ .path = "src/generate.zig" },
.root_source_file = b.path("src/generate.zig"),
.target = target,
.optimize = optimize,
});
Expand Down
13 changes: 7 additions & 6 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
.name = "mach-imgui",
.version = "0.1.0",
.dependencies = .{
.mach_core = .{
.url = "https://pkg.machengine.org/mach-core/370bc1504cebaffcda5ed1ae9915fd2ac6778479.tar.gz",
.hash = "12205da1ecba58ba8c9ca65dbf75e32f42fde0490d34a98596ae72d4d3db81659dc5",
.mach = .{
.url = "https://pkg.machengine.org/mach/b72f0e11b6d292c2b60789359a61f7ee6d7dc371.tar.gz",
.hash = "122015e1dac4afaf275f7f2adde3814e6a27f5799cbef96bb487ee305f7e33f4dca3",
},
.freetype = .{
.url = "https://pkg.machengine.org/freetype/398638fd1cb723e478658ea371fe3be1a4dce0ae.tar.gz",
.hash = "12208c57b72e3fb5c8d5d3e667e2e21ca1d9e2b6fc3f84182b320f63933f591823da",
.mach_freetype = .{
.url = "https://pkg.machengine.org/mach-freetype/86fc8024d4ddd53df75dfa4f3ad4eebe0b1b4284.tar.gz",
.hash = "12206251ed342f400b80abf3c338521f5d8c83eb596899abf77a2afe0cfd46e61ff0",
.lazy = true,
},
.imgui = .{
.url = "https://github.com/ocornut/imgui/archive/refs/tags/v1.90.tar.gz",
Expand Down
5 changes: 3 additions & 2 deletions examples/example_mach.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ const std = @import("std");
const build_options = @import("build-options");
const imgui = @import("imgui");
const imgui_mach = imgui.backends.mach;
const core = @import("mach-core");
const gpu = core.gpu;
const mach = @import("mach");
const core = mach.core;
const gpu = mach.gpu;

pub const App = @This();

Expand Down
2 changes: 1 addition & 1 deletion src/imgui_mach.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");
const imgui = @import("imgui.zig");
const core = @import("mach-core");
const core = @import("mach").core;
const gpu = core.gpu;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be
const gpu = @import("mach").gpu;


var allocator: std.mem.Allocator = undefined;
Expand Down