-
-
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
Ship versioned libc headers on macOS #10215
Conversation
cc @slimsag |
Looks good so far! There's one more place you'll need to edit in Compilation.zig for the generated builtin.zig source. |
`fetch-them-macos-headers` gitrev 7036517cc6a9aa154e7aef4c4593b5c4a5143ed4
This is mainly because arm64 macOS doesn't support all versions supported by x86_64 macOS. This is just a temporary thing until both architectures support the same set of OSes.
This means that I am purposefully regressing linking iOS and related which will require manual specification of the sysroot path, etc.
This is handled before by detecting and adding SDK path which is a centralised point for the native libc installation on darwin.
9db4d61
to
f8eb840
Compare
We will mimick the same solution as with the headers: * `libSystem.10.tbd` * `libSystem.11.tbd` * `libSystem.12.tbd` and so on...
f8eb840
to
3a3576d
Compare
Hmm, are you sure anything needs updating in |
Ready for review! I've fixed one of the oversights I made when adding better iOS, iPadOS, etc. support to Zig. Namely, since all of these represent cross-compilation targets from macOS, if you decide to cross-compile to any such target, you will need to manually specify relevant sysroot and syslib / framework paths on the command line and in your
But, if you're building the same
|
Finally, you are now free to target any of the supported macOS versions for cross-compilation using version ranges. For instance, in order to target Catalina from Monterey, all you need to do is:
Similarly, if we want to target M1 Monterey from a Catalina-based Intel MBP, we can do:
Tl;dr versioning is currently based on major macOS revisions - 10 for Catalina, 11 for BigSur, 12 for Monterey. If this is confusing, or if Apple decides to use minor versioning again between different OS cuts (10.14 vs 10.15), we can add that in too. |
}; | ||
|
||
const sysroot = blk: { | ||
if (options.sysroot) |sysroot| { | ||
break :blk sysroot; | ||
} else if (darwin_can_use_system_sdk) { | ||
} else if (darwin_use_system_sdk) { | ||
break :blk try std.zig.system.darwin.getSDKPath(arena, options.target); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this change might fix an issue I've been meaning to file for a while now, #10217, specifically when specifying a cross-compilation target. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I hope that's the case too actually. Would you mind checking after this gets merged, or building zig directly from this branch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks quite good to me!
CI failure:
|
A bug in libstd, fixed in a041401. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a really big improvement for targeting macOS!
For those who aren't paying super close attention (and for myself when I type up release notes in a couple weeks):
Master branch, before this PR
- macOS C headers & .tbd files total installation size: 6.1 MiB
- tarball size: 534 KB
- supported triples:
- x86_64-macos.11 (Big Sur)
- aarch64-macos.11 (Big Sur)
After this PR is merged
- macOS C headers & .tbd files total installation size: 13.1 MiB
- tarball size: 581 KB
- supported triples:
- x86_64-macos.10 (Catalina)
- x86_64-macos.11 (Big Sur)
- x86_64-macos.12 (Monterey)
- aarch64-macos.11 (Big Sur)
- aarch64-macos.12 (Monterey)
…eting The latest Zig master supports specifying a specific macOS version for libc, via the target triple (ziglang/zig#10215): * x86_64-macos.10 (Catalina) * x86_64-macos.11 (Big Sur) * x86_64-macos.12 (Monterey) * aarch64-macos.11 (Big Sur) * aarch64-macos.12 (Monterey) Mach's `system_sdk.zig` can now download the relevant XCode framework stubs for Big Sur (11) and Monterey (12). We do not support Catalina (10) currently. By default, Zig targets the N-3 version (e.g. `x86_64-macos` defaults to `x86_64-macos.10`). Targeting the older version (`<arch>-macos.11`) is useful for compatability, it guarantees the produced binary will run on macOS 11+. Targeting the newer version can be useful if you wish to use newer APIs not available in previous versions. Fixes #102 Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
…eting The latest Zig master supports specifying a specific macOS version for libc, via the target triple (ziglang/zig#10215): * x86_64-macos.10 (Catalina) * x86_64-macos.11 (Big Sur) * x86_64-macos.12 (Monterey) * aarch64-macos.11 (Big Sur) * aarch64-macos.12 (Monterey) Mach's `system_sdk.zig` can now download the relevant XCode framework stubs for Big Sur (11) and Monterey (12). Although we don't have an SDK for Catalina (10) currently, we use the Big Sur (11) SDK in that case and it generally works fine. By default, Zig targets the N-3 version (e.g. `x86_64-macos` defaults to `x86_64-macos.10`). Targeting the minimum supported version is useful for compatability, it guarantees the produced binary will run on any later macOS version. Targeting the newer version can be useful if you wish to use newer APIs not available in previous versions. Fixes #102 Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
…eting The latest Zig master supports specifying a specific macOS version for libc, via the target triple (ziglang/zig#10215): * x86_64-macos.10 (Catalina) * x86_64-macos.11 (Big Sur) * x86_64-macos.12 (Monterey) * aarch64-macos.11 (Big Sur) * aarch64-macos.12 (Monterey) Mach's `system_sdk.zig` can now download the relevant XCode framework stubs for Big Sur (11) and Monterey (12). Although we don't have an SDK for Catalina (10) currently, we use the Big Sur (11) SDK in that case and it generally works fine. By default, Zig targets the N-3 version (e.g. `x86_64-macos` defaults to `x86_64-macos.10`). Targeting the minimum supported version is useful for compatability, it guarantees the produced binary will run on any later macOS version. Targeting the newer version can be useful if you wish to use newer APIs not available in previous versions. Fixes #102 Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
…eting The latest Zig master supports specifying a specific macOS version for libc, via the target triple (ziglang/zig#10215): * x86_64-macos.10 (Catalina) * x86_64-macos.11 (Big Sur) * x86_64-macos.12 (Monterey) * aarch64-macos.11 (Big Sur) * aarch64-macos.12 (Monterey) Mach's `system_sdk.zig` can now download the relevant XCode framework stubs for Big Sur (11) and Monterey (12). Although we don't have an SDK for Catalina (10) currently, we use the Big Sur (11) SDK in that case and it generally works fine. By default, Zig targets the N-3 version (e.g. `x86_64-macos` defaults to `x86_64-macos.10`). Targeting the minimum supported version is useful for compatability, it guarantees the produced binary will run on any later macOS version. Targeting the newer version can be useful if you wish to use newer APIs not available in previous versions. Fixes hexops/mach#102 Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
…eting The latest Zig master supports specifying a specific macOS version for libc, via the target triple (ziglang/zig#10215): * x86_64-macos.10 (Catalina) * x86_64-macos.11 (Big Sur) * x86_64-macos.12 (Monterey) * aarch64-macos.11 (Big Sur) * aarch64-macos.12 (Monterey) Mach's `system_sdk.zig` can now download the relevant XCode framework stubs for Big Sur (11) and Monterey (12). Although we don't have an SDK for Catalina (10) currently, we use the Big Sur (11) SDK in that case and it generally works fine. By default, Zig targets the N-3 version (e.g. `x86_64-macos` defaults to `x86_64-macos.10`). Targeting the minimum supported version is useful for compatability, it guarantees the produced binary will run on any later macOS version. Targeting the newer version can be useful if you wish to use newer APIs not available in previous versions. Fixes hexops/mach#102 Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
Fixes #10200
Previously, we would ship a singular set of libc headers per macOS CPU architecture. This PR rectifies it by now shipping a separate set of headers per macOS version AND CPU architecture. The headers are deduplicated among themselves following a 3 layer approach such that:
x86_64-macos.10
x86_64-macos.11
x86_64-macos.12
aarch64-macos.11
aarch64-macos.12
any-macos.10
any-macos.11
any-macos.12
any-macos-any
where each subsequent layer contains common headers from the previous layer. More on this can be found in the discussion in ziglang/fetch-them-macos-headers#15.
Changes required to make this work include:
Compilation.detectLibCIncludeDirs
(dab6414)std.Target.Os.defaultVersionRange
to also acceptstd.Target.Cpu.Arch
enum as there is currently a mismatch between the minimum version of macOS supported byx86_64
andaarch64
(the former is 10.15, while the latter is 11.6) (baf4609)xcrun --sdk macosx --show-sdk-path
- turns out that it is possible to have SDK 11.1 on macOS 10.15, or SDK 12.0 on macOS 11.6. I'm guessing that Apple offers devs on the older OSes to target newer / latest OS too.libSystem.B.tbd
shipped with Zig to match the versions that Zig currently supports