-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port dcimgui
to importC - CI fix
#39
Conversation
With importC, ldc2/ldmd2 call |
Ignore warning: In file included from /home/runner/work/sokol-d/sokol-d/src/cimgui/dcimgui.c:6:
In file included from /home/runner/.cache/zig/p/1220190c1c465474d437a8f7955c8b759e6e4ef32e9a61e9f0b5dbe74ebcd84622b3/src/cimgui.h:93:
In file included from /home/runner/.cache/zig/p/12201d024e47d97dea4d1d6024a9cf1b35ca8be8e4fa1a0ecf6ee9080e479467183a/upstream/emscripten/cache/sysroot/include/assert.h:1:
/home/runner/.cache/zig/p/12201d024e47d97dea4d1d6024a9cf1b35ca8be8e4fa1a0ecf6ee9080e479467183a/upstream/emscripten/cache/sysroot/include/features.h:27:9: warning: '__restrict' macro redefined [-Wmacro-redefined]
27 | #define __restrict restrict
| ^
/opt/hostedtoolcache/ldc2/82878ef3/x64/ldc2-82878ef3-linux-x86_64/bin/../import/importc.h:28:9: note: previous definition is here
28 | #define __restrict
| ^
1 warning generated. |
Next step: fix dub - cimgui not founddub build :imgui
Starting Performing "debug" build using /home/kassane/.local/ldc2-82878ef3-linux-x86_64/bin/ldc2 for x86_64.
Building sokol-d:imgui 0.1.6: building configuration [application]
Pre-build Running commands
src/cimgui/dcimgui.c:6:10: fatal error: cimgui.h: No such file or directory
6 | #include <cimgui.h>
| ^~~~~~~~~~
compilation terminated.
src/cimgui/cimgui.d(4,15): Error: /usr/bin/cc failed with status: 1 How to export zig-pkg to |
I'm also currently in the process of fixing the differences between the original cimgui API and the dear_bindings API. One important difference I noticed is that the new C bindings header must be compiled in C11 mode (there are some duplicate symbol definitions in the header which are valid in C11, but not C99 - I don't know if this intended or just an oversight in the bindings generator). Also: I decided to call the resulting static link library just |
Nice! I've renamed the package to
|
@@ -216,6 +218,8 @@ subPackage { | |||
libs "sokol" | |||
lflags "-Lzig-out/lib" platform="posix" | |||
lflags "/LIBPATH:zig-out/lib" platform="windows" | |||
dflags "-P-I$HOME/.cache/zig/p/1220190c1c465474d437a8f7955c8b759e6e4ef32e9a61e9f0b5dbe74ebcd84622b3/src" platform="posix" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although it's not ideal, it works. Instead of cImportPaths
/cSourcePaths
which are already available in the dub.
References
|
||
- name: (Zig) Build Shaders | ||
run: zig build shaders | ||
- name: (Zig) Running Test | ||
if: runner.os != 'Windows' | ||
run: zig build test -DzigCC | ||
- name: (Zig) Build Native | ||
run: zig build -DzigCC --summary all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now, zigcc-wrapper
as lld
emit warnings on Linux:
ld.lld: warning: /home/kassane/sokol-d/.zig-cache/o/83dda58209fccbe4164f94e931ca58d7/libsokol.a: archive member '/lib64/libasound.so' is neither ET_REL nor LLVM bitcode
ld.lld: warning: /home/kassane/sokol-d/.zig-cache/o/83dda58209fccbe4164f94e931ca58d7/libsokol.a: archive member '/lib64/libGL.so' is neither ET_REL nor LLVM bitcode
ld.lld: warning: /home/kassane/sokol-d/.zig-cache/o/83dda58209fccbe4164f94e931ca58d7/libsokol.a: archive member '/lib64/libX11.so' is neither ET_REL nor LLVM bitcode
ld.lld: warning: /home/kassane/sokol-d/.zig-cache/o/83dda58209fccbe4164f94e931ca58d7/libsokol.a: archive member '/lib64/libXi.so' is neither ET_REL nor LLVM bitcode
ld.lld: warning: /home/kassane/sokol-d/.zig-cache/o/83dda58209fccbe4164f94e931ca58d7/libsokol.a: archive member '/lib64/libXcursor.so' is neither ET_REL nor LLVM bitcode
but, works!!
I haven't discovered who is giving the warning in wasm32 target (ldc2-master [llvm19], zig-master [llvm19], emcc [llvm20] - set generic-cpu): update: emcc emit warnings with LTO enabled and Zig emit target-features on LLVM-IR. |
The change to dcimgui (via importC) has already been merged. It is worth emphasizing that any changes made in the headers are currently incorporated when updating the zon (imgui pkg). b6591f0 Lines 1 to 8 in 46746d5
Lines 3 to 4 in 46746d5
|
importC cannot support header files, only Referenceshttps://issues.dlang.org/show_bug.cgi?id=23479 |
Hey @kassane, I updated dcimgui again to add a docking version (so that there's now an all-in-one repo both for C++ and C, and the regular vs docking-branch-version of Dear ImGui. I hope this doesn't break your current work, but if yes the changes should be minimal (I force-pushed the 1.95.1 tag though). (also see the updated readme: https://github.com/floooh/dcimgui) |
Nice! 704b9dd
|
FYI I'll try a few more things in dcimgui in the next few days and may force-push the tag 1.91.5 again (hope that isn't too disruptive):
|
Avoiding naming redundancies will make your code more readable. When declaring modules in Zig and D, it is possible to easily make import naming compatible, which is already the case in the examples. Using importC and updating the dcimgui package hash any changes in The negative point of importC, in my opinion, is the fact that the D compiler analyzes C files using D rules. And also the editor can't autocomplete code from importC.
Moving Unlike sokol-d which just imports dcimgui and configures build in The good thing is that it becomes more convenient for zig users to build without configuring it individually per project. |
Ok, the dcimgui repo can now be used directly as Zig module (see the build.zig and build.zig.zon): https://github.com/floooh/dcimgui ...and the changes in the sokol-zig-imgui-sample: floooh/sokol-zig-imgui-sample@073a6ce ...I had to keep the |
my local test, works on D: diff changesdiff --git a/build.zig b/build.zig
index 53c1a0c..157f597 100644
--- a/build.zig
+++ b/build.zig
@@ -923,7 +923,7 @@ fn buildImgui(b: *Build, options: libImGuiOptions) !*CompileStep {
libimgui.addCSourceFiles(.{
.root = cimgui,
.files = &.{
- "cimgui.cpp",
+ "zimgui.cpp",
},
.flags = &.{
"-Wall",
diff --git a/src/cimgui/dcimgui.c b/src/cimgui/dcimgui.c
index c9674fb..b537fd3 100644
--- a/src/cimgui/dcimgui.c
+++ b/src/cimgui/dcimgui.c
@@ -3,6 +3,6 @@
#ifndef DCIMGUI_H
#define DCIMGUI_H
#pragma attribute(push, nogc, nothrow) // dmd-2.110.x feature
-#include <cimgui.h>
+#include <zimgui.h>
#pragma attribute(pop)
#endif // DCIMGUI_H
diff --git a/src/examples/imgui.d b/src/examples/imgui.d
index 7f3e91a..dbc6372 100644
--- a/src/examples/imgui.d
+++ b/src/examples/imgui.d
@@ -11,7 +11,7 @@ import sgapp = sokol.glue;
import sapp = sokol.app;
import imgui = sokol.imgui;
import log = sokol.log;
-import cimgui.cimgui;
+import ig = cimgui.cimgui;
extern (C):
@safe:
@@ -52,19 +52,19 @@ void frame() @trusted
imgui.newFrame(imgui_desc);
/*=== UI CODE STARTS HERE ===*/
- const ImVec2 window_pos = {10, 10};
- const ImVec2 window_size = {400, 100};
- igSetNextWindowPos(window_pos, ImGuiCond_.ImGuiCond_Once);
- igSetNextWindowSize(window_size, ImGuiCond_.ImGuiCond_Once);
- igBegin("Hello Dear ImGui!".ptr, null, ImGuiWindowFlags_.ImGuiWindowFlags_None);
+ const ig.ImVec2 window_pos = {10, 10};
+ const ig.ImVec2 window_size = {400, 100};
+ ig.SetNextWindowPos(window_pos, ig.ImGuiCond_.ImGuiCond_Once);
+ ig.SetNextWindowSize(window_size, ig.ImGuiCond_.ImGuiCond_Once);
+ ig.Begin("Hello Dear ImGui!".ptr, null, ig.ImGuiWindowFlags_.ImGuiWindowFlags_None);
const(char)* label = "Background";
float[3] rgb = [
state.pass_action.colors[0].clear_value.r,
state.pass_action.colors[0].clear_value.g,
state.pass_action.colors[0].clear_value.b
];
- igColorEdit3(label, &rgb[0], ImGuiColorEditFlags_.ImGuiColorEditFlags_None);
- igEnd();
+ ig.ColorEdit3(label, &rgb[0], ig.ImGuiColorEditFlags_.ImGuiColorEditFlags_None);
+ ig.End();
/*=== UI CODE ENDS HERE ===*/
sg.Pass pass = {action: state.pass_action, swapchain: sgapp.swapchain};
diff --git a/src/sokol/c/sokol_imgui.c b/src/sokol/c/sokol_imgui.c
index 346be8a..ae256d0 100644
--- a/src/sokol/c/sokol_imgui.c
+++ b/src/sokol/c/sokol_imgui.c
@@ -1,7 +1,7 @@
#if defined(IMPL)
#define SOKOL_IMGUI_IMPL
#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS
-#include "cimgui.h"
+#include "zimgui.h"
#endif
#include "sokol_defines.h"
#include "sokol_app.h"
diff --git a/src/sokol/c/sokol_imgui.h b/src/sokol/c/sokol_imgui.h
index 1a7c650..fa2e50d 100644
--- a/src/sokol/c/sokol_imgui.h
+++ b/src/sokol/c/sokol_imgui.h
@@ -2650,9 +2650,9 @@ SOKOL_API_IMPL void simgui_setup(const simgui_desc_t* desc) {
io->Fonts->AddFontDefault();
}
#else
- igCreateContext(NULL);
- igStyleColorsDark(igGetStyle());
- ImGuiIO* io = igGetIO();
+ CreateContext(NULL);
+ StyleColorsDark(GetStyle());
+ ImGuiIO* io = GetIO();
if (!_simgui.desc.no_default_font) {
ImFontAtlas_AddFontDefault(io->Fonts, NULL);
}
@@ -2667,7 +2667,7 @@ SOKOL_API_IMPL void simgui_setup(const simgui_desc_t* desc) {
#if defined(__cplusplus)
ImGuiPlatformIO* pio = &ImGui::GetPlatformIO();
#else
- ImGuiPlatformIO* pio = igGetPlatformIO();
+ ImGuiPlatformIO* pio = GetPlatformIO();
#endif
pio->Platform_SetClipboardTextFn = _simgui_set_clipboard;
pio->Platform_GetClipboardTextFn = _simgui_get_clipboard;
@@ -2850,7 +2850,7 @@ SOKOL_API_IMPL void simgui_create_fonts_texture(const simgui_font_tex_desc_t* de
#if defined(__cplusplus)
ImGuiIO* io = &ImGui::GetIO();
#else
- ImGuiIO* io = igGetIO();
+ ImGuiIO* io = GetIO();
#endif
// a default font sampler
@@ -2904,7 +2904,7 @@ SOKOL_API_IMPL void simgui_shutdown(void) {
#if defined(__cplusplus)
ImGui::DestroyContext();
#else
- igDestroyContext(0);
+ DestroyContext(0);
#endif
// NOTE: it's valid to call the destroy funcs with SG_INVALID_ID
sg_destroy_pipeline(_simgui.pip_unfilterable);
@@ -2980,7 +2980,7 @@ SOKOL_API_IMPL void simgui_new_frame(const simgui_frame_desc_t* desc) {
#if defined(__cplusplus)
ImGuiIO* io = &ImGui::GetIO();
#else
- ImGuiIO* io = igGetIO();
+ ImGuiIO* io = GetIO();
#endif
if (!io->Fonts->TexReady) {
simgui_destroy_fonts_texture();
@@ -3002,7 +3002,7 @@ SOKOL_API_IMPL void simgui_new_frame(const simgui_frame_desc_t* desc) {
#if defined(__cplusplus)
ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();
#else
- ImGuiMouseCursor imgui_cursor = igGetMouseCursor();
+ ImGuiMouseCursor imgui_cursor = GetMouseCursor();
#endif
sapp_mouse_cursor cursor = sapp_get_mouse_cursor();
switch (imgui_cursor) {
@@ -3023,7 +3023,7 @@ SOKOL_API_IMPL void simgui_new_frame(const simgui_frame_desc_t* desc) {
#if defined(__cplusplus)
ImGui::NewFrame();
#else
- igNewFrame();
+ NewFrame();
#endif
}
@@ -3054,9 +3054,9 @@ SOKOL_API_IMPL void simgui_render(void) {
ImDrawData* draw_data = ImGui::GetDrawData();
ImGuiIO* io = &ImGui::GetIO();
#else
- igRender();
- ImDrawData* draw_data = igGetDrawData();
- ImGuiIO* io = igGetIO();
+ Render();
+ ImDrawData* draw_data = GetDrawData();
+ ImGuiIO* io = GetIO();
#endif
if (0 == draw_data) {
return;
@@ -3207,7 +3207,7 @@ SOKOL_API_IMPL void simgui_add_focus_event(bool focus) {
ImGuiIO* io = &ImGui::GetIO();
io->AddFocusEvent(focus);
#else
- ImGuiIO* io = igGetIO();
+ ImGuiIO* io = GetIO();
ImGuiIO_AddFocusEvent(io, focus);
#endif
}
@@ -3221,7 +3221,7 @@ SOKOL_API_IMPL void simgui_add_mouse_pos_event(float x, float y) {
#endif
io->AddMousePosEvent(x, y);
#else
- ImGuiIO* io = igGetIO();
+ ImGuiIO* io = GetIO();
#if (IMGUI_VERSION_NUM >= 18950)
ImGuiIO_AddMouseSourceEvent(io, ImGuiMouseSource_Mouse);
#endif
@@ -3238,7 +3238,7 @@ SOKOL_API_IMPL void simgui_add_touch_pos_event(float x, float y) {
#endif
io->AddMousePosEvent(x, y);
#else
- ImGuiIO* io = igGetIO();
+ ImGuiIO* io = GetIO();
#if (IMGUI_VERSION_NUM >= 18950)
ImGuiIO_AddMouseSourceEvent(io, ImGuiMouseSource_TouchScreen);
#endif
@@ -3255,7 +3255,7 @@ SOKOL_API_IMPL void simgui_add_mouse_button_event(int mouse_button, bool down) {
#endif
io->AddMouseButtonEvent(mouse_button, down);
#else
- ImGuiIO* io = igGetIO();
+ ImGuiIO* io = GetIO();
#if (IMGUI_VERSION_NUM >= 18950)
ImGuiIO_AddMouseSourceEvent(io, ImGuiMouseSource_Mouse);
#endif
@@ -3272,7 +3272,7 @@ SOKOL_API_IMPL void simgui_add_touch_button_event(int mouse_button, bool down) {
#endif
io->AddMouseButtonEvent(mouse_button, down);
#else
- ImGuiIO* io = igGetIO();
+ ImGuiIO* io = GetIO();
#if (IMGUI_VERSION_NUM >= 18950)
ImGuiIO_AddMouseSourceEvent(io, ImGuiMouseSource_TouchScreen);
#endif
@@ -3289,7 +3289,7 @@ SOKOL_API_IMPL void simgui_add_mouse_wheel_event(float wheel_x, float wheel_y) {
#endif
io->AddMouseWheelEvent(wheel_x, wheel_y);
#else
- ImGuiIO* io = igGetIO();
+ ImGuiIO* io = GetIO();
#if (IMGUI_VERSION_NUM >= 18950)
ImGuiIO_AddMouseSourceEvent(io, ImGuiMouseSource_Mouse);
#endif
@@ -3303,7 +3303,7 @@ SOKOL_API_IMPL void simgui_add_key_event(int imgui_key, bool down) {
ImGuiIO* io = &ImGui::GetIO();
io->AddKeyEvent((ImGuiKey)imgui_key, down);
#else
- ImGuiIO* io = igGetIO();
+ ImGuiIO* io = GetIO();
ImGuiIO_AddKeyEvent(io, (ImGuiKey)imgui_key, down);
#endif
}
@@ -3314,7 +3314,7 @@ SOKOL_API_IMPL void simgui_add_input_character(uint32_t c) {
ImGuiIO* io = &ImGui::GetIO();
io->AddInputCharacter(c);
#else
- ImGuiIO* io = igGetIO();
+ ImGuiIO* io = GetIO();
ImGuiIO_AddInputCharacter(io, c);
#endif
}
@@ -3325,7 +3325,7 @@ SOKOL_API_IMPL void simgui_add_input_characters_utf8(const char* c) {
ImGuiIO* io = &ImGui::GetIO();
io->AddInputCharactersUTF8(c);
#else
- ImGuiIO* io = igGetIO();
+ ImGuiIO* io = GetIO();
ImGuiIO_AddInputCharactersUTF8(io, c);
#endif
}
@@ -3490,7 +3490,7 @@ SOKOL_API_IMPL bool simgui_handle_event(const sapp_event* ev) {
#if defined(__cplusplus)
ImGuiIO* io = &ImGui::GetIO();
#else
- ImGuiIO* io = igGetIO();
+ ImGuiIO* io = GetIO();
#endif
switch (ev->type) {
case SAPP_EVENTTYPE_FOCUSED: get same result: |
Well yeah, with changes in sokol_imgui.h it works. I need to come up with a way to pass the prefix into sokol_imgui.h so that it can work with different C API naming conventions. |
FYI: floooh/sokol#1166 This allows to override the C prefix in sokol_imgui. ...next I'll add more options to sokol-zig's sokol library compilation to allow overriding both this prefix and the cimgui.h header path. Associated commit in sokol-zig: floooh/sokol-zig@3132888 ...switching the dcimgui/build.zig over to zimgui.cpp/zimgui.h: floooh/dcimgui@85ddb04 ...and finally how it's all coming together: |
Ah sh*t, the prefix-less cimgui functions collide with Win32 operating system functions :/ https://github.com/floooh/sokol-zig-imgui-sample/actions/runs/12223678665/job/34095519722 Argh... I'll go back to the 'ig' prefix for now :/ ...I think the only way to get rid of the prefix is to use the dear_bindings meta-data to create a Zig module (similar to the sokol-zig bindings generation) instead of relying on the TranslateC feature. That way we could also switch to camelCase (e.g. ...that's for a later time though... |
my suggestion for |
Hmm, in the CMakeLists.txt file I create two separate libraries (imgui and imgui-docking): ...maybe it makes sense to expose two similar modules from the dcimgui build.zig? I haven't thought about using the docking version in the language bindings yet tbh. |
Maybe! It is common in cmake. Based on 518249b
You can ask the zig community about this if you like. |
info: https://dlang.org/spec/importc.html
pragma attribute(push, nogc, nothrow)
: https://dlang.org/changelog/pending.html#dmd.importc-pragma-stcNote
D compiler scans the C file(s) and apply semantic analyzer regardless of file type.
Reference