-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Get hello world compiling for iOS #5145
Comments
Compiling a debug build (the default) has safety features enabled, and many of these things are OS specific. If you want to make good use of zig's runtime safety features, someone would have to implement these for IOS. Large areas of the standard library as a whole likely won't be available yet. For now, I think IOS will work in release fast and release small (providing you can avoid using a lot of the standard library). |
Both release-fast and release-small seem to fail with the same error. Am I doing something wrong?
|
The |
So far my src/main.zig file (the only one I have besides the build.zig) is the following:
I even tried this because I thought std.debug could be the issue:
but the error is still the same. |
wait..... why is ios different to darwin? they're the same kernel |
@daurnimator yes it is the same kernel. But if I add
|
The one above
I forgot to put back the |
@LemonBoy hah! now that's clear :) Ok, then I have one more question regarding compiling for iOS. Let's assume that:
Would it be possible to provide to Zig a list of folders with the source code of SDL2 and the like and write a build.zig script that compiles all of them with the correct inclusion files and the correct switches for clang and also for the Obj-C files? |
@tanis2000 you're prolly gonna need to dive into this, update SDL and add iOS to the build script: https://github.com/andrewrk/zig-sdl |
Yes, and you can see a proof-of-concept here: https://github.com/andrewrk/zig-sdl |
I guess this issue can be closed. A simple hello-world compiles just fine.
|
@SebastianKeller we can close the original issue but I will open a new one for what concerns SDL2 as that's not yet been fixed |
@SebastianKeller, @tanis2000, is the code that compiles in the above example expected to run correctly on the iOS simulator? Is zig's c standard library code correct for iOS? I dropped the compiled binary into a test app bundle and installed the bundle into the simulator. Using lldb to wait for the process to start and then break also fails: the debugger errors out that it is unable to connect to the process. Let me know if you need the detailed steps I followed. |
@coolbluewater I'm a bit confused. Could you please provide more information on 'dropped the binary into an app'? Besides, the simulator runs in x86. The devices run in arm. A more common usecase would be to write a zig-library, export c headers and link the static library. You then call the zig-lib using the c-header. |
:) It helps my learning to create a simple app in zig without depending on Swift or Objective-C. In a real world app your use case is more appropriate.
Ah yes, I used the x86_64-ios target instead. I will provide more details if you can confirm that this target should work. |
Alright. Good luck then. |
Here are the steps:
|
So you think that the x86_64-ios target should work correctly? |
The binary runs on the simulator.
My guess is that the .app-Container is somehow not correct. |
@coolbluewater this is not how you create an iOS app. You can't just create a binary that has a main function entrypoint and pretend it will work without instantiating the UIAppDelegate. As @SebastianKeller pointed out, you should create a library and then import that into your iOS project. This is the easiest approach. BTW we should just close this issue as the original problem has been solved and we're talking about a different issue now. |
@SebastianKeller, thanks.
According to the iOS docs for the app launch sequence, there's nothing special about the UIAppDelegate. It just so happens that that's what the Xcode-supplied main() function (in an Xcode-generated project) winds up creating. But it should certainly call our main() function, which just logs a string and exits. That's the barest stub of functionality I'm looking for at this point. |
@SebastianKeller, Any idea what might be causing this? I'm running zig 0.7.1 and the simulator is iOS 14.3. |
@g-w1, Thanks that would explain it. As a zig newbie, are builds of master available to install? |
They are avaliable on the download page.
…On Wed Feb 3, 2021 at 2:33 PM, coolbluewater wrote:
@g-w1, Thanks that would explain it. As a zig newbie, are builds of
master available to install?
If not, I'll compile from source, a good way to learn the system.
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#5145 (comment)
|
@g-w1, @SebastianKeller - thanks all. Will report back. |
@SebastianKeller, running But running the .app bundle doesn't seem to produce any output in Console. Investigating. |
Update: while I'm still unable to find where the "Hello, world" got written to, adding this worked:
Now Console shows |
hmm... don't app launchers close file handles 0,1,2 and force use of logging api ... and console.app can read? |
@mikdusan, you're probably correct. Now trying to use os_log. What is the zig equivalent of Objective-C's I tried Edit: Think I may need to create an objective-C library with that exposes functionality to zig via the C ABI. Also opened #7944 to discuss whether Objective-C frameworks can be supported more directly in zig. |
If you want to include the c library you probably want const c = @cImport({
@cInclude("os/log.h");
}); |
@g-w1, unfortunately that doesn't work. |
@coolbluewater my buddy Bill just did some writing to the iOS console yesterday for us testing a Zig build (using the iOS SDK still). He used |
I'm just figuring out at what point in time you are with iOS support for Zig. I tried to compile the basic project that you get when you initialize a new Zig project with the following command:
And I get the following error:
Does that mean that iOS is not supported at all or is there anything I could do to help adding support for that platform?
The text was updated successfully, but these errors were encountered: