Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: is it possible to write GUI applications? #4

Open
hronro opened this issue Aug 22, 2022 · 1 comment
Open

Question: is it possible to write GUI applications? #4

hronro opened this issue Aug 22, 2022 · 1 comment

Comments

@hronro
Copy link

hronro commented Aug 22, 2022

I don't have much experience on Cocoa nor Objective-C, just wonder if it's possible to write native macOS GUI apps in Zig?

@hippietrail
Copy link

I have this exact question. I want to be able to program both native Win32 and native MacOS apps in any/all of the new batch of languages. Whichever can do it best/first out of Rust, Kotlin Native, Swift, and Zig. But Zig is the one I really want and expect to be able to do it especially since it can cross-compile across all the major platforms.

My understanding is that MacOS is harder than Win32 because of the Objective C runtime which must be used for interacting with Cocoa/Foundation even in the age of Swift, and that the Objective C runtime does things that can't be done in C for its "message passing". When you program MacOS in C there are key functions for calling Objective C APIs such as objc_getClass() and objc_msgSend(). But though they look like wrapper functions for FFI they are in fact some kind of trampoline IIRC that jump to the API code rather than calling it like in a normal language because of how the stack is used. They involve something called IMP and SEL. Apparently implementing variadic functions is especially tricky.

I believe Apple uses assembly for these stubs but maybe they get Clang/LLVM to just emit the correct opcodes to do that stuff directly. This is a very difficult subject to read up on due to not many low-level technical people in the MacOS world seemingly, and what is there is old and so quite possibly out of date.

Apple does provide the source code to the Objective C runtime though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants