Files
buildroot/package/llvm-project/clang/clang.mk
El Mehdi YOUNES e29dae109a package/llvm-project: bump to version 20.1.5
Release:
https://github.com/llvm/llvm-project/releases/tag/llvmorg-20.1.5

Major Changes and Fixes:

-- CMake 3.20 minimum required

-- Issue encountered during standalone LLVM build:
    CMake Error at CMakeLists.txt:8 (include):
      include could not find requested file:

  This error is due to the line:
    include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake)

  Upstream commit [1] harmonized policy handling by introducing this shared include
  for all LLVM sub-projects. However, in the LLVM CMakeLists, LLVM_COMMON_CMAKE_UTILS
  is set unconditionally, preventing external override — which is required in
  Buildroot when building from separated archives.

  To solve this:
    We apply a patch to wrap the assignment of LLVM_COMMON_CMAKE_UTILS in an
    `if(NOT DEFINED ...)` block, allowing Buildroot to set the path externally.
    In the `llvm-cmake` package, we also **adjust the installation path** of the
    CMake modules: instead of installing directly into `lib/cmake/llvm`, we now
    install them under `lib/cmake/llvm/Modules` to match the expected layout.

  This ensures that:
    LLVM can include `${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake`
    without errors.

-- Also the Clang build system has removed support for
   the GCC_INSTALL_PREFIX option, raising a fatal error when attempting to use it:

   CMake Error at CMakeLists.txt:211 (message):
      GCC_INSTALL_PREFIX is deprecated and will be removed.
      Use configuration files (https://clang.llvm.org/docs/UsersManual.html#configuration-files)
      to specify the default --gcc-install-dir= or --gcc-triple=.
      --gcc-toolchain= is discouraged.
      See https://github.com/llvm/llvm-project/pull/77537
      for details.

   Remove the use of GCC_INSTALL_PREFIX and replace it with a
   Clang configuration file as recommended by upstream.

   A configuration file is now automatically generated at:
   $(HOST_DIR)/lib/clang/$(CLANG_VERSION_MAJOR)/$(GNU_TARGET_NAME).cfg

   It contains:
   --gcc-install-dir=<path to external toolchain's lib/gcc/...>
   --target=<GNU target triplet>

   We dynamically detect the GCC install path by scanning
   $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/<target>/<version>/

   The Clang toolchain wrapper was also updated to add --config=<file> when
   BR_CLANG_CONFIG_FILE is defined.

-- Fix LLVM_MAIN_SRC_DIR path:
   set(LLVM_MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm" CACHE PATH ...)
   This path isn't correct when using standalone archive builds. We explicitly pass
   LLVM_MAIN_SRC_DIR=$(BUILD_DIR)/llvm-$(LLVM_PROJECT_VERSION) to fix the path. [2]

-- Add LLVM_ENABLE_RUNTIMES:
   Upstream added LLVM_ENABLE_RUNTIMES for runtimes [3]

-- Removed LLVM_INCLUDE_GO_TESTS:
   Upstream dropped this option; we remove it too [4]

-- Disable TensorFlow Lite integration:
   LLVM_HAVE_TFLITE is added to the CMakelist
   We now explicitly disable it to avoid unexpected
   TensorFlow Lite dependency.

-- Clang introduced CLANG_ENABLE_LIBXML2 [5]
   We now explicitly disable it by setting CLANG_ENABLE_LIBXLM2=OFF
   since we set LLVM_ENABLE_LIBXML2 to OFF in LLVM

-- Host-python3, which is now always needed by Clang’s resource bundling
   script. [6]

-- Clang explicitly request to disable llvm tests when llvm_gtest is missing.[7]
   CMake Error at CMakeLists.txt:126 (message):
    llvm-gtest not found. Please install llvm-gtest or disable tests with
    -DLLVM_INCLUDE_TESTS=OFF

-- Also update the installation path in COMPILER_RT_SETUP_RUNTIME_LIBS
   to use CLANG_VERSION_MAJOR instead of HOST_CLANG_VERSION,
   ensuring that the runtime files are placed correctly
   in the /lib/clang/<major>/ folder. [8]

-- Add llvm-runtimes dependency
   libunwind needs runtimes [9]

-- Fix for libclc out of tree patch
   Due to upstream changes in libclc, the old patch no longer
   applies. Only the fix related to invoking './prepare_builtins'
   directly is still relevant and preserved, as it is required to avoid
   a build failure when the binary is not in PATH.

-- Upstream commit [10] removed the use of llvm-config in libclc and
   replaced it with proper use of LLVM_CMAKE_DIR. We now pass
   -DLLVM_CMAKE_DIR instead of DLLVM_CONFIG

-- Libclc expects to invoke some LLVM tools. We explicitly set
   LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR to ensure it finds these tools. [11]

-- Remove LLAsm_COMPILER and CLC_COMPILER [12]

-- LIBUNWIND_INSTALL_HEADERS is On by default [13]

-- Update spirv-llvm-translator to align with LLVM 20.1.5
   Release:
   https://github.com/KhronosGroup/SPIRV-LLVM-Translator/releases/tag/v20.1.2

[1]  9dd01a5241
[2]  d2b158e29e
[3]  176db3b3ab
[4]  6ce8727248
[5]  df239a6c17
[6]  96962d5512
[7]  8216910395
[8]  e1b88c8a09
[9]  0af67d167d
[10] b264787453
[11] 0aeeff3059
[12] 72f9881c3f
[13] f8409af354

Signed-off-by: El Mehdi YOUNES <elmehdi.younes@smile.fr>
Signed-off-by: Bernd Kuhls <bernd@kuhls.net>
[Bernd: rebased, removed gcc-15 patches for llvm 15, bumped to 20.1.5]
        used 'git describe' to set the version number for spirv-llvm-translator]
[Mehdi: changed llvm-runtimes version to $(LLVM_PROJECT_VERSION)]
Signed-off-by: Julien Olivain <ju.o@free.fr>
2025-05-25 16:15:41 +02:00

157 lines
6.2 KiB
Makefile

################################################################################
#
# clang
#
################################################################################
CLANG_VERSION_MAJOR = $(LLVM_PROJECT_VERSION_MAJOR)
CLANG_VERSION = $(LLVM_PROJECT_VERSION)
CLANG_SITE = $(LLVM_PROJECT_SITE)
CLANG_SOURCE = clang-$(CLANG_VERSION).src.tar.xz
CLANG_LICENSE = Apache-2.0 with exceptions
CLANG_LICENSE_FILES = LICENSE.TXT
CLANG_CPE_ID_VENDOR = llvm
CLANG_SUPPORTS_IN_SOURCE_BUILD = NO
CLANG_INSTALL_STAGING = YES
HOST_CLANG_DEPENDENCIES = host-llvm host-libxml2 host-python3
CLANG_DEPENDENCIES = llvm host-clang
# since we have LLVM_ENABLE_LIBXML2=OFF, set CLANG_ENABLE_LIBXML2=OFF
CLANG_CONF_OPTS += -DCLANG_ENABLE_LIBXML2=OFF
# This option is needed, otherwise multiple shared libs
# (libclangAST.so, libclangBasic.so, libclangFrontend.so, etc.) will
# be generated. As a final shared lib containing all these components
# (libclang.so) is also generated, this resulted in the following
# error when trying to use tools that use libclang:
# $ CommandLine Error: Option 'track-memory' registered more than once!
# $ LLVM ERROR: inconsistency in registered CommandLine options
# By setting BUILD_SHARED_LIBS to OFF, we generate multiple static
# libraries (the same way as host's clang build) and finally
# libclang.so to be installed on the target.
HOST_CLANG_CONF_OPTS += -DBUILD_SHARED_LIBS=OFF
CLANG_CONF_OPTS += -DBUILD_SHARED_LIBS=OFF
# Default is Debug build, which requires considerably more disk space
# and build time. Release build is selected for host and target
# because the linker can run out of memory in Debug mode.
HOST_CLANG_CONF_OPTS += -DCMAKE_BUILD_TYPE=Release
CLANG_CONF_OPTS += -DCMAKE_BUILD_TYPE=Release
CLANG_CONF_OPTS += -DCMAKE_CROSSCOMPILING=1
# We need to build tools because libclang is a tool
HOST_CLANG_CONF_OPTS += -DCLANG_BUILD_TOOLS=ON
CLANG_CONF_OPTS += -DCLANG_BUILD_TOOLS=ON
HOST_CLANG_CONF_OPTS += \
-DCLANG_BUILD_EXAMPLES=OFF \
-DCLANG_INCLUDE_DOCS=OFF \
-DCLANG_INCLUDE_TESTS=OFF \
-DLLVM_INCLUDE_TESTS=OFF
CLANG_CONF_OPTS += \
-DCLANG_BUILD_EXAMPLES=OFF \
-DCLANG_INCLUDE_DOCS=OFF \
-DCLANG_INCLUDE_TESTS=OFF \
-DLLVM_INCLUDE_TESTS=OFF
HOST_CLANG_CONF_OPTS += -DLLVM_DIR=$(HOST_DIR)/lib/cmake/llvm \
-DCLANG_DEFAULT_LINKER=$(TARGET_LD)
CLANG_CONF_OPTS += -DLLVM_DIR=$(STAGING_DIR)/usr/lib/cmake/llvm \
-DCMAKE_MODULE_PATH=$(HOST_DIR)/lib/cmake/llvm \
-DCLANG_TABLEGEN:FILEPATH=$(HOST_DIR)/bin/clang-tblgen \
-DLLVM_TABLEGEN_EXE:FILEPATH=$(HOST_DIR)/bin/llvm-tblgen
HOST_CLANG_CONF_OPTS += -DLLVM_COMMON_CMAKE_UTILS=$(HOST_DIR)/lib/cmake/llvm
CLANG_CONF_OPTS += -DLLVM_COMMON_CMAKE_UTILS=$(HOST_DIR)/lib/cmake/llvm
+HOST_CLANG_CONF_OPTS += -DLLVM_MAIN_SRC_DIR=$(BUILD_DIR)/llvm-$(LLVM_PROJECT_VERSION)
+CLANG_CONF_OPTS += -DLLVM_MAIN_SRC_DIR=$(BUILD_DIR)/llvm-$(LLVM_PROJECT_VERSION)
# Clang can't be used as compiler on the target since there are no
# development files (headers) and other build tools. So remove clang
# binaries and some other unnecessary files from target.
CLANG_FILES_TO_REMOVE = \
/usr/bin/clang* \
/usr/bin/c-index-test \
/usr/bin/git-clang-format \
/usr/bin/scan-build \
/usr/bin/scan-view \
/usr/libexec/c++-analyzer \
/usr/libexec/ccc-analyzer \
/usr/share/clang \
/usr/share/opt-viewer \
/usr/share/scan-build \
/usr/share/scan-view \
/usr/share/man/man1/scan-build.1 \
/usr/lib/clang
define CLANG_CLEANUP_TARGET
rm -rf $(addprefix $(TARGET_DIR),$(CLANG_FILES_TO_REMOVE))
endef
CLANG_POST_INSTALL_TARGET_HOOKS += CLANG_CLEANUP_TARGET
# clang-tblgen is not installed by default, however it is necessary
# for cross-compiling clang
define HOST_CLANG_INSTALL_CLANG_TBLGEN
$(INSTALL) -D -m 0755 $(HOST_CLANG_BUILDDIR)/bin/clang-tblgen \
$(HOST_DIR)/bin/clang-tblgen
endef
HOST_CLANG_POST_INSTALL_HOOKS = HOST_CLANG_INSTALL_CLANG_TBLGEN
# This option must be enabled to link libclang dynamically against libLLVM.so
HOST_CLANG_CONF_OPTS += -DLLVM_LINK_LLVM_DYLIB=ON
CLANG_CONF_OPTS += -DLLVM_LINK_LLVM_DYLIB=ON
# Prevent clang binaries from linking against LLVM static libs
HOST_CLANG_CONF_OPTS += -DLLVM_DYLIB_COMPONENTS=all
CLANG_CONF_OPTS += -DLLVM_DYLIB_COMPONENTS=all
# Help host-clang to find our external toolchain, use a relative path from the clang
# installation directory to the external toolchain installation directory in order to
# not hardcode the toolchain absolute path.
ifeq ($(BR2_TOOLCHAIN_EXTERNAL),y)
define HOST_CLANG_INSTALL_CONFIG_FILE
mkdir -p $(HOST_DIR)/lib/clang/$(CLANG_VERSION_MAJOR)
touch $(HOST_DIR)/lib/clang/$(CLANG_VERSION_MAJOR)/$(GNU_TARGET_NAME).cfg
echo "--gcc-install-dir=$(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/$$(ls $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/)/$$(ls $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/$$(ls $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)/lib/gcc/)/)" > $(HOST_DIR)/lib/clang/$(CLANG_VERSION_MAJOR)/$(GNU_TARGET_NAME).cfg
echo "--target=$(GNU_TARGET_NAME)" >> $(HOST_DIR)/lib/clang/$(CLANG_VERSION_MAJOR)/$(GNU_TARGET_NAME).cfg
endef
HOST_CLANG_POST_INSTALL_HOOKS += HOST_CLANG_INSTALL_CONFIG_FILE
HOST_CLANG_TOOLCHAIN_WRAPPER_ARGS += -DBR_CLANG_CONFIG_FILE="\"--config=$(HOST_DIR)/lib/clang/$(CLANG_VERSION_MAJOR)/$(GNU_TARGET_NAME).cfg\""
endif
define HOST_CLANG_INSTALL_WRAPPER_AND_SIMPLE_SYMLINKS
$(Q)cd $(HOST_DIR)/bin; \
rm -f clang-$(CLANG_VERSION_MAJOR).br_real; \
mv clang-$(CLANG_VERSION_MAJOR) clang-$(CLANG_VERSION_MAJOR).br_real; \
ln -sf toolchain-wrapper-clang clang-$(CLANG_VERSION_MAJOR); \
for i in clang clang++ clang-cl clang-cpp; do \
ln -snf toolchain-wrapper-clang $$i; \
ln -snf clang-$(CLANG_VERSION_MAJOR).br_real $$i.br_real; \
done
endef
define HOST_CLANG_TOOLCHAIN_WRAPPER_BUILD
$(HOSTCC) $(HOST_CFLAGS) $(TOOLCHAIN_WRAPPER_ARGS) \
-s -Wl,--hash-style=$(TOOLCHAIN_WRAPPER_HASH_STYLE) \
toolchain/toolchain-wrapper.c \
-o $(@D)/toolchain-wrapper-clang
endef
define HOST_CLANG_TOOLCHAIN_WRAPPER_INSTALL
$(INSTALL) -D -m 0755 $(@D)/toolchain-wrapper-clang \
$(HOST_DIR)/bin/toolchain-wrapper-clang
endef
HOST_CLANG_TOOLCHAIN_WRAPPER_ARGS += -DBR_CROSS_PATH_SUFFIX='".br_real"'
HOST_CLANG_POST_BUILD_HOOKS += HOST_CLANG_TOOLCHAIN_WRAPPER_BUILD
HOST_CLANG_POST_INSTALL_HOOKS += HOST_CLANG_TOOLCHAIN_WRAPPER_INSTALL
HOST_CLANG_POST_INSTALL_HOOKS += HOST_CLANG_INSTALL_WRAPPER_AND_SIMPLE_SYMLINKS
$(eval $(cmake-package))
$(eval $(host-cmake-package))