Add minimal support to Zig toolchain to support building iOS binaries #9532
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With this change, it is possible to successfully target iOS and iPhone Simulator platforms. See kubkon/zig-ios-example for a complete project example how.
Major changes include:
-iwithsysroot
and-iframeworkwithsysroot
flags with values frombuild.zig
and that they are correctly transferred forward tozig cc
std.zig.system.macos
intostd.zig.system.darwin.macos
since we now special-case all Apple platforms when building from another Apple platform (usually macOS) -std.zig.system.darwin.getSDKPath
now takes two args as input: allocator andTarget
, and based on the target it will invokexcrun --sdk <sdk_name> --show-sdk-path
with the appropriatesdk_name
such asiphonesimulator
oriphoneos
, etc. With this change, we make Zig auto-invokegetSDKPath
when targeting an Apple platform from an Apple platform, meaning that we no longer constrain ourselves to running natively but also when targetingios
frommacos
, etc.libSystem.tbd
in the provided syslibroot.simulator
ABI when targeting iOS -.simulator
ABI signals that the binary is meant to be run on Apple iPhone Simulator rather than on a real device and therefore it should be linked against a completely standalone set of libraries and frameworks known asiphonesimulator
SDKVERSION_MIN
load command forBUILD_VERSION
- turns out, the latter is required to make the app get properly launched on the iPhone Simulator, while presence of the former generates a sigkill-equivalent for some reasonI could use some input here on the validity of treating
std.build.addSystemIncludeDir
andstd.build.addFrameworkDir
differently based on the presence of the sysroot on the command line - if there is no sysroot present, we convert them into-isystem
and-iframework
; if the sysroot is present however, we change that to-iwithsysroot
and-iframeworkwithsysroot
. This can trigger a weird error if we are auto-detecting sysroots by Zig (when targeting iOS for instance) and the user adds explicit system search paths to theirbuild.zig
as then we get conflicting search dirs for the headers which can lead to a compile error.UPDATE: turns out that when linking against simulator ABI such as
aarch64-ios-simulator
, several libc functions such asfstat
, etc., are provided by the host (aarch64-macos
), and thus, it is necessary to take that into account when linking against tbd stubs. This has now been added in 83f1203.