E-xyza / zigler

zig nifs in elixir
MIT License
763 stars 42 forks source link

Use pkg-config #339

Open CGenie opened 1 year ago

CGenie commented 1 year ago

Hello,

I'm currently using nixos for my project. The directory structure there is quite complex, eg. the proj lib is in /nix/store/2sgdzvhnmai3xsgn1f3p7p03vp3852yj-proj-9.0.0/lib/libproj.so and in fact it's a symlink to libproj.so.25 which is a symlink to libproj.so.25.9.0.0.

I noticed that zigler copies the files specified in the libs setting, so for symlinks it won't work. I also cannot specify libproj.so.25.9.0.0 in libs as I'm getting a compile error with 'invalid library file'.

To get out of this mess, I made a small test project that uses SDL2 with nix. I added sdl2 with a simple exe.linkSystemLibrary("sdl2") (apparently this uses pkg-config as described here https://zig.news/xq/zig-build-explained-part-3-1ima in the "system libraries" section).

So my question is: could zigler use pkg-config as well so that I can specify proj in libs and don't care about paths?

CGenie commented 1 year ago

Ah, ok, nvm, it seems it's possible with system_libs

https://github.com/ityonemo/zigler/blob/master/lib/zig/templates/build.zig.eex#L35

CGenie commented 1 year ago

Hm, however I'm still getting this error:

10:58:43.779 [error] loading module libElixir.Utils.Proj {:load_failed, 'Failed to load NIF library .../_build/dev/lib/utils/ebin/libElixir.Utils.Proj: \'libproj.so.25: cannot open shared object file: No such file or directory\''}

My /nix/store/2sgdzvhnmai3xsgn1f3p7p03vp3852yj-proj-9.0.0/lib directory looks like this:

total 2615
lrwxrwxrwx 1 xxx xxx      13 Jan  1  1970 libproj.so -> libproj.so.25
lrwxrwxrwx 1 xxx xxx      19 Jan  1  1970 libproj.so.25 -> libproj.so.25.9.0.0
-r-xr-xr-x 1 xxx xxx 4957392 Jan  1  1970 libproj.so.25.9.0.0
ityonemo commented 1 month ago

if you are still running into this, in the meantime, I would suggest using dlopen/dlsym directly, i have had a lot of success with this strategy.