You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
zig build-exe ./src/main.zig -target aarch64-ios
And I get the following error:
/usr/local/Cellar/zig/0.6.0_1/lib/zig/std/debug.zig:662:21: error: openSelfDebugInfo unsupported for this platform
else => @compileError("openSelfDebugInfo unsupported for this platform"),
^
Does that mean that iOS is not supported at all or is there anything I could do to help adding support for that platform?
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).
The --release-* switches won't do anything for your problem. Try adding .ios in the switch where the @compilError is, I believe the Darwin codepath works just fine on IOS too.
The --release-* switches won't do anything for your problem. Try adding .ios in the switch where the @compilError is, I believe the Darwin codepath works just fine on IOS too.
wait..... why is ios different to darwin? they're the same kernel
@daurnimator yes it is the same kernel. But if I add .ios to this switch in the std library (I believe this is the switch @LemonBoy was referring to) then it compiles:
/// TODO resources https://github.com/ziglang/zig/issues/4353
pub fn openSelfDebugInfo(allocator: *mem.Allocator) anyerror!DebugInfo {
noasync {
if (builtin.strip_debug_info)
return error.MissingDebugInfo;
if (@hasDecl(root, "os") and @hasDecl(root.os, "debug") and @hasDecl(root.os.debug, "openSelfDebugInfo")) {
return root.os.debug.openSelfDebugInfo(allocator);
}
switch (builtin.os.tag) {
.linux,
.freebsd,
.netbsd,
.dragonfly,
.macosx,
.windows,
.ios,
=> return DebugInfo.init(allocator),
else => @compileError("openSelfDebugInfo unsupported for this platform"),
}
}
}
Ok, then I have one more question regarding compiling for iOS. Let's assume that:
I have a C library that I wrote that I use to make games on all kind of platforms with.
In that library I am including SDL2 and other libraries as source code and compile them all statically into my library to make sure that I'm using the same versions that I have written my code with.
I believe that Zig has no clue about CMake files
But Zig is using clang to compile C code, so I guess it should be able to understand Obj-C code, too
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?
@prime31 I already did all of that in my own repo without all the extra stuff of that SDL repo. But I still have issues compiling for macOS, not even iOS... Actually the compiler itself is crashing: #5188
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?
@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.
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)
@mikdusan, you're probably correct. Now trying to use os_log.
What is the zig equivalent of Objective-C's#import <os/log.h>? This allows framework headers to be imported easily.
I tried const log = @import("os/log.h"); but that fails with or without the .h.
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.
@g-w1, unfortunately that doesn't work.
More detail: Apple frameworks have a known location and layout that clang uses to resolve #import <os/log.h>when parsing a source file as objective-c, but not as plain C. Since zig uses clang in plain-C mode to parse files, this mechanism isn't invoked and so the header can't be located. That's why I've opened the issue mentioned above to discuss the future of objective-C interop in zig.
@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 os_log(), which you should be able to create an extern for _os_log_internal to using this within your Zig app without needing the full SDK to build against. It was extremely helpful in our debugging yesterday (which we have working beautifully now). Man, Zig is great.
Reacted by Johnneylee Jack Rollins, Chris Heyes and Victor Malov
Activity
Sobeston commentedon Apr 23, 2020
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).
tanis2000 commentedon Apr 27, 2020
Both release-fast and release-small seem to fail with the same error. Am I doing something wrong?
LemonBoy commentedon Apr 27, 2020
The
--release-*switches won't do anything for your problem. Try adding.iosin the switch where the@compilErroris, I believe the Darwin codepath works just fine on IOS too.tanis2000 commentedon Apr 27, 2020
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.
I don't get where I should add an
.iosto a switch... which switch? :)daurnimator commentedon Apr 27, 2020
wait..... why is ios different to darwin? they're the same kernel
tanis2000 commentedon Apr 27, 2020
@daurnimator yes it is the same kernel. But if I add
.iosto this switch in the std library (I believe this is the switch @LemonBoy was referring to) then it compiles:LemonBoy commentedon Apr 27, 2020
The one above
/usr/local/Cellar/zig/0.6.0_1/lib/zig/std/debug.zig:662. I'd suggest you to fetch a copy from git to avoid modifying the homebrew copy.I forgot to put back the
.ios,.watchosand friends when I refactored the debug stuff.tanis2000 commentedon Apr 27, 2020
@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?
prime31 commentedon May 3, 2020
@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
tanis2000 commentedon May 4, 2020
@prime31 I already did all of that in my own repo without all the extra stuff of that SDL repo. But I still have issues compiling for macOS, not even iOS... Actually the compiler itself is crashing: #5188
[-]Compiling for iOS[/-][+]Get hello world compiling for iOS[/+]andrewrk commentedon May 30, 2020
Yes, and you can see a proof-of-concept here: https://github.com/andrewrk/zig-sdl
13 remaining items
coolbluewater commentedon Feb 3, 2021
@SebastianKeller,
Running the steps you listed produces
dyld: Symbol not found: __tlv_bootstrapAny idea what might be causing this? I'm running zig 0.7.1 and the simulator is iOS 14.3.
g-w1 commentedon Feb 3, 2021
The symbol is defined on master, not 0.7.1

coolbluewater commentedon Feb 3, 2021
@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.
g-w1 commentedon Feb 3, 2021
SebastianKeller commentedon Feb 3, 2021
@coolbluewater
https://ziglang.org/download/
https://ziglang.org/builds/zig-macos-x86_64-0.8.0-dev.1119+2d447b57c.tar.xz thats the version i used
coolbluewater commentedon Feb 3, 2021
@g-w1, @SebastianKeller - thanks all. Will report back.
coolbluewater commentedon Feb 3, 2021
@SebastianKeller, running
xcrun simctl spawnworks, and the output is in Terminal.But running the .app bundle doesn't seem to produce any output in Console. Investigating.
coolbluewater commentedon Feb 3, 2021
Update: while I'm still unable to find where the "Hello, world" got written to, adding this worked:
std.os.exit(1);Now Console shows
Service exited with abnormal code: 1So that's probably the first iOS app written entirely in zig with no Objective-C or Swift! :)
mikdusan commentedon Feb 3, 2021
hmm... don't app launchers close file handles 0,1,2 and force use of logging api ... and console.app can read?
coolbluewater commentedon Feb 4, 2021
@mikdusan, you're probably correct. Now trying to use os_log.
What is the zig equivalent of Objective-C's
#import <os/log.h>? This allows framework headers to be imported easily.I tried
const log = @import("os/log.h");but that fails with or without the.h.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.
g-w1 commentedon Feb 4, 2021
If you want to include the c library you probably want
coolbluewater commentedon Feb 4, 2021
@g-w1, unfortunately that doesn't work.
More detail: Apple frameworks have a known location and layout that clang uses to resolve
#import <os/log.h>when parsing a source file as objective-c, but not as plain C. Since zig uses clang in plain-C mode to parse files, this mechanism isn't invoked and so the header can't be located. That's why I've opened the issue mentioned above to discuss the future of objective-C interop in zig.kerrhome commentedon Feb 17, 2021
@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
os_log(), which you should be able to create anexternfor_os_log_internalto using this within your Zig app without needing the full SDK to build against. It was extremely helpful in our debugging yesterday (which we have working beautifully now). Man, Zig is great.