This is a small utility repo that can be used to fetch and generate deduplicated macOS libc headers. The intention for
this utility is to use it to update the libc headers shipped with Zig, and used when cross-compiling to macOS
(see this article for an amazing description of the zig cc
C compiler frontend).
- Build
$ zig build
-
(Optional) Add additional libc headers to
src/headers.c
. -
Fetch headers into
libc/include/
. Thefetch
command will automatically fetch for bothx86_64
andaarch64
architectures by default.3.1. Fetch from the system-wide, latest SDK.
$ ./zig-out/bin/fetch_them_macos_headers fetch
3.2. (Optional) Fetch from a custom SDK by explicitly specifying sysroot path.
$ ./zig-out/bin/fetch_them_macos_headers fetch --sysroot <path>
See Getting older SDKs for a guide of how to install additional SDKs for older versions of macOS.
-
Merge
x86_64
andaarch64
into destination pathany-macos-any
mkdir headers/any-macos-any
rsync -vaHP headers/aarch64-macos.<VERSION>-none/. headers/any-macos-any/.
rsync -vaHP headers/x86_64-macos.<VERSION>-none/. headers/any-macos-any/.
- (Optional) Replace the contents of Zig's
lib/libc/include/any-macos-any
withheaders/any-macos-any
, and analyze the changes withgit status
.
For the deprecated method, replace steps 4,5 as follows:
- Generate deduplicated headers dirs in
<destination>
path
./zig-out/bin/fetch_them_macos_headers generate <destination>
- (Optional) Copy the contents of
<destination>
into Zig'slib/libc/include/
, and analyze the changes withgit status
.
Thanks to Rasmus Andersson's amazing work on llvmbox
it is now possible to
download additional, older SDKs on your main Mac, extract them without having to install them, and use the extracted SDKs
with fetch_them_macos_headers
.
How does it work?
- Navigate to Apple's developer portal and pick Command Line Tools installers of interest.
- Mount all of them.
- Run
unpack_sdks.sh
script.
$ ./unpack_sdks.sh .
Note that you need pbzx
in your PATH which you can get via brew install pbzx
or build from source.
- You can now pass use the extracted SDKs with
fetch_them_macos_headers
which you will find in./apple-clts
unless you used a different argument tounpack_sdks.sh
.