Swift has C interoperability, in a sense that you can call functions from C libraries in your Swift code.
How about the other way around, though?
Is it possible to make a Swift library that "pretends to be a C library" in order to call it from basically any other language?
I know that Rust can do that (via the "no mangle" macro & auto-generated header files) & I was wondering if Swift can too.
If not, why? Because of Swift's runtime? Or because of the type-system? (guess that shouldn't be a problem if you only return "C types" like
cString or "simple" values like integers & floats)
Also if not: could interoperability be achieved via other means? (from a user perspective - I don't plan on going hacking on the compiler )
I've been googling & playing around with
swiftc's options like
-emit-library -static etc. but I got nowhere because I don't know what I'm doing tbh
Also I don't even know where to start learning about this stuff - from what I understand, every language "mangles" the identifier in some way & for the library to "look" like C to other language it needs to "mangle" the id's in "the C way" (hence Rust's "no mangle" macro)
EDIT no. 2:
Of course, I'm not the only one asking this question & it is possible... not stable though: