Hello, I am currently binding an ultra portable C library called KinC ( Kore in C https://github.com/Kode/Kinc ) to Nim. It has a nice build system that I am trying to reuse with Nim ( why reinvent the wheel ? ) ( Kincmake https://github.com/Kode/kincmake )
My initial implementation involves some dirty defines which works when i link against the generated DLL:
when defined(windows):
const libName* = "Kinc.dll"
when defined(Direct3D11):
import ../../../Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/indexbuffer
when defined(Direct3D12):
import ../../../Backends/Graphics4/Direct3D12/Sources/kinc/backend/graphics4/indexbuffer
when defined(OpenGL):
import ../../../Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/indexbuffer
proc kinc_g4_shader_init*(shader: ptr kinc_g4_shader_t; data: pointer; length: csize_t; `type`: kinc_g4_shader_type_t) {.
importc: "kinc_g4_shader_init", dynlib: "Kinc.dll".}
#...#
Then I build with c --define:OpenGL -o:DeploymentN/Shader -r Sources/Shader.nim
Here is a JSON representing what for example a windows/opengl build looks like ( many more systems and backends included in the lib ): https://pastebin.com/zYXNgE3k
The build includes some directories where the abstracted Kinc API calls into the included backends implementations. Kind of like what I am emulating with my "when defined()" but it will get messy with all the OSs and GraphicsAPIs.
It's currently tested with OpenGL and DirectX on Win10 and OpenGL on Linux.
Here's the stuff: https://drive.google.com/drive/folders/1d2TSgbGnPEd8gXvzcNSYXNVcZcnZDoXh?usp=sharing
I didn't bother to make a repo yet.
If anyone has any suggestions as to how I can do this better in Nim because right now I would have to write a lot of when defined() almost everywhere in my code, which I don't mind ^_^.
Yardanico suggested i use PassC.
maybe thats the better option?
-d:OpenGL
--passC:"-I /home/dian/Stuff/kinctest/Shader-Kinc_new/Kinc/Sources/"
--passC:"-I /home/dian/Stuff/kinctest/Shader-Kinc_new/Kinc/Backends/Graphics4/OpenGL/Sources"
i figured it out by using nimscript
switch("path", "path/to/dir/")
I read the docs about the --path switch but I'm experiencing something weird in my project.
I have two graphics backends with multiple Nim binding modules and also two DLLs.
The plan is to tell nim which backend to use by using the --path switch while also switching to the appropriate DLL.
Currently I have Direct3D11 DLL and OpenGL DLL with these path switches in a nimscript:
#switch("path","../Kinc/Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4")
switch("path","../Kinc/Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4")
The problem is when I have the Direct3D11 path switch in my nimscript, i can freely switch between the OpenGL DLL and the Direct3D11 DLL and somehow Nim includes the correct Nim modules whereas when I switch to the OpenGL path, Nim suddenly crashes.
Can someone explain to me how Nim finds paths?
nimscript
switch("define","dx11")
#switch("define","ogl")
for each module:
when defined(dx11):
import ../../../Backends/Graphics4/Direct3D11/Sources/kinc/backend/graphics4/kni/indexbuffer
elif defined(ogl):
import ../../../Backends/Graphics4/OpenGL/Sources/kinc/backend/graphics4/kni/indexbuffer
if i --define:ogl it builds but crashes no matter what dll i use
if i --define:dx11 it always works for both dx11.dll and ogl.dll
i literally just replace the dll and it always works with the dx11 define.
can someone please explain?