floooh / sokol-zig

Zig bindings for the sokol headers (https://github.com/floooh/sokol)
zlib License
341 stars 46 forks source link

Finalize WASM and zig-0.12.0 support (see #50) #51

Closed floooh closed 7 months ago

floooh commented 7 months ago

...not this time, but should be considered for an update

floooh commented 7 months ago

@kassane fyi πŸ‘†(PR into master to keep track of what I'm adding... e.g. the black screen samples are working now...

kassane commented 7 months ago

@kassane fyi πŸ‘†(PR into master to keep track of what I'm adding... e.g. the black screen samples are working now...

Amazing! image

floooh commented 7 months ago

Now with a shell.html which fills the whole client area :)

image
floooh commented 7 months ago

KC85 emulator running in browser (wasn't supported before, but quite trivial now):

Screenshot 2024-01-15 at 16 39 34
kassane commented 7 months ago

On: https://github.com/floooh/sokol-zig/pull/51/commits/a2e4b461d6a78ab4f542e2aef391bde424175173

Does this do a recursive dependency lookup on libsokol? For example, if you had any examples that used cimgui, would it link it directly to sokol so that emcc would pull both of them?

floooh commented 7 months ago

The idea is that one could add additional C library compile steps (like for instance cimgui) to the top-level module (same as happens with the sokol C library), and the Emscripten linker step would pick those up automatically.

I don't actually know whether it's fully recursive, but for the cimgui case, I wouldn't add that dependency to the sokol module, but to the 'Zig main module' (obviously that loop which scans for dependencies isn't recursive, but I don't know if the 'dependency iterator' does that for me... from looking around in the stdlib where this dependency iterator is used, all places I saw don't have any sort of 'explicit recursion', but still seem to walk over all dependencies).

I haven't actually tested it though, only made sure that it discovers the sokol library dependency.

floooh commented 7 months ago

Whoop whoop!

kkukshtel commented 6 months ago

@floooh Been tracing through these changes as I look to move my own sokol-based engine to work with wasm. If the intention is that sokol is being comsumed as a wasm module directly (DLL-like), is it sufficient to use wasm32-freestanding or does sokol always require the intermediate emscripten step (and hence the build.zig template here) for the EM_JS() stuff you mentioned in another thread?

floooh commented 6 months ago

@kkukshtel yeah, you'll need to compile the sokol C library as wasm32-emscripten, and link the final executable (or WASM 'DLL' I guess) with the Emscripten linker.

Decoupling the sokol headers from Emscripten is currently not feasable unfortunately (since even without the use of EM_JS, it would require writing our own browser API shims and/or parts of the Emscripten helper functions).