Skip to content

Add macOS arm64 sysroot/lbcxx#4656

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

Add macOS arm64 sysroot/lbcxx#4656
mathetake wants to merge 20 commits into
envoyproxy:mainfrom
mathetake:tyoneda/darwin-cross-compilation

Conversation

@mathetake

@mathetake mathetake commented Jun 16, 2026

Copy link
Copy Markdown
Member

No description provided.

@netlify

netlify Bot commented Jun 16, 2026

Copy link
Copy Markdown

Deploy Preview for nifty-bassi-e26446 ready!

Name Link
🔨 Latest commit d602445
🔍 Latest deploy log https://app.netlify.com/projects/nifty-bassi-e26446/deploys/6a31c4ea50bc39000914fc14
😎 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 5 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>
Without this, binaries linked against the cross-compiled libc++ fail
at runtime with "no LC_RPATH's found" because the dylib install name
is @rpath/libc++.1.dylib. macOS ships libc++ at /usr/lib/libc++.1.dylib,
so patching the install names makes binaries use the system library.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
@mathetake

Copy link
Copy Markdown
Member Author

sorry will switch to a different way -

@mathetake mathetake marked this pull request as draft June 16, 2026 16:25
mathetake and others added 8 commits June 16, 2026 16:27
Replace the macos-14 runner approach with a fully Linux-based build:

Sysroot: Download Apple's CLTools SDK package from their public CDN
(swcdn.apple.com, no auth required) and extract on Linux using
cerisier/pkgutil. A manifest file selects only the needed files
(headers, .tbd stubs, 6 frameworks). Result: ~6MB vs 205MB.

Libcxx: Extract __config_site and libc++ dylibs directly from the
official LLVM macOS-ARM64 release tarball — no cmake build needed.
Patch install names from @rpath/ to /usr/lib/ so binaries use the
system libc++ at runtime.

Benefits:
- No macOS runner needed (cheaper, faster)
- Deterministic (pinned URLs + SHA256 checksums)
- Minimal sysroot (only files needed for cross-compilation)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
Apple's CDN may reject requests without a browser user-agent.
Also fix stale comment referencing macos-14 runner.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
LLVM 18.x uses "clang+llvm-VER-arm64-apple-macosNN" naming convention,
not "LLVM-VER-macOS-ARM64" (which is the newer format from LLVM 20+).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
The macOS LLVM tarball's llvm-install-name-tool is a Mach-O binary
that can't run on Linux. Use the Linux distro's llvm-install-name-tool
instead — it can edit Mach-O files cross-platform.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
The system llvm package doesn't include llvm-install-name-tool.
Extract it from the Linux LLVM 18.1.8 release instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
llvm-install-name-tool is a symlink to llvm-objcopy that changes
behavior based on argv[0]. Extract llvm-objcopy and create the symlink.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
The pre-built LLVM 18 binaries need libtinfo.so.5 which isn't on
Ubuntu 24.04. Use the system llvm-18 package instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
@mathetake mathetake marked this pull request as ready for review June 16, 2026 20:59
Comment thread .github/workflows/_bazel.yml Outdated
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
@mathetake mathetake enabled auto-merge (squash) June 16, 2026 21:09
Comment thread .github/workflows/_bazel.yml Outdated
mathetake and others added 2 commits June 16, 2026 21:33
These cmake/Xcode-based scripts are superseded by the CI job that
extracts pre-built artifacts from Apple's CDN and LLVM releases.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
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 6eabf64 to 406c810 Compare June 16, 2026 21:37
@phlax

phlax commented Jun 16, 2026

Copy link
Copy Markdown
Member

ci/docker error is unrelated annoyance

Comment thread bazel/versions.bzl Outdated
# Darwin libc++ cross-compilation libraries (built from LLVM source for macOS arm64)
# Contains include/__config_site and lib/libc++.dylib, lib/libc++abi.dylib
"libcxx_libs_darwin_sha256": {
"aarch64": "", # TODO: populate after building and uploading tarball

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might need to hook this into the ci bazel/prepare step

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d602445 🤞

@mathetake mathetake changed the title sysroot/compile: add macOS arm64 cross-compilation support Add macOS arm64 sysroot/lbcxx Jun 16, 2026
@mathetake mathetake disabled auto-merge June 16, 2026 21:49
Hook the macOS cross-compilation artifact hashes into the bazel release
prepare step in _release.yml. When a bins release is created, the jq
filter now also updates macos_sysroot_sha256 and libcxx_libs_darwin_sha256
in versions.bzl from the release asset checksums.

Handles both initial population (empty string → hash) and updates
(old hash → new hash).

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

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Takeshi Yoneda <tyoneda@netflix.com>
@mathetake

Copy link
Copy Markdown
Member Author

docker 🤷

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.

2 participants