Skip to content

compile: support host LLVM in llvm_toolchain_alias via BAZEL_LLVM_PATH - #5266

Open
jwendell wants to merge 1 commit into
envoyproxy:mainfrom
jwendell:host-llvm-toolchain-alias
Open

jwendell wants to merge 1 commit into
envoyproxy:mainfrom
jwendell:host-llvm-toolchain-alias

Conversation

@jwendell

@jwendell jwendell commented Sep 16, 2026

Copy link
Copy Markdown
Member

The bzlmod llvm_toolchain_alias rule always backs @llvm_toolchain_llvm
with the hermetic minimal-LLVM artifact. WORKSPACE builds could steer the
whole LLVM surface (including the libclang the Envoy openssl prefixer links)
to the host toolchain via BAZEL_LLVM_PATH; that escape hatch was lost in
the bzlmod migration, so host builds link the hermetic libclang-cpp, which
can need a newer libstdc++ (GLIBCXX_3.4.30) than the host ships.

Honor BAZEL_LLVM_PATH (the same variable Envoy's own repo.bzl/toolchains.bzl
branch on): when set, populate @llvm_toolchain_llvm from the host and reuse
the same BUILD template as the hermetic path, so both expose an identical
target surface. The repo name is unchanged, so hardcoded consumers (e.g. an
-isystem) keep resolving -- now to the host.

  • bin/ tools symlinked from the host, preferring the version-suffixed name
    (llvm-nm-21) so multi-LLVM hosts match the selected resource-dir major.
  • LLVM C++ API headers + per-triple libc++ headers symlinked, scoped to
    LLVM rather than the whole distro tree.
  • clang resource dir normalized to lib/clang/ from lib/ or lib64/.
  • libclang/libLLVM shared libs exposed under both lib/ (feeds the template's
    lib-globbed filegroups) and lib64/ (feeds the version-qualified label Envoy
    composes from the host's own lib dir, e.g. lib64/libclang-cpp.so.).
  • BAZEL_LLVM_PATH validated (must exist and hold a clang resource dir).

The shared template's fixed-name tool filegroups now render from a table with
a tools_optional switch: literal srcs on the hermetic path (a missing tool
is a real integrity error), globbed with allow_empty on the host path so a
distro that omits an optional tool (git-clang-format, llvm-dwp, ...) does not
fail analysis.

Also fixes a latent sandbox collision: cxx_builtin_include globbed
directories (exclude_directories = 0) also staged as files via :include,
failing sandbox setup with ".../include/c++ (File exists)"; it now globs the
directory contents (/**).

@netlify

netlify Bot commented Sep 16, 2026

Copy link
Copy Markdown

Deploy Preview for nifty-bassi-e26446 ready!

Name Link
🔨 Latest commit 19efb4a
🔍 Latest deploy log https://app.netlify.com/projects/nifty-bassi-e26446/deploys/6aab00c8ff6a7a0009912d99
😎 Deploy Preview https://deploy-preview-5266--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.

The bzlmod `llvm_toolchain_alias` rule always backs `@llvm_toolchain_llvm`
with the hermetic minimal-LLVM artifact. WORKSPACE builds could steer the
whole LLVM surface (including the libclang the Envoy openssl prefixer links)
to the host toolchain via `BAZEL_LLVM_PATH`; that escape hatch was lost in
the bzlmod migration, so host builds link the hermetic libclang-cpp, which
can need a newer libstdc++ (GLIBCXX_3.4.30) than the host ships.

Honor `BAZEL_LLVM_PATH` (the same variable Envoy's own repo.bzl/toolchains.bzl
branch on): when set, populate `@llvm_toolchain_llvm` from the host and reuse
the *same* BUILD template as the hermetic path, so both expose an identical
target surface. The repo name is unchanged, so hardcoded consumers (e.g. an
`-isystem`) keep resolving -- now to the host.

  - bin/ tools symlinked from the host, preferring the version-suffixed name
    (llvm-nm-21) so multi-LLVM hosts match the selected resource-dir major.
  - LLVM C++ API headers + per-triple libc++ headers symlinked, scoped to
    LLVM rather than the whole distro tree.
  - clang resource dir normalized to lib/clang/<major> from lib/ or lib64/.
  - libclang/libLLVM shared libs exposed under both lib/ (feeds the template's
    lib-globbed filegroups) and lib64/ (feeds the version-qualified label Envoy
    composes from the host's own lib dir, e.g. lib64/libclang-cpp.so.<ver>).
  - `BAZEL_LLVM_PATH` validated (must exist and hold a clang resource dir).

The shared template's fixed-name tool filegroups now render from a table with
a `tools_optional` switch: literal srcs on the hermetic path (a missing tool
is a real integrity error), globbed with `allow_empty` on the host path so a
distro that omits an optional tool (git-clang-format, llvm-dwp, ...) does not
fail analysis.

Also fixes a latent sandbox collision: `cxx_builtin_include` globbed
directories (`exclude_directories = 0`) also staged as files via `:include`,
failing sandbox setup with ".../include/c++ (File exists)"; it now globs the
directory contents (`/**`).

Signed-off-by: Jonh Wendell <jwendell@redhat.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jwendell
jwendell force-pushed the host-llvm-toolchain-alias branch from f70d9ba to 19efb4a Compare September 16, 2026 20:49
@jwendell

Copy link
Copy Markdown
Member Author

@phlax this fixes the build using host's toolchain after migration to bzlmod.

This branch has not been deployed

No deployments
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