Skip to content

Commit 5530ecb

Browse files
committed
Merge branch 'main' into feature/add_sdl2_backend
2 parents d5d74ee + 62c8645 commit 5530ecb

13 files changed

+2422
-79
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ pub fn build(b: *std.Build) void {
3535
.with_implot = true,
3636
});
3737
exe.root_module.addImport("zgui", zgui.module("root"));
38-
exe.linkLibrary(zgui.artifact("imgui"));
39-
38+
4039
{ // Needed for glfw/wgpu rendering backend
4140
const zglfw = b.dependency("zglfw", .{});
4241
exe.root_module.addImport("zglfw", zglfw.module("root"));

build.zig

Lines changed: 46 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub const Backend = enum {
1010
glfw,
1111
sdl2_opengl3,
1212
osx_metal,
13-
sdl2,
13+
sdl3_gpu,
1414
};
1515

1616
pub fn build(b: *std.Build) void {
@@ -68,7 +68,7 @@ pub fn build(b: *std.Build) void {
6868

6969
const options_module = options_step.createModule();
7070

71-
_ = b.addModule("root", .{
71+
const imgui = b.addModule("root", .{
7272
.root_source_file = b.path("src/gui.zig"),
7373
.imports = &.{
7474
.{ .name = "zgui_options", .module = options_module },
@@ -88,49 +88,24 @@ pub fn build(b: *std.Build) void {
8888
"-Wno-availability",
8989
};
9090

91-
const imgui = if (options.shared) blk: {
92-
const lib = b.addSharedLibrary(.{
93-
.name = "imgui",
94-
.target = target,
95-
.optimize = optimize,
96-
});
97-
98-
if (target.result.os.tag == .windows) {
99-
lib.root_module.addCMacro("IMGUI_API", "__declspec(dllexport)");
100-
lib.root_module.addCMacro("IMPLOT_API", "__declspec(dllexport)");
101-
lib.root_module.addCMacro("ZGUI_API", "__declspec(dllexport)");
102-
}
103-
104-
if (target.result.os.tag == .macos) {
105-
lib.linker_allow_shlib_undefined = true;
106-
}
107-
108-
break :blk lib;
109-
} else b.addStaticLibrary(.{
110-
.name = "imgui",
111-
.target = target,
112-
.optimize = optimize,
113-
});
114-
115-
b.installArtifact(imgui);
116-
117-
const emscripten = target.result.os.tag == .emscripten;
118-
if (emscripten) {
119-
imgui.root_module.addCMacro("__EMSCRIPTEN__", "");
120-
// TODO: read from enviroment or `emcc --version`
121-
imgui.root_module.addCMacro("__EMSCRIPTEN_major__", "3");
122-
imgui.root_module.addCMacro("__EMSCRIPTEN_minor__", "1");
123-
imgui.root_module.stack_protector = false;
124-
//imgui.root_module.disable_stack_probing = true;
125-
}
91+
//Shared Library details
92+
//if (target.result.os.tag == .macos) {
93+
// lib.linker_allow_shlib_undefined = true;
94+
//}
95+
//if (target.result.os.tag == .windows) {
96+
// imgui.addCMacro("IMGUI_API", "__declspec(dllexport)");
97+
// imgui.addCMacro("IMPLOT_API", "__declspec(dllexport)");
98+
// imgui.addCMacro("ZGUI_API", "__declspec(dllexport)");
99+
//}
126100

127101
imgui.addIncludePath(b.path("libs"));
128102
imgui.addIncludePath(b.path("libs/imgui"));
129103

104+
const emscripten = target.result.os.tag == .emscripten;
130105
if (!emscripten) {
131-
imgui.linkLibC();
106+
imgui.link_libc = true;
132107
if (target.result.abi != .msvc)
133-
imgui.linkLibCpp();
108+
imgui.link_libcpp = true;
134109
}
135110

136111
imgui.addCSourceFile(.{
@@ -157,11 +132,11 @@ pub fn build(b: *std.Build) void {
157132
.file = b.path("libs/imgui/misc/freetype/imgui_freetype.cpp"),
158133
.flags = cflags,
159134
});
160-
imgui.root_module.addCMacro("IMGUI_ENABLE_FREETYPE", "1");
135+
imgui.addCMacro("IMGUI_ENABLE_FREETYPE", "1");
161136
}
162137

163138
if (options.use_wchar32) {
164-
imgui.root_module.addCMacro("IMGUI_USE_WCHAR32", "1");
139+
imgui.addCMacro("IMGUI_USE_WCHAR32", "1");
165140
}
166141

167142
if (options.with_implot) {
@@ -216,8 +191,8 @@ pub fn build(b: *std.Build) void {
216191
.flags = cflags,
217192
});
218193

219-
imgui.root_module.addCMacro("IMGUI_ENABLE_TEST_ENGINE", "");
220-
imgui.root_module.addCMacro("IMGUI_TEST_ENGINE_ENABLE_COROUTINE_STDTHREAD_IMPL", "1");
194+
imgui.addCMacro("IMGUI_ENABLE_TEST_ENGINE", "");
195+
imgui.addCMacro("IMGUI_TEST_ENGINE_ENABLE_COROUTINE_STDTHREAD_IMPL", "1");
221196

222197
imgui.addIncludePath(b.path("libs/imgui_test_engine/"));
223198

@@ -268,7 +243,6 @@ pub fn build(b: *std.Build) void {
268243
winpthreads.addIncludePath(b.path("libs/winpthreads/include"));
269244
winpthreads.addIncludePath(b.path("libs/winpthreads/src"));
270245
winpthreads.linkLibC();
271-
b.installArtifact(winpthreads);
272246
imgui.linkLibrary(winpthreads);
273247
imgui.addSystemIncludePath(b.path("libs/winpthreads/include"));
274248
}
@@ -280,21 +254,28 @@ pub fn build(b: *std.Build) void {
280254
imgui.addSystemIncludePath(.{
281255
.cwd_relative = b.pathJoin(&.{ b.sysroot.?, "include" }),
282256
});
257+
imgui.addCSourceFiles(.{
258+
.files = &.{
259+
"libs/imgui/backends/imgui_impl_glfw.cpp",
260+
"libs/imgui/backends/imgui_impl_wgpu.cpp",
261+
},
262+
.flags = cflags,
263+
});
283264
} else {
284265
if (b.lazyDependency("zglfw", .{})) |zglfw| {
285266
imgui.addIncludePath(zglfw.path("libs/glfw/include"));
286267
}
287268
if (b.lazyDependency("zgpu", .{})) |zgpu| {
288269
imgui.addIncludePath(zgpu.path("libs/dawn/include"));
289270
}
271+
imgui.addCSourceFiles(.{
272+
.files = &.{
273+
"libs/imgui/backends/imgui_impl_glfw.cpp",
274+
"libs/imgui/backends/imgui_impl_wgpu.cpp",
275+
},
276+
.flags = &(cflags.* ++ .{"-DIMGUI_IMPL_WEBGPU_BACKEND_WGPU"}),
277+
});
290278
}
291-
imgui.addCSourceFiles(.{
292-
.files = &.{
293-
"libs/imgui/backends/imgui_impl_glfw.cpp",
294-
"libs/imgui/backends/imgui_impl_wgpu.cpp",
295-
},
296-
.flags = cflags,
297-
});
298279
},
299280
.glfw_opengl3 => {
300281
if (b.lazyDependency("zglfw", .{})) |zglfw| {
@@ -319,7 +300,7 @@ pub fn build(b: *std.Build) void {
319300
},
320301
.flags = cflags,
321302
});
322-
imgui.linkSystemLibrary("d3dcompiler_47");
303+
imgui.linkSystemLibrary("d3dcompiler_47", .{});
323304
},
324305
.win32_dx12 => {
325306
imgui.addCSourceFiles(.{
@@ -329,11 +310,11 @@ pub fn build(b: *std.Build) void {
329310
},
330311
.flags = cflags,
331312
});
332-
imgui.linkSystemLibrary("d3dcompiler_47");
333-
imgui.linkSystemLibrary("dwmapi");
313+
imgui.linkSystemLibrary("d3dcompiler_47", .{});
314+
imgui.linkSystemLibrary("dwmapi", .{});
334315
switch (target.result.abi) {
335-
.msvc => imgui.linkSystemLibrary("Gdi32"),
336-
.gnu => imgui.linkSystemLibrary("gdi32"),
316+
.msvc => imgui.linkSystemLibrary("Gdi32", .{}),
317+
.gnu => imgui.linkSystemLibrary("gdi32", .{}),
337318
else => {},
338319
}
339320
},
@@ -374,10 +355,10 @@ pub fn build(b: *std.Build) void {
374355
});
375356
},
376357
.osx_metal => {
377-
imgui.linkFramework("Foundation");
378-
imgui.linkFramework("Metal");
379-
imgui.linkFramework("Cocoa");
380-
imgui.linkFramework("QuartzCore");
358+
imgui.linkFramework("Foundation", .{});
359+
imgui.linkFramework("Metal", .{});
360+
imgui.linkFramework("Cocoa", .{});
361+
imgui.linkFramework("QuartzCore", .{});
381362
imgui.addCSourceFiles(.{
382363
.files = &.{
383364
"libs/imgui/backends/imgui_impl_osx.mm",
@@ -386,13 +367,14 @@ pub fn build(b: *std.Build) void {
386367
.flags = objcflags,
387368
});
388369
},
389-
.sdl2 => {
370+
.sdl3_gpu => {
390371
if (b.lazyDependency("zsdl", .{})) |zsdl| {
391-
imgui.addIncludePath(zsdl.path("libs/sdl2/include"));
372+
imgui.addIncludePath(zsdl.path("libs/sdl3/include"));
392373
}
393374
imgui.addCSourceFiles(.{
394375
.files = &.{
395-
"libs/imgui/backends/imgui_impl_sdl2.cpp",
376+
"libs/imgui/backends/imgui_impl_sdl3.cpp",
377+
"libs/imgui/backends/imgui_impl_sdlgpu3.cpp",
396378
},
397379
.flags = cflags,
398380
});
@@ -418,7 +400,7 @@ pub fn build(b: *std.Build) void {
418400
b.installArtifact(tests);
419401

420402
tests.root_module.addImport("zgui_options", options_module);
421-
tests.linkLibrary(imgui);
403+
tests.root_module.addImport("zgui", imgui);
422404

423405
test_step.dependOn(&b.addRunArtifact(tests).step);
424406
}

build.zig.zon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
.lazy = true,
2727
},
2828
.zsdl = .{
29-
.url = "https://github.com/zig-gamedev/zsdl/archive/360a5033010c71445ba42d1de3973abd50c6b128.tar.gz",
30-
.hash = "1220b661c47496008c7b2717c06b7bc1f79b1cfc430c885222d5d49c91d3fc57cbde",
29+
.url = "https://github.com/zig-gamedev/zsdl/archive/d03b4d4e7cb7a74e01d9dad30d0f1692286f58f8.tar.gz",
30+
.hash = "12205dcdb071febd9d3412a65e6235b832205cc49c1e20c88a71f62ada4e27dfb878",
3131
.lazy = true,
3232
},
3333
.freetype = .{

0 commit comments

Comments
 (0)