Not-Nik / raylib-zig

Manually tweaked, auto-generated raylib bindings for zig. https://github.com/raysan5/raylib
MIT License
473 stars 101 forks source link

Offer to help: raygui support #38

Closed jdoleary closed 11 months ago

jdoleary commented 1 year ago

Hi, I'd love to help add support for raygui bindings to this repo.

I'm quite new to zig but making progress quickly. I got raygui working in a fork of this repo. If you're in the raylib discord you can see my results here:

I think my first attempt isn't idiomatic but it works. As you can see in the above link, I had to import raylib again in order to get the raygui import working, so I'm sure there's a better way than what I did.

const c = @cImport({
    @cInclude("raylib.h");
    @cDefine("RAYGUI_IMPLEMENTATION", {});
    @cInclude("raygui.h");
});

Thoughts?

raysan5 commented 1 year ago

Could it be related to being a single-file header-only library?

Oh, sorry, I didn't read fully the explanation, I thought it was not working...

Not-Nik commented 1 year ago

Zig allows for setting C defines in the build script, so maybe we could look into that?

jdoleary commented 1 year ago

Zig allows for setting C defines in the build script, so maybe we could look into that?

I will look into this!

jdoleary commented 1 year ago

I was successfully able to define RAYGUI_IMPLEMENTATION in build.zig with the following: exe.defineCMacroRaw("RAYGUI_IMPLEMENTATION");

However, I'm still working on getting the raygui.h to be added in build.zig. The way that raylib is added to the build doesn't seem to apply to a header-only library like raygui.h because I can't invoke raylib.addCSourceFiles on a .h file. I assumed adding raygui as a static library and adding the include path would be sufficient but it is not and I am getting error: lld-link: undefined symbol: GuiButton even though I've defined the extern fn in a new zig file and added raygui.h as a static library. This makes me suspect the build isn't parsing the raygui.h file. I will continue to post here as I make progress for posterity.

Not-Nik commented 1 year ago

You probably need to add an extra C file that includes raygui, so the functions actually get compiled

jdoleary commented 1 year ago

You probably need to add an extra C file that includes raygui, so the functions actually get compiled

I tried this to no avail. I've uploaded a PR with my attempt: https://github.com/Not-Nik/raylib-zig/pull/39/files in case you want to take a look. I'm still working on it and I can tell I'm getting closer but it's just not there yet.

jdoleary commented 11 months ago

https://github.com/Not-Nik/raylib-zig/pull/39#issuecomment-1646580664