Skip to content

sysroot/compile: add macOS arm64 cross-compilation support#4656

Open
mathetake wants to merge 7 commits into
envoyproxy:mainfrom
mathetake:tyoneda/darwin-cross-compilation
Open

sysroot/compile: add macOS arm64 cross-compilation support#4656
mathetake wants to merge 7 commits into
envoyproxy:mainfrom
mathetake:tyoneda/darwin-cross-compilation

Conversation

@mathetake

Copy link
Copy Markdown
Member

Add repository rules and build scripts for cross-compiling to macOS arm64 from Linux x86_64:

  • sysroot.bzl: add macos_sysroot rule and setup_macos_sysroot() for macOS SDK sysroot (headers, frameworks, .tbd stubs)
  • libcxx_libs.bzl: add libcxx_libs_darwin rule and setup_libcxx_libs_darwin() for darwin libc++ (dylibs + __config_site)
  • versions.bzl: add placeholder hashes for macOS sysroot and darwin libcxx
  • build_macos_sysroot.sh: script to package macOS SDK from Xcode
  • build_libcxx_darwin.sh: script to build darwin libc++ from LLVM source

The macOS SDK sysroot provides system headers and .tbd library stubs. The darwin libcxx provides libc++ dylibs and the __config_site header needed by the LLVM toolchain for cross-compilation.

When hashes are empty (tarballs not yet built/uploaded), the rules generate fallback content: the sysroot creates an empty directory, and libcxx_libs generates __config_site from the Linux LLVM version.

@netlify

netlify Bot commented Jun 16, 2026

Copy link
Copy Markdown

Deploy Preview for nifty-bassi-e26446 ready!

Name Link
🔨 Latest commit 064d691
🔍 Latest deploy log https://app.netlify.com/projects/nifty-bassi-e26446/deploys/6a3170f1fde80200088d3e81
😎 Deploy Preview https://deploy-preview-4656--nifty-bassi-e26446.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@mathetake mathetake requested a review from phlax June 16, 2026 03:44
mathetake and others added 3 commits June 16, 2026 15:00
Add repository rules and build scripts for cross-compiling to macOS arm64
from Linux x86_64:

- sysroot.bzl: add `macos_sysroot` rule and `setup_macos_sysroot()` for
  macOS SDK sysroot (headers, frameworks, .tbd stubs)
- libcxx_libs.bzl: add `libcxx_libs_darwin` rule and
  `setup_libcxx_libs_darwin()` for darwin libc++ (dylibs + __config_site)
- versions.bzl: add placeholder hashes for macOS sysroot and darwin libcxx
- build_macos_sysroot.sh: script to package macOS SDK from Xcode
- build_libcxx_darwin.sh: script to build darwin libc++ from LLVM source

The macOS SDK sysroot provides system headers and .tbd library stubs.
The darwin libcxx provides libc++ dylibs and the __config_site header
needed by the LLVM toolchain for cross-compilation.

When hashes are empty (tarballs not yet built/uploaded), the rules
generate fallback content: the sysroot creates an empty directory,
and libcxx_libs generates __config_site from the Linux LLVM version.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
Add a `build-macos-sysroot` job to the Bazel CI workflow that runs on
`macos-14` and produces two artifacts:

1. `sysroot-macos-arm64.tar.xz` — macOS SDK sysroot extracted from
   the Xcode installation on the CI runner (headers, frameworks, .tbd stubs)

2. `libcxx-llvm18.1.8-darwin-aarch64.tar.xz` — libc++ built from LLVM
   source for darwin arm64 (dylibs + __config_site)

These artifacts are needed for cross-compiling Envoy (and other C++
projects) from Linux x86_64 to macOS arm64. The Linux sysroots are
built by debootstrap on Linux runners; the macOS sysroot requires a
macOS runner with Xcode to extract Apple's SDK.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
- Fix shellcheck SC2295: quote expansions inside ${..} in sysroot scripts
- Fix shellcheck SC2034: remove unused ARCH variable in libcxx script
- Fix cmake error: add libunwind to LLVM_ENABLE_RUNTIMES and set
  LIBCXXABI_USE_LLVM_UNWINDER=ON (required by libcxxabi)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
@mathetake mathetake force-pushed the tyoneda/darwin-cross-compilation branch from 043c3fe to fa34f54 Compare June 16, 2026 15:00
@mathetake mathetake marked this pull request as ready for review June 16, 2026 15:08
mathetake and others added 4 commits June 16, 2026 15:13
Some frameworks (e.g., SystemConfiguration) have headers under
Versions/A/Headers/ instead of just Headers/. Copy the full framework
structure including versioned directories so clang can find all headers.

Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
macOS `cp -a` requires the parent directory to exist. Create it with
mkdir -p before copying Headers/Modules directories.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
Ruby.framework contains self-referencing symlinks (ruby -> .) that
cause infinite recursion during Bazel's glob expansion. Remove these
circular symlinks before packaging.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
Selectively copying Headers/Modules/tbd from frameworks breaks clang's
framework header lookup, which depends on symlinks like:
  Headers -> Versions/Current/Headers
  Versions/Current -> A

SDK frameworks contain only headers, modules, and .tbd stubs (no large
binaries), so copying the entire directory is safe and correct.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant