-
Notifications
You must be signed in to change notification settings - Fork 40
Implement cbool for emscripten_set_main_loop to reflect recent emsdk change #130
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
base: main
Are you sure you want to change the base?
Conversation
| return 0 | ||
|
|
||
| when defined(emscripten): | ||
| type cbool* {.importc: "bool", nodecl.} = uint8 |
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.
| type cbool* {.importc: "bool", nodecl.} = uint8 | |
| type cbool* {.importc: "bool", header:"<stdbool>".} = uint8 |
This will fail if stdbool is not imported, nodecl is used for compiler builtins, though it's possible that the compiler auto-imports stdbool and issues a warning. See https://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf p253

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.
Tested both variants. Only the first one worked on my Windows machine.
| type em_callback_func* = proc() {.cdecl.} | ||
| {.push importc.} | ||
| proc emscripten_set_main_loop*(f: em_callback_func, fps, simulate_infinite_loop: cint) | ||
| proc emscripten_set_main_loop*(f: em_callback_func, fps: cint, simulate_infinite_loop: cbool) |
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.
| proc emscripten_set_main_loop*(f: em_callback_func, fps: cint, simulate_infinite_loop: cbool) | |
| proc emscripten_set_main_loop*(f: em_callback_func, fps: cint, simulate_infinite_loop: bool) |
Given that cbool and Nim bool both defer to _Bool it might be okay to reuse Nim bool here and it might be the reason why cbool doesn't exist in Nim.
I leave that choice to the maintainers of the library.
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.
Tested both variants. Only the first one worked on my Windows machine.
|
I've tested the changes in the PR. Compilation still fails but this time the reason is that posix_spawnp is undefined on Windows. To fix that, I've added when defined(windows):
--clang.exe:emcc.bat # Replace C
--clang.linkerexe:emcc.bat # Replace C linker
--clang.cpp.exe:emcc.bat # Replace C++
--clang.cpp.linkerexe:emcc.bat # Replace C++ linker.
+ --define:useForkTo make the fix permanent, this change should be added to The game didn't run eventually, there was an error about lidbfs.js in the console but that's still a progress:
|
This is related to and resolves issue #129 for me.
Emsdk recently changed the type signature for emscripten_set_main_loop specifically changing the argument from int to bool. There exists an issue when linking emscripten in regards to the definition of a ctype for bool. Nim language has proper support for the bool (boolean) C99 type however the function definitions use custom defined types to match the fact that WASM thunks everything to int32? Either way by adding a cbool type which corresponds to the "bool" declared in emsdk function definition the linking now doesnt fail.
emsdk breaking change
I spoke to the nimlang developers in matrix chat that pointed me to the proper definition for bool internal to nim language so it lead me to believe that its related to nico. though adding the same cbool declaration to nim/system/ctypes.nim also alleviated the issue I feel a bit out of my depth here in the sense that I cant fully articulate where the problem is.
Also spoke to the emsdk developer who made the change. Investigating how to write tests for this or where to look.