greenfork / nimraylib_now

The Ultimate Raylib gaming library wrapper for Nim
MIT License
149 stars 16 forks source link

flag for static linking? #13

Closed balenamiaa closed 3 years ago

balenamiaa commented 3 years ago

Would it make sense to have a compile flag for linking with a specified static library instead of a shared library? I tried

dynlibOverride:raylib
passL %= "~/git_clones/raylib/src/libraylib.a"

but that didn't seem to help. My aim is to link with raylib compiled for the web using emscripten.

greenfork commented 3 years ago

Would it make sense to have a compile flag for linking with a specified static library instead of a shared library?

My understanding is that you will have to manually compile raylib source together with your nim program. From this wiki article it requires some CMake options.

All the linking is done here, so you could probably just try different options in that nim file. I am very unsure how to make it work properly with static linking and emscripten too, as far as I know you would also need some nim magic. So far just static linking seemed to work with the exception that I still had dependency on libc, but I don't remember exact steps. Probably directly editing the file is the best option for now.

balenamiaa commented 3 years ago

I built a static library of raylib compiled for the web following the guide on raylib's repo, then changed {.passL:"-lraylib".} to {.passL:"/path/to/staticlibrary".}, and did a few changes to the window main loop for emscripten. It worked with no problem.

What I meant was if it's possible to somehow ignore the {.passL:"-lraylib".} without modifying nimraylib_now, and instead link on my own?

Dependency on libc isn't a problem as the emscripten compiler handles that(, and glfw which raylib uses under the hood), but it doesn't handle arbitrary libraries like raylib.

greenfork commented 3 years ago

What I meant was if it's possible to somehow ignore the {.passL:"-lraylib".} without modifying nimraylib_now, and instead link on my own?

I'm not sure it is possible. --dynlibOverride will not work because raylib and other libraries are not loaded dynamically with dynlib, but statically with header, you can see pragmas here (and to avoid ambiguities, it is separate from dynamic/static linking, those 2 options exist for dynamic linking). And I don't know if there's an option to override all past passL options for gcc llvm or whatever linker is used.

Do I understand correctly that the only thing you did was "changed {.passL:"-lraylib".} to {.passL:"/path/to/staticlibrary".}" inside this library and then "did a few changes to the window main loop" inside your game code? If so, we can introduce a custom flag to override all the passL things.

balenamiaa commented 3 years ago

I tried it from fresh and yes that's all that was needed. https://github.com/balenamiaa/nimraylib_now_wasm.git is a working example, demo I compiled it with the following in my case: nim c -d:wasm="/home/tbalen/git_clones/raylib/src/libraylib.a" raylib_wasm.nim; the rest is handled by compiler options set in config.nims

greenfork commented 3 years ago

@balenamiaa I added emscripten support. Could you check out this example and see if it works for you?

Also pushed new tag and release https://github.com/greenfork/nimraylib_now/releases/tag/v0.10.0

greenfork commented 3 years ago

@balenamiaa hi, there's another release https://github.com/greenfork/nimraylib_now/releases/tag/v0.12.0

You can still check out this this example. Main change - library is compiled for you, you shouldn't have to do anything manually. Just use config.nims file in the example.

greenfork commented 3 years ago

@balenamiaa sorry for too many updates, I finally fixed this library and everything promised above should work now

balenamiaa commented 3 years ago

No, it's alright :). The example for emscripten works for me just fine, good job!