Skip to content

Build clang-tidy with plugin support and publish plugin headers#13

Merged
guybedford merged 1 commit into
mainfrom
gbedford/clang-tidy-plugin-support
May 11, 2026
Merged

Build clang-tidy with plugin support and publish plugin headers#13
guybedford merged 1 commit into
mainfrom
gbedford/clang-tidy-plugin-support

Conversation

@guybedford
Copy link
Copy Markdown
Contributor

This enables workerd to ship its JsgLint clang-tidy plugin against the workerd-tools-built clang-tidy binary.

Two coordinated changes:

  • build/llvm/common.args flips LLVM_ENABLE_PLUGINS=ON, CLANG_PLUGIN_SUPPORT=ON, and adds LLVM_ENABLE_RTTI=ON. Without these the clang-tidy binary neither exports its symbols for dlopen resolution nor emits the typeinfo records that an out-of-tree plugin's vtable references, and clang-tidy --load=... fails.

  • The LLVM workflow gains a packaging step that, when the requested target contains clang-tidy, builds a per-platform llvm-<version>-<os>-clang-tidy-dev.tar.xz asset. It contains the headers needed to compile an out-of-tree plugin against this exact build:

    clang/include/{clang,clang-c}/**
    llvm/include/{llvm,llvm-c}/**
    build/include/**                   # generated config headers
    build/tools/clang/include/**       # generated clang config headers
    clang-tools-extra/clang-tidy/**.h  # plugin API (only in the source tree)
    

    Layout mirrors the LLVM source tree, so a consumer just adds -I clang/include -I llvm/include -I build/include -I build/tools/clang/include -I clang-tools-extra. Generated headers under build/ are platform-specific, hence one tarball per matrix entry.

The consuming workerd side (build/tools/clang_tidy/plugin/BUILD.headers) already expects this layout; once a release is cut with this workflow change, the temporary new_local_repository pointing at a hand-built LLVM tree gets replaced with a github_release entry in build/deps/build_deps.jsonc.

Verified the workflow's packaging step locally by mirroring it against a hand-built LLVM 22 source/build tree and confirming that bazel build //build/tools/clang_tidy/plugin:JsgLint.so in workerd consumes the resulting layout cleanly.

Workerd's JsgLint clang-tidy plugin needs the workerd-tools clang-tidy
binary to be built with LLVM_ENABLE_PLUGINS, CLANG_PLUGIN_SUPPORT and
LLVM_ENABLE_RTTI enabled so that plugins can be loaded via --load= and
resolve symbols against the running binary. Flip those three flags in
build/llvm/common.args.

Out-of-tree plugins also need a slice of the LLVM source / build tree
headers to compile against. Add a packaging step to the LLVM workflow
that, when the target contains 'clang-tidy', produces a per-platform
llvm-<version>-<os>-clang-tidy-dev.tar.xz asset containing:

  - clang/include/{clang,clang-c}/**
  - llvm/include/{llvm,llvm-c}/**
  - build/include/** (generated config headers)
  - build/tools/clang/include/** (generated clang config headers)
  - clang-tools-extra/clang-tidy/**.h (plugin API)

The layout mirrors the LLVM source tree so consumers just need
-I clang/include -I llvm/include -I build/include
-I build/tools/clang/include -I clang-tools-extra. Generated headers
under build/ are platform-specific, hence one tarball per platform.
@guybedford guybedford requested a review from a team as a code owner May 11, 2026 21:40
@guybedford guybedford merged commit 581a6c9 into main May 11, 2026
3 checks passed
@guybedford guybedford deleted the gbedford/clang-tidy-plugin-support branch May 11, 2026 21:47
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