Skip to content
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

imgui: not found assert.h on wasm32 target #53

Open
kassane opened this issue Jan 19, 2025 · 5 comments
Open

imgui: not found assert.h on wasm32 target #53

kassane opened this issue Jan 19, 2025 · 5 comments
Labels
bug Something isn't working

Comments

@kassane
Copy link
Owner

kassane commented Jan 19, 2025

In file included from ./src/imgui/dcimgui.c:5:
/home/runner/.cache/zig/p/1220c640ad23d8800437166865e54f172c612fcfe6e000149a2b2af631c37b605f50/src/cimgui.h:93:10: fatal error: 'assert.h' file not found
   93 | #include <assert.h>
      |          ^~~~~~~~~~
1 error generated.
./src/imgui/package.d(15,15): Error: cannot find input file `./src/imgui/dcimgui.c`
public import imgui.dcimgui;
              ^

source: https://github.com/floooh/dcimgui/blob/9356c08eb4d1d320e79e418a36d59a427627634a/src/cimgui.h#L92-L95

How to reproduce

Clean zig global-cache + zig-cache packages and run any imgui sample in wasm32 target.

@kassane kassane added the bug Something isn't working label Jan 19, 2025
@kassane
Copy link
Owner Author

kassane commented Jan 19, 2025

Is it possible to make assert.h available only when build in debug mode?
cc: @floooh

@floooh
Copy link
Collaborator

floooh commented Jan 19, 2025

That looks like the dcimgui dependency doesn't get the Emscripten system header search path set, e.g. in sokol-zig this needs to happen in the 'upstream' build.zig, e.g.:

https://github.com/floooh/sokol-zig-imgui-sample/blob/e1f1c048f8a63488de3e2c76f50d1ebfefbda453/build.zig#L65-L69

...alternatively I also had the case that the Emscripten SDK setup was still pending when the C code was already being compiled, that's why there's also this dependency setup on the sokol C library (since the sokol C library depends on the Emscripten SDK setup, any C code compilation will only be attempted once the Emscripten SDK setup has finished):

https://github.com/floooh/sokol-zig-imgui-sample/blob/e1f1c048f8a63488de3e2c76f50d1ebfefbda453/build.zig#L71-L75

@kassane
Copy link
Owner Author

kassane commented Jan 19, 2025

https://github.com/floooh/sokol-zig-imgui-sample/blob/e1f1c048f8a63488de3e2c76f50d1ebfefbda453/build.zig#L71-L75

Based on sokol-d, the proccess is reversed!

sokol-d/build.zig

Lines 195 to 211 in 3faf1c0

if (options.with_sokol_imgui) {
lib.addCSourceFile(.{
.file = b.path(csrc_root ++ "sokol_imgui.c"),
.flags = cflags.slice(),
});
const imgui = try buildImgui(b, .{
.target = options.target,
.optimize = options.optimize,
.emsdk = options.emsdk,
.use_tsan = lib.root_module.sanitize_thread orelse false,
.use_ubsan = lib.root_module.sanitize_c orelse false,
});
for (imgui.root_module.include_dirs.items) |dir| {
try lib.root_module.include_dirs.append(b.allocator, dir);
}
lib.linkLibrary(imgui);
}

https://github.com/floooh/sokol-zig-imgui-sample/blob/e1f1c048f8a63488de3e2c76f50d1ebfefbda453/build.zig#L65-L69

Note

Only the imgui is standalone, requiring a double emsdk import, unlike ldc2 which inherits all flags from libsokol.

sokol-d/build.zig

Lines 1200 to 1214 in 3faf1c0

if (options.emsdk) |emsdk| {
if (libimgui.rootModuleTarget().isWasm()) {
if (try emSdkSetupStep(b, emsdk)) |emsdk_setup| {
libimgui.step.dependOn(&emsdk_setup.step);
}
// add the Emscripten system include seach path
libimgui.addIncludePath(emSdkLazyPath(b, emsdk, &.{
"upstream",
"emscripten",
"cache",
"sysroot",
"include",
}));
}
}

@kassane
Copy link
Owner Author

