-
Notifications
You must be signed in to change notification settings - Fork 48
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
wasm support and zig-0.12.0 fixes #50
Conversation
I only skimmed the changes so far (will try to take some time to actually understand it later). But in the meantime: Some of those changes might overlap with the changes I did for the sokol module in the package branch: Lines 88 to 114 in 2a0d82e
...this basically just expects that a --sysroot parameter is provided when the project is built for wasm which points into the Emscripten SDK and sets up a required header search path and C define for building the sokol module. ...the build.zig doesn't directly allow to build the samples as wasm though (as this requires more work to use emcc as the linker), I've only done this in the pacman.zig repository in the package branch: PS: also note this workaround around a package manager issue, not sure if that's fixed yet: PPS: also see: |
wow! I'll analyze the suggestion and adjust with the new zig update which breaks the previous build. |
My suggestion
from: Lines 18 to 26 in 2a0d82e
Lines 106 to 109 in 2a0d82e
to: Lines 19 to 34 in e176d2b
Lines 231 to 237 in e176d2b
|
Phew, FYI I just fixed build.zig for the latest build system changes in the nightly version (in a new branch zig-0.12.0): https://github.com/floooh/sokol-zig/tree/zig-0.12.0 I started this branch with the sokol-package branch, so that at least there won't be two version (package and non-package) from there on. This is getting a bit messy with the wasm changes on top, I hope the build system APIs stabilize a bit better soon-ish. |
Amazing!! 👍
I also hope! Because right now, I was looking into a new issue in sokol-d for windows-msvc target. Since the latest zig update |
0cebc28
to
71335db
Compare
Rebased on branch: |
FYI I think I will spend the next couple of days with a couple of fixes: I had started a zig-0.12.0 branch in sokol-zig which has been updated to the latest zig build system API changes (I'm not happy with some changes I did, and will use some of your changes which make more sense, like I think I will just merge the current master branch back into zig-0.11.0 and treat this as the stable target for people using zig 0.11.x, and instead merge zig-0.12.0 into master (meaning the sokol-zig master branch would be "bleeding edge"). This also means that the sokol-zig master becomes 'package-capable', and I will move the master branches of my example/test projects pacman.zig and kc85.zig to also use the package manager. I'll keep working on the zig-0.12.0 branch until everything is ready. I'll only do minimal changes to the already existing wasm support and try not to interfere too much with your wip changes :) PS: while at it, I will also check if some of the package-manager related workarounds in pacman.zig are actually still needed. |
PPS: One question that popped into my mind... I wonder if it makes sense to split the examples into a separate build.zig (maybe in a subdirectory). For instance adding Emscripten/WASM build support for the samples adds a lot more stuff to the root build.zig which wouldn't be needed for the sokol package alone. Thoughts? |
Redesigning the new api is pretty tedious, besides looking more verbose. Thoughts?
That could be! However, this reorganization of build module would require a more complete configuration of emscripten. Something similar here, perhaps: |
In case of sokol, emcc will need to do the linking, because the sokol C sources use Emscripten-specific magic like embedded Javascript snippets via EM_JS() which need special handling in the linker step. Also the output must not just be a .wasm file, but also a .html and .js file. For just compiling the sokol static link library, the Zig compiler is sufficient (with the So one way or another, if we want to have the sokol-zig examples built out of the box (for wasm), we need to be able to call To just build the sokol link library from the C sources, only a path to the Emscripten SDK sysroot is needed to provide the Emscripten C headers, but the compilation can be done by the Zig compiler. |
...wait... did you actually get it to work? |
This is pretty awesome tbh, didn't know that this works (but hoped it would):
...means I can probably do something similar with the sokol-shc compiler... |
Lines 398 to 400 in ae79928
|
All tests ✔️ \o/ |
This is totally awesome.... The clear-sample works (which means all the Emscripten stuff is working). ...for the samples which require shaders the GLES3/WebGL2 shaders seem to be missing (which figures because they are not currently in the generated shader files here: https://github.com/floooh/sokol-zig/tree/master/src/examples/shaders, and the args here: Line 248 in 24134d5
...need to be extended like this:
(maybe also We should also replace that ugly Emscripten default webpage which our own shell.html... but that's also no show stopper for the merge, I can take care of this polishing stuff... In any case, I will abandon my wip work on pacman.zig and kc85.zig and focus on this MR first. Good stuff :) |
...not today though (but expect some potential review feedback bits and pieces over the next few days). |
You can update the package using the command: # (over)write [zon] with new commit hash pkg
>$ zig fetch --save=emsdk "git+https://github.com/emscripten-core/emsdk#{latest-commit-hash}"
Yeah! I was also thinking about this possibility in the sokol-d project. |
Hmm strange, I just updated the package branch with the latest changes from master, but the PR diff view still shows differences in sokol_app.h, sokol_gfx.h and sokol_log.h which shouldn't be there anymore... PS: probably a Github bug: isaacs/github#750 |
...changing base branches to update the view didn't work though hmm... |
I added a couple of code review comments / change requests. Two things are still mysterious to me:
|
Do you want to rebase to branch |
TL;DR: keep this PR based on the That was my plan yesterday, but there will be collisions with the changes I already did there (and those changes don't make sense anymore, I would like to use your branch as the "0.12.0 reference branch"). In general my plan is:
...e.g. the main branch becomes the 'bleeding edge'. Now I already started a 0.12.0 branch prematurely. It would have been better to merge your changes back into the package branch and then merge the package branch back into main, and only create a 0.12.0 branch when Zig 0.12.0 has been released. I'll check out your changes later today. After merging back into And I think I will also generally switch everything (meaning my example projects) to use the package manager approach, and declare the old way of integrating the bindings as 'deprecated' (but probably still keep it working for a while). |
Yes, ideally the PR would only affect the main.yml, build.zig and build.zig.zon file. As I said above, I'm not sure why Github even still shows changes for the .h files, since I updated the package branch yesterday, but the .h file changes that are still shown look like the PR is against an outdated version of those files... Maybe rebasing again on top |
650476d
to
0b13e25
Compare
Done! |
Yay that helped, thanks! Looking through your changes now and if I'm happy I'll merge it (but slight change of plans, I'll try to merge into a new |
Interesting, the captureStdOut trick doesn't seem to hide the emsdk output (on macOS I mean). But anyway, I'm happy with the PR as is and will merge now, and then start fixing the remaining issues (black screen samples etc...) in a branch wasm_zig-0.12.0 |
Ok merged! Slight correction: target branch name is https://github.com/floooh/sokol-zig/tree/zig-0.12.0-wasm ...I'll continue working on this until it's ready for merging into master and will keep you posted (I'll probably open a new PR where we can discuss changes if needed). |
PS: Many thanks for this awesome PR :) |
Finalize WASM and zig-0.12.0 support (see #50)
Tested
0.12.0-dev.2150+63de8a598
Steps
zon
file.emcc
andemrun
Note: This is experimental, and some examples get black screen on browser or get errors!!
Reference