Prototype own CMake configuration for `llvm-project` by thevar1able · Pull Request #97453 · ClickHouse/ClickHouse · GitHub
Skip to content

Prototype own CMake configuration for llvm-project#97453

Merged
thevar1able merged 25 commits into
masterfrom
own-cmake-for-llvm
Apr 15, 2026
Merged

Prototype own CMake configuration for llvm-project#97453
thevar1able merged 25 commits into
masterfrom
own-cmake-for-llvm

Conversation

@thevar1able

@thevar1able thevar1able commented Feb 20, 2026

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Build/Testing/Packaging Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Provide own CMake configuration for llvm-project instead of importing upstream one.

Version info

  • Merged into: 26.4.1.971

@clickhouse-gh

clickhouse-gh Bot commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

@clickhouse-gh clickhouse-gh Bot added pr-build Pull request with build/testing/packaging improvement submodule changed At least one submodule changed in this PR. labels Feb 20, 2026
@thevar1able thevar1able marked this pull request as draft February 20, 2026 06:07
Comment thread contrib/llvm-project-cmake-new/CMakeLists.txt Outdated
@thevar1able thevar1able marked this pull request as ready for review April 8, 2026 18:04
Comment thread contrib/llvm-project-cmake/native-tblgen/CMakeLists.txt Outdated
Comment thread contrib/llvm-project-cmake/native-tblgen/CMakeLists.txt
@alexey-milovidov alexey-milovidov self-assigned this Apr 8, 2026

@alexey-milovidov alexey-milovidov left a comment

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.

LGTM

Comment thread contrib/llvm-project-cmake/native-tblgen/CMakeLists.txt Outdated
Comment thread contrib/llvm-project-cmake/CMakeLists.txt
Comment thread contrib/llvm-project-cmake/CMakeLists.txt Outdated
@alexey-milovidov

Copy link
Copy Markdown
Member

The Can't adjust last granule error in CI is a known issue. The fix is in #101641

@thevar1able

Copy link
Copy Markdown
Member Author

@thevar1able thevar1able marked this pull request as draft April 9, 2026 21:16
Replace the upstream LLVM CMake with a custom build that explicitly
lists source files, runs tablegen, and builds individual LLVM static
libraries. This gives full control over compilation flags and
dependencies while significantly reducing CMake configure time.

Assisted-by: Claude Sonnet 4.5 via GitHub Copilot
…Make build

Add source file lists for AArch64, PowerPC, SystemZ, and RISCV targets
with their respective tablegen rules. Add missing LLVM libraries needed
for linking: CGData, ObjCARCOpts, IRPrinter, CFGuard, FrontendOpenMP,
FrontendOpenACC, FrontendOffloading, Coroutines, and SandboxIR. Also add
BLAKE3 sources to LLVMSupport and DWARF LowLevel sources to
LLVMDebugInfoDWARF.

Assisted-by: Claude Opus 4.6
When cross-compiling (e.g., ARM host building for x86_64), tablegen
tools must be built for the host system to be executable during the
build process. Previously, tablegen was built with the target sysroot,
making the binaries reference target system libraries that don't exist
on the host.

This commit:
- Detects cross-compilation via CMAKE_CROSSCOMPILING
- Uses ExternalProject_Add to build native tablegen without toolchain
- Copies GenVT.inc from native build to target build directory
- Updates tablegen macros to use LLVM_TABLEGEN_EXE variable

Fixes CI failures with error:
  x86_64-binfmt-P: Could not open '/lib64/ld-linux-x86-64.so.2'
Remove X86CompressEVEXTablesEmitter.cpp and X86ManualInstrMapping.cpp
from the native-tblgen source list - these files don't exist in
ClickHouse's LLVM fork.
- Use CMake variables in config.h.in for platform-specific defines
- Set HAVE_MALLINFO only on Linux with glibc (not musl/BSD/macOS)
- Set HAVE_GETAUXVAL only on Linux (it's Linux-specific)
- Set HAVE_MACH_MACH_H, HAVE_MALLOC_MALLOC_H for macOS
- Use st_mtimespec on macOS/FreeBSD, st_mtim on Linux
- Set HAVE_DECL_ARC4RANDOM on macOS/FreeBSD
- Use .dylib extension on macOS, .so elsewhere
- Apply same logic to native-tblgen using CMAKE_HOST_SYSTEM_NAME
- Disable HAVE_BACKTRACE on musl (no execinfo.h)
- Don't link with -ldl on musl (dlopen is in libc)
- Use USE_MUSL variable for proper detection

Assisted-by: Claude Opus 4.5 via GitHub Copilot
…nACC

Remove LLVM components that ClickHouse doesn't need:
- LLVMFrontendOpenACC library (and its tablegen commands)
- Architecture AsmParser libraries (all 5 targets)
- Architecture Disassembler libraries (all 5 targets)
- -gen-disassembler tablegen commands

This reduces build time and binary size without affecting functionality.

Assisted-by: Claude Opus 4.5 via GitHub Copilot
Comment thread contrib/llvm-project-cmake/CMakeLists.txt
Comment thread contrib/llvm-project-cmake/native-tblgen/CMakeLists.txt
Comment thread contrib/llvm-project-cmake/CMakeLists.txt
Comment thread contrib/llvm-project-cmake/CMakeLists.txt
@thevar1able thevar1able marked this pull request as ready for review April 15, 2026 00:41
@thevar1able thevar1able added this pull request to the merge queue Apr 15, 2026
Merged via the queue into master with commit 80c38dd Apr 15, 2026
317 of 318 checks passed
@thevar1able thevar1able deleted the own-cmake-for-llvm branch April 15, 2026 15:35
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-build Pull request with build/testing/packaging improvement pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants