logoalt Hacker News

Testing the Swift C compatibility with Raylib (+WASM)

43 pointsby LucidLynxlast Sunday at 1:47 PM16 commentsview on HN

Comments

enbuggertoday at 4:26 PM

> So, if you want to build games using raylib, why not learn learning or use Swift for that?

Never ever worked for me. Imagine, you actually learned basic Swift and Raylib, now you want "advanced" features in your game like navigation/pathfinding, model loading, ImGui, skeletal animation (those are actually vital for gamedev). You realize that

- Navigation is only ReCast which is pure C++ library,

- ImGui has C++ API as first-class citizen,

- Decent animation with compression is only open-sourced by OzzAnimation which is pure C++ project.

For gamedev interfacing with C is never enough, half of ecosystem is built heavily on C++. Even C++ interop is not enough (see Dlang). Without all those libraries you are bound to make boring 2d platformers.

Same for Zig, Odin, C3 etc.

show 1 reply
leecommamichaeltoday at 5:33 PM

> So, if you want to build games using raylib, why not learn learning or use Swift for that?

Because Apple won't fix Swift's abysmal compile times, and there are languages with similar or better ergonomics without that flaw.

show 1 reply
acarettelast Sunday at 1:58 PM

Thanks for sharing it!

I might be interested on how to build the WASM build more easier with Swift tools. I guess some tools exist to facilitate the final builds, but did not found it...

Do not hesitate to comment if someone experienced this before.

keldaristoday at 4:13 PM

Out of curiosity, how does the size and performance of the generated WASM compare to just compiling the same Raylib example from the equivalent C code via Emscripten? In other words, how much overhead does the choice to use Swift add here or in general?

flohofwoetoday at 4:23 PM

Raylib has a C API though, and this is 'easy-mode' in any language (even without integrated bindings generation like Swift or Zig have - e.g. it's fairly trivial to write a bindings generator that uses Clang's ast-dump json file format as input and translates the API declarations into another language.

A more interesting question would be how well the C++ interoperability works that was added in Swift 5.9, does it work with all C++ headers, even headers that make extensive use of template code. Also how does Swift extract information needed for lifetime tracking, e.g. C++ APIs that return smart pointers and object lifetime ends on the caller's side. Does this only work for C++ stdlib smart pointer types, or are custom types also supported.

show 2 replies