elmarco/macos-cross

macOS cross-compilation from Linux

★ 0Forks 0ShellGitHub ↗Compare

README

macos-cross — macOS cross-compilation from Linux

Download the macOS SDK from Apple's Software Update servers, process it, and package it for cross-compiling macOS applications from Linux using Clang and LLD.

What it fetches

The macOS SDK is downloaded directly from Apple's public Software Update catalog (the same mechanism macOS uses for Command Line Tools updates). No Apple account is required.

The SDK includes:

  • C/C++ headers (usr/include/)
  • Library stubs as .tbd files (usr/lib/)
  • macOS frameworks (System/Library/Frameworks/)

Supported target architectures: aarch64 (Apple Silicon) and x86_64 (Intel).

Quick start (RPM)

Generate, build, and install the RPMs:

./gen rpm --cache-dir .cache --install

Cross-compile with the installed helper scripts:

macos-aarch64-meson builddir
ninja -C builddir

macos-aarch64-cmake -B builddir
cmake --build builddir

macos-aarch64-config && macos-aarch64-make  # autotools (configure/make)

Quick start (Meson subproject)

For projects that vendor the SDK instead of installing it system-wide:

./gen meson --cache-dir .cache --output-dir macos-cross

Link it into your project:

ln -s /path/to/macos-cross subprojects/macos-cross
meson setup builddir --cross-file hello-macos/aarch64-apple-darwin.txt
ninja -C builddir

In your meson.build:

macos_cross_dep = dependency('macos-cross')
executable('app', 'main.c', dependencies: macos_cross_dep)

What the RPM provides

The SDK subpackage (macos-cross-sdk) installs the SDK to /usr/share/macos-cross/sdk/.

Each arch subpackage (macos-cross-aarch64, macos-cross-x86_64) installs:

File aarch64 path
Sysroot /usr/aarch64-apple-darwin/sys-root/ (entries symlinked from shared SDK)
Meson cross file /usr/share/macos-cross/aarch64-apple-darwin.txt
CMake toolchain /usr/share/macos-cross/toolchain-aarch64-apple-darwin.cmake
pkgconf personality /usr/share/pkgconfig/personality.d/aarch64-apple-darwin.personality
pkg-config wrapper /usr/bin/aarch64-apple-darwin-pkg-config
Helper: meson /usr/bin/macos-aarch64-meson
Helper: cmake /usr/bin/macos-aarch64-cmake
Helper: configure /usr/bin/macos-aarch64-config
Helper: make /usr/bin/macos-aarch64-make

x86_64 equivalents use the x86_64-apple-darwin triple and a macos-x86_64- prefix.

The RPM pulls in clang, lld, and pkgconf-pkg-config as dependencies.

Installing third-party libraries with macos-brew

The macOS SDK only provides system frameworks and libraries. For third-party libraries (e.g., glib, openssl, libpng), use macos-brew to download pre-built Homebrew bottles directly into your cross-compilation sysroot:

macos-brew --arch aarch64 install glib

macos-brew fetches bottles from Homebrew's public API (no macOS or Homebrew installation required), verifies checksums, resolves dependencies automatically, and links everything into the sysroot so headers and libraries are found by the cross-compiler toolchain.

Common commands:

macos-brew search libpng              # Search available formulae
macos-brew info glib                  # Show formula details and dependencies
macos-brew install openssl glib       # Install formulae (with dependencies)
macos-brew upgrade                    # Upgrade all installed formulae
macos-brew list                       # List installed formulae
macos-brew uninstall glib             # Remove a formula

Options and environment variables:

Option / Variable Description Default
--arch <arch> / MACOS_BREW_ARCH Target architecture (x86_64 or aarch64) x86_64
--dry-run Show what would be done without doing it
MACOS_BREW_VERSION macOS codename for bottle selection sonoma
MACOS_BREW_SYSROOT Sysroot path /usr/<arch>-apple-darwin/sys-root
MACOS_BREW_CACHE Cache directory for downloads $XDG_CACHE_HOME/macos-brew

The macos-brew script is included in the macos-cross-sdk RPM package.

Using a local SDK

If you already have a macOS SDK (e.g., from Xcode on a Mac):

./gen rpm --sdk-path /path/to/MacOSX15.5.sdk --cache-dir .cache

Requirements

  • Python 3 (for ./gen)
  • cpio (for extracting Apple .pkg files)
  • defusedxml (pip install defusedxml or dnf install python3-defusedxml)

For building:

  • Clang + LLD (dnf install clang lld)
  • Meson + Ninja (dnf install meson ninja-build)

The RPM packages pull in clang and lld automatically.

Options

Common options (both ./gen rpm and ./gen meson):

--clt-version VERSION   Command Line Tools version (e.g. 16.4;
                        determines the macOS SDK version; default: latest)
--sdk-path PATH         Use a local SDK directory (skip download)
--cache-dir DIR         Cache for downloads (default: temp)
--output-dir DIR        Directory for generated files (default: .)
--list-versions         List available CLT versions and exit
--inspect               Show SDK contents without generating output

RPM-only options:

--install               Build and install RPMs after generation
--no-install            Skip RPM build/install (just generate spec + tarball)

When neither --install nor --no-install is given, the tool prompts interactively.

License

The generator scripts are in the public domain (no license restrictions). The downloaded macOS SDK is proprietary — see the generated LICENSE.txt. Do not upload the SDK output to public repositories.

Contributors

elmarco

Issues