From patchwork Mon Sep 15 19:11:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Burton X-Patchwork-Id: 70264 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 013E2CAC598 for ; Mon, 15 Sep 2025 19:11:28 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.1334.1757963478553090893 for ; Mon, 15 Sep 2025 12:11:18 -0700 Authentication-Results: mx.groups.io; dkim=none (message not signed); spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: ross.burton@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CE7341424 for ; Mon, 15 Sep 2025 12:11:09 -0700 (PDT) Received: from cesw-amp-gbt-1s-m12830-04.lab.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B4E083F694 for ; Mon, 15 Sep 2025 12:11:17 -0700 (PDT) From: Ross Burton To: openembedded-core@lists.openembedded.org Subject: [PATCH v3 5/8] llvm: add recipe for just the LLVM libraries Date: Mon, 15 Sep 2025 20:11:06 +0100 Message-ID: <20250915191109.1117663-5-ross.burton@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250915191109.1117663-1-ross.burton@arm.com> References: <20250915191109.1117663-1-ross.burton@arm.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Mon, 15 Sep 2025 19:11:27 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/223502 Whilst it's convenient to build all of the LLVM project in one big recipe, that's not ideal when we may just need LLVM on target and not the rest. Bring back a LLVM recipe that can be used by both clang (shortly) and Rust (in the future) Set the build type to MinSizeRel and DEBUG_LEVELFLAG to -g1 (instead of the default, -g): the LLVM debug symbols are very large (several gigabytes) and this reduces them to hundreds of megabytes. Signed-off-by: Ross Burton --- meta/conf/distro/include/maintainers.inc | 1 + meta/recipes-devtools/clang/llvm_git.bb | 132 +++++++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 meta/recipes-devtools/clang/llvm_git.bb diff --git a/meta/conf/distro/include/maintainers.inc b/meta/conf/distro/include/maintainers.inc index 3ede77df4e0..5588dd4c492 100644 --- a/meta/conf/distro/include/maintainers.inc +++ b/meta/conf/distro/include/maintainers.inc @@ -483,6 +483,7 @@ RECIPE_MAINTAINER:pn-lld = "Khem Raj " RECIPE_MAINTAINER:pn-lldb = "Khem Raj " RECIPE_MAINTAINER:pn-llvm-project-source-21.1.1 = "Khem Raj " RECIPE_MAINTAINER:pn-llvm-tblgen-native = "Khem Raj " +RECIPE_MAINTAINER:pn-llvm = "Khem Raj " RECIPE_MAINTAINER:pn-logrotate = "Yi Zhao " RECIPE_MAINTAINER:pn-log4cplus = "Unassigned " RECIPE_MAINTAINER:pn-lrzsz = "Anuj Mittal " diff --git a/meta/recipes-devtools/clang/llvm_git.bb b/meta/recipes-devtools/clang/llvm_git.bb new file mode 100644 index 00000000000..913fff48082 --- /dev/null +++ b/meta/recipes-devtools/clang/llvm_git.bb @@ -0,0 +1,132 @@ +# Copyright (C) 2017 Khem Raj +# Released under the MIT license (see COPYING.MIT for the terms) + +SUMMARY = "The LLVM Compiler Infrastructure" +HOMEPAGE = "http://llvm.org" +LICENSE = "Apache-2.0-with-LLVM-exception" +SECTION = "devel" + +require common-clang.inc +require common-source.inc + +LIC_FILES_CHKSUM = "file://LICENSE.TXT;md5=8a15a0759ef07f2682d2ba4b893c9afe" + +DEPENDS = "llvm-tblgen-native libffi libxml2 zlib zstd" + +inherit cmake pkgconfig lib_package + +OECMAKE_SOURCEPATH = "${S}/llvm" + +# By default we build all the supported CPU architectures, and the GPU targets +# if the opengl or vulkan DISTRO_FEATURES are enabled. +# +# For target builds we default to building that specific architecture, BPF, and the GPU targets if required. +# +# The available target list can be seen in the source code +# in the LLVM_ALL_TARGETS assignment: +# https://github.com/llvm/llvm-project/blob/main/llvm/CMakeLists.txt +LLVM_TARGETS_GPU ?= "${@bb.utils.contains_any('DISTRO_FEATURES', 'opengl vulkan', 'AMDGPU;NVPTX;SPIRV', '', d)}" +LLVM_TARGETS_TO_BUILD ?= "AArch64;ARM;BPF;Mips;PowerPC;RISCV;X86;LoongArch;${LLVM_TARGETS_GPU}" +LLVM_TARGETS_TO_BUILD:class-target ?= "${@get_clang_host_arch(bb, d)};BPF;${LLVM_TARGETS_GPU}" + +LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ?= "" + +HF = "" +HF:class-target = "${@ bb.utils.contains('TUNE_CCARGS_MFLOAT', 'hard', 'hf', '', d)}" +HF[vardepvalue] = "${HF}" + +EXTRA_OECMAKE += "-DCMAKE_BUILD_TYPE=MinSizeRel \ + -DLLVM_ENABLE_ASSERTIONS=OFF \ + -DLLVM_ENABLE_EXPENSIVE_CHECKS=OFF \ + -DLLVM_ENABLE_PIC=ON \ + -DLLVM_ENABLE_BINDINGS=OFF \ + -DLLVM_ENABLE_FFI=ON \ + -DLLVM_ENABLE_RTTI=ON \ + -DLLVM_TARGETS_TO_BUILD='${LLVM_TARGETS_TO_BUILD}' \ + -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD='${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD}' \ + -DLLVM_LIBDIR_SUFFIX=${LLVM_LIBDIR_SUFFIX} \ + -DLLVM_VERSION_SUFFIX='${VER_SUFFIX}' \ + -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON \ + -DLLVM_INCLUDE_TESTS=OFF \ + -DLLVM_INCLUDE_EXAMPLES=OFF \ + -DLLVM_TOOL_OBJ2YAML_BUILD=OFF \ + -DLLVM_TOOL_YAML2OBJ_BUILD=OFF \ + -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen \ + " + +EXTRA_OECMAKE:append:class-target = "\ + -DLLVM_DEFAULT_TARGET_TRIPLE=${TARGET_SYS}${HF} \ + -DLLVM_TARGET_ARCH=${HOST_ARCH} \ + -DLLVM_HOST_TRIPLE=${TARGET_SYS}${HF} \ + -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config \ + -DLLVM_NATIVE_TOOL_DIR=${STAGING_BINDIR_NATIVE} \ + " + +EXTRA_OECMAKE:append:class-nativesdk = "\ + -DLLVM_HOST_TRIPLE=${SDK_SYS} \ + -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config \ + -DLLVM_NATIVE_TOOL_DIR=${STAGING_BINDIR_NATIVE} \ + " + +PACKAGECONFIG ??= "eh rtti shared-libs ${@bb.utils.filter('DISTRO_FEATURES', 'lto thin-lto', d)}" +PACKAGECONFIG:remove:class-native = "lto thin-lto" + +PACKAGECONFIG[eh] = "-DLLVM_ENABLE_EH=ON,-DLLVM_ENABLE_EH=OFF" +PACKAGECONFIG[exegesis] = "-DLLVM_TOOL_LLVM_EXEGESIS_BUILD=ON,-DLLVM_TOOL_LLVM_EXEGESIS_BUILD=OFF" +PACKAGECONFIG[libedit] = "-DLLVM_ENABLE_LIBEDIT=ON,-DLLVM_ENABLE_LIBEDIT=OFF,libedit" +PACKAGECONFIG[rtti] = "-DLLVM_ENABLE_RTTI=ON,-DLLVM_ENABLE_RTTI=OFF" +PACKAGECONFIG[shared-libs] = "-DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_LINK_LLVM_DYLIB=ON,-DLLVM_BUILD_LLVM_DYLIB=OFF -DLLVM_LINK_LLVM_DYLIB=OFF" +PACKAGECONFIG[split-dwarf] = "-DLLVM_USE_SPLIT_DWARF=ON,-DLLVM_USE_SPLIT_DWARF=OFF" +PACKAGECONFIG[opt-viewer] = "-DLLVM_TOOL_OPT_VIEWER_BUILD=ON,-DLLVM_TOOL_OPT_VIEWER_BUILD=OFF, \ + python3-pyyaml-native python3-pygments-native python3-pyyaml python3-pygments, \ + python3-pyyaml python3-pygments," +PACKAGECONFIG[lto] = "-DLLVM_ENABLE_LTO=Full -DLLVM_BINUTILS_INCDIR=${STAGING_INCDIR},,binutils," +PACKAGECONFIG[thin-lto] = "-DLLVM_ENABLE_LTO=Thin -DLLVM_BINUTILS_INCDIR=${STAGING_INCDIR},,binutils," + +# LLVM debug symbols are very large (several gigabytes), reduce the debug level +# so they're just hundreds of megabytes. +DEBUG_LEVELFLAG = "-g1" + +reproducible_build_variables() { + sed -i -e "s,${DEBUG_PREFIX_MAP},,g" \ + -e "s,--sysroot=${RECIPE_SYSROOT},,g" \ + -e "s,${STAGING_DIR_HOST},,g" \ + -e "s,${S}/llvm,,g" \ + -e "s,${B},,g" \ + ${B}/tools/llvm-config/BuildVariables.inc +} + +do_configure:append:class-target() { + reproducible_build_variables +} +do_configure:append:class-nativesdk() { + reproducible_build_variables +} + +do_install:append() { + # llvm hardcodes lib as install path, this corrects it to actual libdir. + # https://github.com/llvm/llvm-project/issues/152193 + if [ -d ${D}/${prefix}/lib -a ! -d ${D}/${libdir} ]; then + mv ${D}/${prefix}/lib ${D}/${libdir} + fi + + # Reproducibility fixes + sed -i -e 's,${WORKDIR},,g' ${D}/${libdir}/cmake/llvm/LLVMConfig.cmake +} + +do_install:append:class-native() { + # These are provided by llvm-tblgen-native + rm ${D}${bindir}/*-tblgen +} + +SYSROOT_PREPROCESS_FUNCS:append:class-target = " llvm_sysroot_preprocess" +SYSROOT_PREPROCESS_FUNCS:append:class-nativesdk = " llvm_sysroot_preprocess" + +llvm_sysroot_preprocess() { + install -d ${SYSROOT_DESTDIR}${bindir_crossscripts}/ + install -m 0755 ${S}/llvm/tools/llvm-config/llvm-config ${SYSROOT_DESTDIR}${bindir_crossscripts}/ +} + +FILES:${PN}-dev += "${libdir}/llvm-config" + +BBCLASSEXTEND = "native nativesdk"