Closed kassane closed 5 months ago
Need cimgui binding for run example. Old module amalgamation cimgui + sokol_imgui: https://github.com/kassane/sokol-d/blob/1d1fc586969aba82fc6b854aeb2d16f7ec656976/src/sokol/imgui.d
now, only sokol_imgui: https://github.com/kassane/sokol-d/blob/1110006dd280fca4be0a16402fc6455f1c82f494/src/examples/imgui.d#L103-L115
cimgui
to the example?Unlike zig translate-c
, importC
doesn't read header, only C source.
However, this still falls short (translate-c
also has some issues). The only difference between the two projects is the level of support (zig project wins here).
And not have current D module about cimgui
, only old imgui
(C++, no extern(C)
) version.
Please, @floooh.
Test it!
Note: For wasm32 build change... https://github.com/kassane/sokol-d/blob/8d589cb82b9a509f561147e3feec853cc1663157/build.zig#L245
Why block? CI error. Why imgui-cpp
need assert.h
, but rebuild (no-clean global cache) works!
And for old ldc2 versions (1.36...1.38 [latest]) change... .freestanding
to .emscripten
or try ldc2-master
https://github.com/kassane/sokol-d/blob/8d589cb82b9a509f561147e3feec853cc1663157/build.zig#L512-L515
Note that there was an bug in the translateC step in the cimgui sample which caused this above error about missing assert.h in imgui.h when trying to build for wasm32-emscripten. I fixed this by always running the translateC step with the host target (instead of the build target):
...otherwise I would somehow need to inject the Emscripten include path into the translateC step. Using the host triplet is the better solution though, since there no platform-specific stuff happening in the translateC step.
Note that there was an bug in the translateC step in the cimgui sample which caused this above error about missing assert.h in imgui.h when trying to build for wasm32-emscripten. I fixed this by always running the translateC step with the host target [...]
According to this solution, perhaps it would have been possible to use importC to bypass the error, just like translate-c.
However, the assert.h
error occurs during the libsokol build, a step before ldc2.
I know there exists a step wait for emsdk_setup
in libsokol and this will run imgui in a direct dependency.
https://github.com/kassane/sokol-d/blob/20fe32c375502d2d4bc709086a0fdd2027e31f0c/build.zig#L79-L82 https://github.com/kassane/sokol-d/blob/20fe32c375502d2d4bc709086a0fdd2027e31f0c/build.zig#L184-L194
Another question that puzzles me. Would it be useful to use the build.zig
dependency to make sokol-zig a dependency of sokol-d?
That way we could reduce the complexity redundancy of build.zig
.
@floooh , my assert.h
fix - if with_imgui enabled, move lib.step.dependOn(&emsdk_setup.step);
to libimgui.step.dependOn(&emsdk_setup.step);
https://github.com/kassane/sokol-d/commit/bca71beb160425aeecf7a76f7256f4e2ca356744
Ah btw, I fixed this a bit differently, by letting the cimgui library depend on the sokol C library (up in the top level project):
Since the sokol C library depends on the Emscripten SDK setup this also guarantees that the SDK is setup when cimgui is compiled (e.g. the idea is that all C libraries need to depend on the sokol C library... but maybe this could indeed be moved up into sokol-zig since we're iterating over the C libraries anyway in the linker step - also the injection of the Emscripten include path... hmm...)
Another question that puzzles me. Would it be useful to use the build.zig dependency to make sokol-zig a dependency of sokol-d?
Not a fan tbh, it would probably make more sense to move the emsdk stuff into a separate project (and Zig package) which could then be used both by sokol-zig and sokol-d.
Wrote a ticket for that idea (to handle the C library stuff in sokol-zig build.zig): https://github.com/floooh/sokol-zig/issues/71
it would probably make more sense to move the emsdk stuff into a separate project (and Zig package) which could then be used both by sokol-zig and sokol-d.
Make sense. Like, https://github.com/kassane/anotherBuildStep (a.k.a abs) Also, I have not yet completed emsdk support. But in pacman.d, besides sokol-d (passing libsokol + D modules), using abs to set ldc2. Maybe ldc2/ldmd2 could be ported outside of sokol-d using this idea.
fix #10
old branch, need long rebase... I'll delete (for testing only) https://github.com/kassane/sokol-d/tree/imgui-support
inspired by: