Skip to content

Port libClangSharp to the LLVM 22 Clang AST#785

Merged
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:regenerate-native-workflow
Jul 15, 2026
Merged

Port libClangSharp to the LLVM 22 Clang AST#785
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:regenerate-native-workflow

Conversation

@tannergooding

@tannergooding tannergooding commented Jul 15, 2026

Copy link
Copy Markdown
Member

Note

This PR body was drafted by Copilot.

Updates sources/libClangSharp for the LLVM 21 -> 22 type-sugar refactor so the native library compiles and links against the 22.1.8 release (#779 bumped the tracked version ahead of the C++ port, leaving the regenerate-native legs red).

libClangSharp port

  • ElaboratedType is removed; the elaboration keyword/qualifier and tag ownership moved onto TagType. clangsharp_Type_getOwnedTagDecl now uses TagType::isTagOwned()/getDecl(), and the Elaborated CXType kind mapping is dropped from CXType.cpp.
  • InjectedClassNameType is now a TagType. The injected specialization is recovered via getCanonicalInjectedSpecializationType(ctx) (decl-level, the same replacement clang itself uses in findPartialSpecialization) and via getCanonicalTemplateSpecializationType(None, getTemplateName(ctx), getTemplateArgs(ctx)) (type-level, matching clang's own ClassTemplatePartialSpecializationDecl::getCanonicalInjectedSpecializationType construction).
  • DependentTemplateSpecializationType is folded into TemplateSpecializationType; its template-argument branch is dropped and handled by the existing TemplateSpecializationType branch.
  • UsingType::getFoundDecl -> getDecl (same underlying UsingShadowDecl).

One inherent behavior shift: the injected-specialization getters now return the canonical injected type -- LLVM 22 no longer stores the as-written one. Same template and injected args.

Build

  • CMakeLists.txt: set CMAKE_MSVC_RUNTIME_LIBRARY to the static CRT (/MT) so libClangSharp links against the official /MT LLVM release binaries without LNK2038. Bumped cmake_minimum_required 3.13 -> 3.15 so the runtime-library policy applies. Validated locally: compiles with 0 errors and links libClangSharp.dll against the real 22.1.8 release via a plain -DPATH_TO_LLVM invocation.

Detect refactor

Moves the regenerate-native change-detection and package-version verification out of YAML into build.ps1/build.sh (--detectchanges/--verifypackages) so they're reproducible and testable locally, and thins the workflow down to glue around the scripts.


Directory.Packages.props intentionally stays on the 21.1.8 consuming refs so ci.yml restore stays green -- the 22.1.8 native packages are published by this workflow first. A stacked follow-up then bumps the consuming refs, regenerates the managed bindings, and fixes the CX_TypeClass ordinals (the LLVM 22 TypeNodes change removes Elaborated/DependentTemplateSpecialization and reparents InjectedClassName, shifting the ordinals that clangsharp_Type_getTypeClass feeds into the managed enum).

Update sources/libClangSharp for the LLVM 21 -> 22 type-sugar refactor so it
compiles and links against the 22.1.8 release:

- ElaboratedType is removed; the elaboration keyword/qualifier and tag ownership
  moved onto TagType, so getOwnedTagDecl now uses TagType::isTagOwned()/getDecl()
  and the Elaborated CXType kind mapping is dropped.
- InjectedClassNameType is now a TagType; recover the injected specialization via
  getCanonicalInjectedSpecializationType and getTemplateName/getTemplateArgs(ctx),
  which return the canonical injected type (22 no longer stores the as-written one).
- DependentTemplateSpecializationType is folded into TemplateSpecializationType, so
  its template-argument branch is dropped and handled by the existing one.
- UsingType::getFoundDecl is renamed to getDecl.

Set CMAKE_MSVC_RUNTIME_LIBRARY to the static CRT so libClangSharp links against the
official /MT LLVM release binaries without LNK2038.

----------

Move the regenerate-native detection/verification out of YAML into build.ps1|sh
(--detectchanges/--verifypackages) so it is reproducible and testable locally, and
thin the workflow down to glue around the scripts.

Directory.Packages.props intentionally stays on the 21.1.8 consuming refs; the 22.1.8
native packages are published by this workflow first, then bumped in a follow-up.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tannergooding
tannergooding merged commit da0bdc5 into dotnet:main Jul 15, 2026
12 checks passed
@tannergooding
tannergooding deleted the regenerate-native-workflow branch July 15, 2026 04:28
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