kassane commented Jan 19, 2025

I tried removing duplicate emsdk import:

diff-patch
diff --git a/build.zig b/build.zig
index 118a7d5..586de7b 100644
--- a/build.zig
+++ b/build.zig
@@ -73,20 +73,19 @@ pub fn buildLibSokol(b: *Build, options: LibSokolOptions) !*CompileStep {
         lib.root_module.root_source_file = b.path("src/handmade/math.zig");
         if (options.optimize != .Debug)
             lib.want_lto = true;
+
         // make sure we're building for the wasm32-emscripten target, not wasm32-freestanding
         if (lib.rootModuleTarget().os.tag != .emscripten) {
             std.log.err("Please build with 'zig build -Dtarget=wasm32-emscripten", .{});
             return error.Wasm32EmscriptenExpected;
         }
         // one-time setup of Emscripten SDK
-        if (!options.with_sokol_imgui) {
-            if (options.emsdk) |emsdk| {
-                if (try emSdkSetupStep(b, emsdk)) |emsdk_setup| {
-                    lib.step.dependOn(&emsdk_setup.step);
-                }
-                // add the Emscripten system include seach path
-                lib.addIncludePath(emSdkLazyPath(b, emsdk, &.{ "upstream", "emscripten", "cache", "sysroot", "include" }));
+        if (options.emsdk) |emsdk| {
+            if (try emSdkSetupStep(b, emsdk)) |emsdk_setup| {
+                lib.step.dependOn(&emsdk_setup.step);
             }
+            // add the Emscripten system include seach path
+            lib.addSystemIncludePath(emSdkLazyPath(b, emsdk, &.{ "upstream", "emscripten", "cache", "sysroot", "include" }));
         }
     }
 
@@ -1197,21 +1196,6 @@ fn buildImgui(b: *Build, options: libImGuiOptions) !*CompileStep {
         const imgui = dep.path(imguiver_path);
         libimgui.addIncludePath(imgui);
 
-        if (options.emsdk) |emsdk| {
-            if (libimgui.rootModuleTarget().isWasm()) {
-                if (try emSdkSetupStep(b, emsdk)) |emsdk_setup| {
-                    libimgui.step.dependOn(&emsdk_setup.step);
-                }
-                // add the Emscripten system include seach path
-                libimgui.addIncludePath(emSdkLazyPath(b, emsdk, &.{
-                    "upstream",
-                    "emscripten",
-                    "cache",
-                    "sysroot",
-                    "include",
-                }));
-            }
-        }
         libimgui.addCSourceFiles(.{
             .root = imgui,
             .files = &.{
output-error
run-droptest
└─ run /home/kassane/.cache/zig/p/12201185a3deb48d17035e6c619f2b28cef8cd6080afe88e061e326a6a3826a7a370/upstream/emscripten/emrun
   └─ install generated/
      └─ emcc
         └─ zig build-lib imgui Debug wasm32-emscripten-none 6 errors
/home/kassane/.cache/zig/p/1220c640ad23d8800437166865e54f172c612fcfe6e000149a2b2af631c37b605f50/src/imgui.h:90:10: error: 'assert.h' file not found
#include <assert.h>
         ^~~~~~~~~~~
/home/kassane/.cache/zig/p/1220c640ad23d8800437166865e54f172c612fcfe6e000149a2b2af631c37b605f50/src/cimgui.cpp:5:10: note: in file included from /home/kassane/.cache/zig/p/1220c640ad23d8800437166865e54f172c612fcfe6e000149a2b2af631c37b605f50/src/cimgui.cpp:5:
#include "imgui.h"
         ^
/home/kassane/.cache/zig/p/1220c640ad23d8800437166865e54f172c612fcfe6e000149a2b2af631c37b605f50/src/imgui.h:90:10: error: 'assert.h' file not found
#include <assert.h>
         ^~~~~~~~~~~
/home/kassane/.cache/zig/p/1220c640ad23d8800437166865e54f172c612fcfe6e000149a2b2af631c37b605f50/src/imgui_tables.cpp:198:10: note: in file included from /home/kassane/.cache/zig/p/1220c640ad23d8800437166865e54f172c612fcfe6e000149a2b2af631c37b605f50/src/imgui_tables.cpp:198:
#include "imgui.h"
         ^
/home/kassane/.cache/zig/p/1220c640ad23d8800437166865e54f172c612fcfe6e000149a2b2af631c37b605f50/src/imgui.h:90:10: error: 'assert.h' file not found
#include <assert.h>
         ^~~~~~~~~~~
/home/kassane/.cache/zig/p/1220c640ad23d8800437166865e54f172c612fcfe6e000149a2b2af631c37b605f50/src/imgui_demo.cpp:106:10: note: in file included from /home/kassane/.cache/zig/p/1220c640ad23d8800437166865e54f172c612fcfe6e000149a2b2af631c37b605f50/src/imgui_demo.cpp:106:
#include "imgui.h"
         ^
/home/kassane/.cache/zig/p/1220c640ad23d8800437166865e54f172c612fcfe6e000149a2b2af631c37b605f50/src/imgui.h:90:10: error: 'assert.h' file not found
#include <assert.h>
         ^~~~~~~~~~~
/home/kassane/.cache/zig/p/1220c640ad23d8800437166865e54f172c612fcfe6e000149a2b2af631c37b605f50/src/imgui_draw.cpp:34:10: note: in file included from /home/kassane/.cache/zig/p/1220c640ad23d8800437166865e54f172c612fcfe6e000149a2b2af631c37b605f50/src/imgui_draw.cpp:34:
#include "imgui.h"
         ^
/home/kassane/.cache/zig/p/1220c640ad23d8800437166865e54f172c612fcfe6e000149a2b2af631c37b605f50/src/imgui.h:90:10: error: 'assert.h' file not found
#include <assert.h>
         ^~~~~~~~~~~
/home/kassane/.cache/zig/p/1220c640ad23d8800437166865e54f172c612fcfe6e000149a2b2af631c37b605f50/src/imgui_widgets.cpp:43:10: note: in file included from /home/kassane/.cache/zig/p/1220c640ad23d8800437166865e54f172c612fcfe6e000149a2b2af631c37b605f50/src/imgui_widgets.cpp:43:
#include "imgui.h"
         ^
/home/kassane/.cache/zig/p/1220c640ad23d8800437166865e54f172c612fcfe6e000149a2b2af631c37b605f50/src/imgui.h:90:10: error: 'assert.h' file not found
#include <assert.h>
         ^~~~~~~~~~~
/home/kassane/.cache/zig/p/1220c640ad23d8800437166865e54f172c612fcfe6e000149a2b2af631c37b605f50/src/imgui.cpp:1071:10: note: in file included from /home/kassane/.cache/zig/p/1220c640ad23d8800437166865e54f172c612fcfe6e000149a2b2af631c37b605f50/src/imgui.cpp:1071:
#include "imgui.h"
         ^
error: warning(compilation): failed to delete '/home/kassane/sokol-d/.zig-cache/tmp/b180ba3be8c1367-cimgui.o.d': FileNotFound
warning(compilation): failed to delete '/home/kassane/sokol-d/.zig-cache/tmp/7c5f4382b077c680-imgui_tables.o.d': FileNotFound
warning(compilation): failed to delete '/home/kassane/sokol-d/.zig-cache/tmp/2631f3da44f3d9a5-imgui_demo.o.d': FileNotFound
warning(compilation): failed to delete '/home/kassane/sokol-d/.zig-cache/tmp/353cd2b018dc0fd2-imgui_draw.o.d': FileNotFound
warning(compilation): failed to delete '/home/kassane/sokol-d/.zig-cache/tmp/81484e60b1b0734-imgui_widgets.o.d': FileNotFound
warning(compilation): failed to delete '/home/kassane/sokol-d/.zig-cache/tmp/1bb28bc0c30a803c-imgui.o.d': FileNotFound

fixed by: b531649

However, returned previous error...

@kassane
Copy link
Owner Author

kassane commented Jan 20, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants