Skip to content

Add compiler/cross package for cross-compilation libc++ libraries#3780

Closed
Copilot wants to merge 4 commits intomainfrom
copilot/create-libcxx-cross-package
Closed

Add compiler/cross package for cross-compilation libc++ libraries#3780
Copilot wants to merge 4 commits intomainfrom
copilot/create-libcxx-cross-package

Conversation

Copy link
Contributor

Copilot AI commented Mar 9, 2026

  • compiler/cross/BUILD — cmake targets from @llvm_source with cross-compile target triple flags, like msan/tsan. No prebuilt downloads.
  • MODULE.bazel — remove @llvm_prebuilt_aarch64 and @llvm_prebuilt_x86_64 http_archives
  • versions.bzl — remove "llvm_prebuilt_sha256" dict (not needed)
  • compiler/cross/libcxx_cross.bzl — fix generated BUILD to use flat lib/ paths (cmake output layout)
  • compiler/cross/README.md — update to reflect cmake approach
  • bazel.yml — both arch artifacts uploaded (already correct)
Original prompt

Context

PR #3779 proposes overlaying aarch64 libc++ into the sysroot when cross-compiling for arm64. However, the sysroot should stay lean — it's there to provide glibc headers/libs and nothing more. We need a better approach.

What to implement

Create a standalone extraction package for cross-compilation libc++ libraries, following the exact same pattern as the existing msan_libs/tsan_libs in bazel/compile/sanitizer_libs.bzl. The key insight is that libc++.a, libc++abi.a, and libunwind.a are already prebuilt in the official LLVM release tarballs — no compilation needed.

Files to create/modify

1. Create bazel/compile/libcxx_cross.bzl

Create a new repository rule libcxx_cross that:

  • Takes target_arch (e.g., "aarch64", "x86_64"), llvm_version, and sha256 as attributes
  • Maps target arch to the LLVM release triple (e.g., "aarch64""aarch64-linux-gnu", "x86_64""x86_64-linux-gnu-ubuntu-18.04")
  • Downloads the official LLVM release tarball from https://github.com/llvm/llvm-project/releases/download/llvmorg-{ver}/clang+llvm-{ver}-{triple}.tar.xz
  • Extracts only libc++.a, libc++abi.a, libunwind.a from the lib/{target-unknown-linux-gnu}/ subdirectory of the tarball
  • Also extracts the __config_site header from include/{target-unknown-linux-gnu}/c++/v1/__config_site
  • Generates a BUILD.bazel that exposes:
    • cc_library targets for individual libs (:libcxx, :libcxxabi, :libunwind)
    • A combined cc_library target (:libcxx_cross) that bundles all three
    • A filegroup for the __config_site header
    • All with visibility = ["//visibility:public"]
  • Also create a setup_libcxx_cross() helper function (similar to setup_sanitizer_libs()) that uses defaults from VERSIONS

Follow the style/patterns of the existing bazel/compile/sanitizer_libs.bzl closely. Reference the existing code at https://github.com/envoyproxy/toolshed/blob/05dcb996bb8a087a88eb7627e05f99f327f8830b/bazel/compile/sanitizer_libs.bzl for the pattern.

The tarball structure for LLVM 18.1.8 aarch64 is:

clang+llvm-18.1.8-aarch64-linux-gnu/
  lib/aarch64-unknown-linux-gnu/libc++.a
  lib/aarch64-unknown-linux-gnu/libc++abi.a  
  lib/aarch64-unknown-linux-gnu/libunwind.a
  include/aarch64-unknown-linux-gnu/c++/v1/__config_site

2. Update bazel/compile/extensions.bzl

Add a new module extension libcxx_cross_extension (following the same pattern as sanitizer_extension) that allows bzlmod consumers to configure libcxx_cross in their MODULE.bazel.

3. Update bazel/versions.bzl

Add SHA256 hashes for the LLVM release tarballs used by this package. Add a new dict keyed by arch, e.g.:

"libcxx_cross_sha256": {
    "aarch64": "dcaa1bebbfbb86953fdfbdc7f938800229f75ad26c5c9375ef242edad737d999",
},

This is the sha256 of the clang+llvm-18.1.8-aarch64-linux-gnu.tar.xz release tarball.

4. Update bazel/compile/BUILD

Add the new .bzl file to any relevant exports/filegroups if needed to match the existing pattern.

5. Update bazel/MODULE.bazel

Add a commented-out example (like the existing sanitizer_ext example) showing how downstream consumers would use the libcxx_cross extension:

# Setup cross-compilation libc++ libraries
# libcxx_cross_ext = use_extension("@envoy_toolshed//compile:extensions.bzl", "libcxx_cross_extension")
# libcxx_cross_ext.setup()
# use_repo(libcxx_cross_ext, "libcxx_cross")

6. Update bazel/compile/README.md

Add documentation for the new libcxx_cross package, covering:

  • What it provides and why (cross-compilation libc++ without polluting the sysroot)
  • How to use with WORKSPACE
  • How to use with bzlmod

Design principles

  • Sysroot stays clean: This is a separate repository, not part of the sysroot
  • Arch-generic: Parameterized by target_arch, not hardcoded to arm64
  • Opt-in: Only fetched/instantiated when a consumer needs it
  • No compilation needed: Just download-and-extract from LLVM release tarballs
  • Follows existing patterns: Matches msan_libs/tsan_libs structure exactly

This pull request was created from Copilot chat.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

@netlify
Copy link

netlify bot commented Mar 9, 2026

Deploy Preview for nifty-bassi-e26446 ready!

Name Link
🔨 Latest commit e681c64
🔍 Latest deploy log https://app.netlify.com/projects/nifty-bassi-e26446/deploys/69aea2d1389cad000810f98b
😎 Deploy Preview https://deploy-preview-3780--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.

Co-authored-by: phlax <454682+phlax@users.noreply.github.com>
Copilot AI changed the title [WIP] Create standalone extraction package for libc++ libraries Add libcxx_cross: standalone cross-compilation libc++ extraction package Mar 9, 2026
Copilot finished work on behalf of phlax March 9, 2026 09:56
Copilot AI and others added 2 commits March 9, 2026 10:32
Co-authored-by: phlax <454682+phlax@users.noreply.github.com>
…ins_llvm

Co-authored-by: phlax <454682+phlax@users.noreply.github.com>
Copilot AI changed the title Add libcxx_cross: standalone cross-compilation libc++ extraction package Add compiler/cross package for cross-compilation libc++ libraries Mar 9, 2026
Copilot finished work on behalf of phlax March 9, 2026 10:37
Copilot stopped work on behalf of phlax due to an error March 9, 2026 10:42
@phlax
Copy link
Member

phlax commented Mar 9, 2026

USELESS

@phlax phlax closed this Mar 9, 2026
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