Making a high level raylib binding with Swift for a game engine; does Swift PM support C linking?

Title says it all. So I already built Raylib on my machine with cmake and I just ideally want to take the headers from that repo and the dynamic libs .so (for my Linux machine, I expect for windows I will build for .dll?) My only major pain point has always been the PM. I find it kind of lackingly documented for using with C. Regardless, I have no idea what I am doing other then I just want to make a high level game engine with Swift and using that C base.

Otherwise, I have a pretty high level project next to it for my actual swift game and engine, but I wouldn't even know if implementing the Package.swift needs some higher magic with C headers/source...

Plus, I love swift, so I really, really want to make this work cross platform.
Sorry if that is open ended and alot, please be patient with me.

2 Likes

You could check out how the Raylib for Swift project does it!

1 Like

I am going to pretend this wasnt the obvious solution, so basically to go over this.

  • Swift supports Package.swift using conditional compilation with #if-platform(os) and end so I can just pick and choose the raylib files per platform? Does this work say, if I made my own Vulkan and I Would have to go "well you should work on Windows and Linux, but for Apple I Will have to turn that SPIR-V to Metal" (purely an example btw, just wanted to probe the features I can use)
  • The linker settings is an array variable for C and CXxx, I also found this documentation clearing that up I believe
  • Package — Swift Package Manager
  • Finally, so other then linking and sort of mapping our files from say C/C++/Objective C.... the Package.swift will build so long as the structure of the file-tree parses correctly? Because for better or worse, I just ripped that old Package file and it builds fine. Trying to replicate it in another, blank project and that builds fine too.

Anyway, sorry if this is not your wheel house and it took a while. I am currently sort of manually grepping, see what I can do. And since I want to write my own swift packages and import them here, I sort of just want to make it all work best I can.
But basically, the Package.swift is a series of arrays/map, with various conditional compilation options with # and using linker settings with [CSettings], as an example for my use case. Are there other C bindings that Swift has I can clone and study?