electronstudio / raylib-python-cffi

Python CFFI bindings for Raylib
http://electronstudio.github.io/raylib-python-cffi
Eclipse Public License 2.0
142 stars 29 forks source link

Improve dynamic loading #34

Closed adamlwgriffiths closed 3 years ago

adamlwgriffiths commented 3 years ago

Disclosure: This uses a derivative of code I write for raylib-py today (https://github.com/overdev/raylib-py/pull/31).

Support searching for the raylib library on multiple paths. Add a new environment variable "RAYLIB_BIN_PATH" which lets us specify the dir path to search for the library. The ability to over-ride the library path is important for operating systems like Nix. Add a new environment variable "RAYLIB_BIN_FILENAME" which lets us specify the filename to load for the library. Fix reference to raylib 3.5 (#33)

With these changes I'm able to run the "test_dynamic.py" script using Raylib 3.7.0 provided by NixOS.

adamlwgriffiths commented 3 years ago

Continuing on from the discussion in #33.

I haven't tested the static versions as I haven't tried building them. I've got my system raylib build as a shared lib, I could try and build a static version also but it would require work. I personally would prefer the dynamic version. I wasn't even aware you could run python's ffi against a static library.

I'm happy to remove the list of names and just locking it down to one.

I also suspect the RAYLIB_BIN_FILENAME may be unused. I just added it while I was there thinking someone may get use, but I suspect it's just an extra feature to maintain that no one will use. So I should remove that.

I do need the ability to use the system raylib .so though. I can rely on LD_LIBRARY_PATH, the issue is the priority of loading them. There will be people that want to load the included .so's over their systems ones, and vice versa.

I suspect the solution is:

adamlwgriffiths commented 3 years ago

Ok, I've reworked this to be far simpler.

electronstudio commented 3 years ago

I suspect the solution is:

  • Remove all the raylib .so files in the list apart from the core ones libraylib.so.

  • Load from /dynamic by default.

  • Provide an option (let's say USE_EXTERNAL_RAYLIB) that changes the directory to "" so that LD will look on the LD_LIBRARY_PATH.

cool, that sounds like the best way to do it.

adamlwgriffiths commented 3 years ago

Fantastic, thanks for rubber ducking it out!