raylib-go without cgo (dynamic loading) #306
Replies: 1 comment 7 replies
-
The only viable option for removing cgo seems to be on Windows, where the code to load the dynamic library is in the kernel and not in the libC. The purego without the structs looks like it would be a real pain. Anyway, if ever done, purego says it can be also used for Windows, so then I would not see a point in having a different code base just for Windows. It would also remove so many options, we would need one .dll/.so file for every combination, i.e., one for SDL, one for DRM, Wayland, and what about OpenGL versions, etc., or if you want to override something in config.h, etc. Currently having C code included in the repo has many advantages. On the other hand, without cgo, I guess building for Web platform should be possible in theory, now that would be very nice. There is also one more possible way, to compile raylib library to |
Beta Was this translation helpful? Give feedback.
-
With the
syscall
package in go's standard library orgolang.org/x/sys
it is already possible to dynamically load libraries without cgo.Works kinda like this: https://learn.microsoft.com/en-us/windows/win32/dlls/using-run-time-dynamic-linking
Here is a small example, of just displaying a white window:
For Linux and MacOS there is a project called "purego": https://github.com/ebitengine/purego
But sadly structs are not supported in purego.
As a workaround you could write wrapper functions or try to get libffi working: ebitengine/purego#88 (comment)
Using dynamic loading would reduce build times and enable cross compiling without any third party c-compiler.
So what do you think?
Beta Was this translation helpful? Give feedback.
All reactions