![]() Zig has a handy template for creating a static library project. That said, before we even open Xcode, we first need to make sure we know what to do on the Zig side of things. This is nice because it means that we can have a separate build step that builds the Zig code into a static library, and then we just need to make sure that the linker knows about it. Swift can refer to C symbol definitions put in a special header file and have those symbols be resolved at link time. That's good to know, but it's not the full story because we also have to think about the compilation process. ![]() Swift can't call Zig functions directly, but it can call functions that respect the C ABI and Zig can export functions (and types) that respect it. In our case, we'll start with a much more humble example and work our way up. The best example of this are video games: when your app doesn't really have any native GUI element to it and it's just a 3D rendering canvas, then there's no point in trying to rewrite it for no gains and potentially worse performance. The main reason one might want to run Zig on iOS is because you have Zig code that you can't (or don't want) to rewrite to Swift code. On iOS it's much easier to use Swift or ObjC than any other language, this is not a secret. ![]() The goal here is not just to have Swift call into Zig code, but also to have a reasonably clean integration with the build process of our iOS application so that a single button press can build our app correctly and without doing any unnecessary work. This is a post series dedicated to integrating Zig code into an iOS SwiftUI project.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |