-
Notifications
You must be signed in to change notification settings - Fork 498
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
Bindgen: D language #955
Bindgen: D language #955
Conversation
Wow interesting! I don't know yet whether I will merge before new year because I'm currently back in retro-land and I want to take time to test the bindings (which means getting at least a bit familiar with the D language and toolchain), but I'm definitely interested to make this "official". PS: would be nice to have a handful samples in the bindings repository, like in the other bindings :) |
PS: please ignore the CI pipeline errors for now, the Emscripten error is caused by a Clang update (they have a new warning), and the error in the gen-bindings job needs to be fixed in the github actions script (I think). |
I'm working on the examples and the cross-compiling easy using zig as a reference. WiP$> zig build debugtext_print --verbose --summary all
# Zig commands
/home/kassane/zig/0.12.0-dev.1828+225fe6ddb/files/zig build-lib -cflags -DIMPL -DSOKOL_GLCORE33 -DSOKOL_DISABLE_WAYLAND -- /home/kassane/sokol-d/src/sokol/c/sokol_log.c -cflags -DIMPL -DSOKOL_GLCORE33 -DSOKOL_DISABLE_WAYLAND -- /home/kassane/sokol-d/src/sokol/c/sokol_app.c -cflags -DIMPL -DSOKOL_GLCORE33 -DSOKOL_DISABLE_WAYLAND -- /home/kassane/sokol-d/src/sokol/c/sokol_gfx.c -cflags -DIMPL -DSOKOL_GLCORE33 -DSOKOL_DISABLE_WAYLAND -- /home/kassane/sokol-d/src/sokol/c/sokol_glue.c -cflags -DIMPL -DSOKOL_GLCORE33 -DSOKOL_DISABLE_WAYLAND -- /home/kassane/sokol-d/src/sokol/c/sokol_time.c -cflags -DIMPL -DSOKOL_GLCORE33 -DSOKOL_DISABLE_WAYLAND -- /home/kassane/sokol-d/src/sokol/c/sokol_audio.c -cflags -DIMPL -DSOKOL_GLCORE33 -DSOKOL_DISABLE_WAYLAND -- /home/kassane/sokol-d/src/sokol/c/sokol_gl.c -cflags -DIMPL -DSOKOL_GLCORE33 -DSOKOL_DISABLE_WAYLAND -- /home/kassane/sokol-d/src/sokol/c/sokol_debugtext.c -cflags -DIMPL -DSOKOL_GLCORE33 -DSOKOL_DISABLE_WAYLAND -- /home/kassane/sokol-d/src/sokol/c/sokol_shape.c -lasound -lGL -lX11 -lXi -lXcursor -lc --cache-dir /home/kassane/sokol-d/zig-cache --global-cache-dir /home/kassane/.cache/zig --name sokol -static -fcompiler-rt -fPIE --listen=-
# LDC (LLVM D Compiler commands) based on libsokol config
/usr/bin/ldc2 -d-debug --gc -g --O0 -w --wo --vcolumns -od=/home/kassane/sokol-d/zig-cache/o/4030eb13042ae0eaeb90332d5358ac3e --oq --Hkeep-all-bodies -I/home/kassane/sokol-d/src/sokol /home/kassane/sokol-d/src/sokol/app.d /home/kassane/sokol-d/src/sokol/audio.d /home/kassane/sokol-d/src/sokol/gl.d /home/kassane/sokol-d/src/sokol/gfx.d /home/kassane/sokol-d/src/sokol/glue.d /home/kassane/sokol-d/src/sokol/log.d /home/kassane/sokol-d/src/sokol/shape.d /home/kassane/sokol-d/src/sokol/time.d /home/kassane/sokol-d/src/sokol/debugtext.d /home/kassane/sokol-d/src/examples/debugtext_print.d -L-L/home/kassane/sokol-d/zig-out/lib -L-lsokol -L-lasound -L-lGL -L-lX11 -L-lXi -L-lXcursor --Xcc=-DIMPL --Xcc=-DSOKOL_GLCORE33 --Xcc=-DSOKOL_DISABLE_WAYLAND --Xcc=-DIMPL --Xcc=-DSOKOL_GLCORE33 --Xcc=-DSOKOL_DISABLE_WAYLAND --Xcc=-DIMPL --Xcc=-DSOKOL_GLCORE33 --Xcc=-DSOKOL_DISABLE_WAYLAND --Xcc=-DIMPL --Xcc=-DSOKOL_GLCORE33 --Xcc=-DSOKOL_DISABLE_WAYLAND --Xcc=-DIMPL --Xcc=-DSOKOL_GLCORE33 --Xcc=-DSOKOL_DISABLE_WAYLAND --Xcc=-DIMPL --Xcc=-DSOKOL_GLCORE33 --Xcc=-DSOKOL_DISABLE_WAYLAND --Xcc=-DIMPL --Xcc=-DSOKOL_GLCORE33 --Xcc=-DSOKOL_DISABLE_WAYLAND --Xcc=-DIMPL --Xcc=-DSOKOL_GLCORE33 --Xcc=-DSOKOL_DISABLE_WAYLAND --Xcc=-DIMPL --Xcc=-DSOKOL_GLCORE33 --Xcc=-DSOKOL_DISABLE_WAYLAND --Xcc=-DSOKOL_GLCORE33 --mtriple=x86_64-linux-gnu --mcpu=znver3 --of=/home/kassane/sokol-d/zig-out/bin/debugtext_print
Build Summary: 5/5 steps succeeded
debugtext_print success
└─ run /usr/bin/ldc2 success 819ms MaxRSS:291M
└─ install success
└─ install sokol success
└─ zig build-lib sokol Debug native success 852ms MaxRSS:118M |
Some examples are added.
Having completed some initial tests with the added (functional) examples, bindgen will be enhanced according to the configurations of the ported examples. Currently, the main issue facing me is mangling (D ABI by default) where some generated functions ( especially the logger) need |
Ported!! WiP After porting some zig/rust examples to D, I still didn't get a satisfactory result. I am evaluating the issue of structs and memory layout on the part of D, even in BetterC mode and using References |
Is it a good time for me to start looking into the PR already, or should I wait a bit (and pick another topic in the meantime)? |
Feel free to review it! |
The sokol-d project repository is not available in CI/CD! |
Hmm, testing on my M1 Mac with ldc2 I'm seeing a couple of weird issues: Warnings like this:
...it's interesting that debugtext_print.o stands out and this is the sample that fails with an assertion. Each sample has strange behaviour:
I'll try to come up with a way to debug via VSCode. Should I use a different platform for testing for now? In the meantime though I will fix the sokol-zig build files for the latest zig build system changes ;) |
What flags were used? Any errors by the target will include the flags renamed by zig to ldc2/ldmd2. If possible, share in the sokol-d issue the output of this in verbose. |
Hmm, I was just running If you haven't tested macOS so far then it's not all that surprising though. I will check on my Windows and Linux machine next (probably on Monday when I'm back in Berlin, and I can also check on my old Intel Mac there). We can figure out what the problem is on M1 Macs later :) |
After some changes to
Nice! I made some improvements regarding support for MacOS and Windows. |
There will be no more auto-generation of helper functions. Providing these conversions will be the responsibility of the user. |
Now, solved NaN init issues! (debugtext_print and sgl_context fixed) |
Finally CI (gen d binding added) ✔️ |
For initial support, this solution already works. Waiting for your review! -- Edit Any corrections and improvements will be handled by sokol-d directly, since I haven't yet identified a reason from bindgen. |
Ok, I'll start looking into this again now. |
Did you get debugging to work somewhow? I'm trying this extension on macOS: https://marketplace.visualstudio.com/items?itemName=webfreak.code-d, and while it starts the debuggee, it doesn't stop on breakpoints. (I'm using the ldc debugger on macOS btw via |
On Linux I'm getting tons of errors like this:
...with this ldc version:
...on macOS the ldc2 version is slightly more recent:
|
...on Ubuntu with ldc2 version 1.30.0, if I remove the All samples that render directly via D code are blank (which could mean that something about shaders or the shader-desc is off). The samples which render indirectly through other sokol headers (e.g. sokol_debugtext.h or sokol_gl.h) seem to render fine. This is on Ubuntu though, on macOS all samples are either blank or crash outright. |
Currently I use lldb extension to debug in vscode. For |
The scope only becomes impactful for those who use the TLS and GC warnings are intentional in debug mode only. Flags: Any allocation (dynArray or assocArray/HashMap) requires GC (stdlib phobos2 requires GC on almost everything, except
This would justify the absence of rendering.
Some examples for me, worked on archlinux, windows11, and wasm32-emscripten (for D is freestanding). |
Zig prefers native compilation on the host target, unlike other compilers. if (options.target.query.isNative())
try cmds.append(b.fmt("-mcpu={s}", .{builtin.cpu.model.name})); Or need rename, like $> zig build-obj -target aarch64-macos -mcpu= --show-builtin
info: available CPUs for architecture 'aarch64':
[...]
apple_a10
apple_a11
apple_a12
apple_a13
apple_a14 # HERE
apple_a15
apple_a16
[...]
# like clang output (replacing `-mtriple=arm64-apple` to `-target aarch64`)
$> ldc2 -mtriple=arm64-apple -mcpu=help
Targeting aarch64. Available CPUs for this target:
[...]
apple-a10 - Select the apple-a10 processor.
apple-a11 - Select the apple-a11 processor.
apple-a12 - Select the apple-a12 processor.
apple-a13 - Select the apple-a13 processor.
apple-a14 - Select the apple-a14 processor. # HERE
apple-a15 - Select the apple-a15 processor.
apple-a16 - Select the apple-a16 processor.
[...]
apple-m1 - Select the apple-m1 processor.
[...] |
Well, remembering that this implementation was still in wip, this is really a problem that is still an open issue. |
Some improvements and fixes * gen-d: remove semicolon (enum/struct) * remove Range_struct duplicate * add module name * fix: replace C in all file to C functions only * scope c_str return to D * fix format * exter(C) in funcptr * Drt/betterC compat * remove helper functions (auto-generated) by @ryuukk * C functions: `@system` to `@trusted` nothrow @nogc * D strings conversion * fix Cstr * C void_ptr * D ref added on func_arg_type * CI/CD sokol-d added
Note: I'm going to put a 'scope' in front of all pointer and ref params in my merge-thread, that way the init() function in the samples doesn't need a |
This is my local 'merge-branch' btw: https://github.com/floooh/sokol/tree/kassane-dlang_bindgen |
Merge your minor fixes... |
Ok, so just to clarify :)
Let me know if that makes sense and I'll do the merge :) PS: We'll have to see how the above model works when there are breaking changes to the sokol headers and the examples in the bindings need to be updated, in this case I usually create a number of related PRs for the language bindings which then need to be merged right before the sokol main repository is merged. But for smaller things I guess I can handle those myself without requiring actions from your side (when in doubt I'll wait for your approval though). |
Ok, brace for impact :D |
...and merged. Next I'll check if the bindings CI pipeline works: https://github.com/floooh/sokol/actions/runs/9064596060 ...then I'll update the changelog and announce the new bindings. Thanks for the hard work and apologies for the long delay. |
...and failed :D https://github.com/floooh/sokol/actions/runs/9064596060/job/24903528985 ...but I know why, I need to setup an access token in both repositories, one sec, let me check if I can do this on my own. |
Ok, I need to figure out again how this works :D But I definitely need your help because I don't have access to the Github settings of https://github.com/kassane/sokol-d (we'll need to add a deploy key there). This also involves creating an ssh public/private key pair, I just need to figure out again where the public and pivate key goes, and whether you or me need to create the key pair, one sec... |
Hmm ok interesting, looks like the public key goes into the deploy key of the target repository... @kassane can you do the following please:
Meanwhile on my side in the sokol repository I will add the private key part as the missing |
@floooh done. |
Ok thanks, let's see what happens when I restart the pipeline... |
Ok it worked :) This is the commit: kassane/sokol-d@0b2587f (these are the WebGPU changes I merged earlier today) Ok, then I'll add the bindings link and badge to the readme, add a changelog item and do an announcement. |
Based on
gen_zig.py
.Result: https://github.com/kassane/sokol-d (unofficial)
Note: I will archive my repository if there is interest in official support.
Reference
sokol-d: initial support sokol-tools#115cc: @floooh