planetis-m / naylib

Yet another raylib Nim wrapper
MIT License
209 stars 11 forks source link

Build against system raylib #118

Closed ehmry closed 2 months ago

ehmry commented 4 months ago

This makes it buildable on my machine without using the vendored raylib and avoids the hardcoded path at https://github.com/ehmry/naylib/blob/1d8b8c686167aed0bffa6cd35df590da70e6de6a/src/raylib.nim#L5

planetis-m commented 4 months ago

Thank you for this patch, I am really grateful for working on this. However I am not sure I can merge it.

First I use my own version of raylib because of the breaking changes each new version introduces. It would mean you have to regenerate the api/raylib.json, rerun tools/raylib_gen.nim and fix any errors manually. (done in update_bindings.nims)

Second the reason for the "rl" prefix of some functions, is that on windows nim includes both raylib.h and windows.h in the generated C file in random order. And these identifiers are present in both headers and cause compilation errors.

I used to patch after installation raylib.h with the mangle_names.patch on windows. But people started cross-compiling for emscripten on windows and were getting errors. Also they wanted to cross-compile on linux for windows, which can work with some changes (but currently doesn't). So I am now mangle these identifiers on all platforms. This patch also breaks after every release so it needs maintenance.

ehmry commented 4 months ago

Okay, I need dig into this more and run more tests then.

planetis-m commented 3 months ago

I've tried before using emit, but you need to place it in every module of your project that imports naylib:

{.emit: """/*INCLUDESECTION*/
#if defined(__WIN32) || defined(__WIN64)
#define WIN32_LEAN_AND_MEAN
#define Rectangle rectangle_win32
#define CloseWindow CloseWindow_win32
#define ShowCursor __imp_ShowCursor
#define _APISETSTRING_
#endif

#if defined(__WIN32) || defined(__WIN64)
#undef DrawText
#undef ShowCursor
#undef CloseWindow
#undef Rectangle
#endif
""".}

Clearly can't work.

planetis-m commented 2 months ago

Closing, reason: no response.