From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 6089415812D for ; Mon, 30 Dec 2024 11:35:09 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 38748E0830; Mon, 30 Dec 2024 11:35:08 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 1AF4CE082D for ; Mon, 30 Dec 2024 11:35:08 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 2AD44335CAF for ; Mon, 30 Dec 2024 11:35:07 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 45C82191A for ; Mon, 30 Dec 2024 11:35:04 +0000 (UTC) From: "Michał Górny" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Michał Górny" Message-ID: <1735558351.9675dfad09d92b64ea05adabbd2ea9bbe221de59.mgorny@gentoo> Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/ X-VCS-Repository: repo/gentoo X-VCS-Files: eclass/llvm-r2.eclass X-VCS-Directories: eclass/ X-VCS-Committer: mgorny X-VCS-Committer-Name: Michał Górny X-VCS-Revision: 9675dfad09d92b64ea05adabbd2ea9bbe221de59 X-VCS-Branch: master Date: Mon, 30 Dec 2024 11:35:04 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 56760ae7-3f34-40c5-8344-d59a3e8a692b X-Archives-Hash: ecacaf5c7a20af8e741422a3f3911af9 commit: 9675dfad09d92b64ea05adabbd2ea9bbe221de59 Author: Michał Górny gentoo org> AuthorDate: Mon Dec 16 10:37:29 2024 +0000 Commit: Michał Górny gentoo org> CommitDate: Mon Dec 30 11:32:31 2024 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=9675dfad llvm-r2.eclass: Generate a llvm-config script for CHOST Signed-off-by: Michał Górny gentoo.org> eclass/llvm-r2.eclass | 173 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 172 insertions(+), 1 deletion(-) diff --git a/eclass/llvm-r2.eclass b/eclass/llvm-r2.eclass index 91e841821331..e499f9dba38d 100644 --- a/eclass/llvm-r2.eclass +++ b/eclass/llvm-r2.eclass @@ -216,6 +216,162 @@ get_llvm_prefix() { echo "${prefix}/usr/lib/llvm/${LLVM_SLOT}" } +# @FUNCTION: generate_llvm_config +# @DESCRIPTION: +# Output a llvm-config compatible script that yields paths specific +# to the requested LLVM version. +generate_llvm_config() { + debug-print-function ${FUNCNAME} "$@" + + local bindir=$(get_llvm_prefix -b)/bin + [[ ! -d ${bindir} ]] && bindir= + + local prefix=$(get_llvm_prefix -d) + local includedir=${prefix}/include + local libdir=${prefix}/$(get_libdir) + local cmake_conf=${libdir}/cmake/llvm/LLVMConfig.cmake + if [[ ! -f ${cmake_conf} ]]; then + cat <<-EOF + #!/usr/bin/env sh + echo "LLVM ${LLVM_SLOT} not installed for ABI=${ABI}" >&2 + exit 127 + EOF + return + fi + + local version=$( + sed -ne 's:set(LLVM_PACKAGE_VERSION \(.*\)):\1:p' "${cmake_conf}" || die + ) + [[ -n ${version} ]] || die + local cppdefs=$( + sed -ne 's:set(LLVM_DEFINITIONS "\(.*\)"):\1:p' "${cmake_conf}" || die + ) + [[ -n ${cppdefs} ]] || die + local targets=$( + sed -ne 's:set(LLVM_TARGETS_TO_BUILD \(.*\)):\1:p' "${cmake_conf}" || die + ) + [[ -n ${targets} ]] || die + local libs=$( + sed -ne 's:set(LLVM_AVAILABLE_LIBS \(.*\)):\1:p' "${cmake_conf}" || die + ) + [[ -n ${libs} ]] || die + local target_triple=$( + sed -ne 's:set(LLVM_TARGET_TRIPLE "\(.*\)"):\1:p' "${cmake_conf}" || die + ) + [[ -n ${target_triple} ]] || die + + readarray -d';' -t targets <<<"${targets}" + readarray -d';' -t libs <<<"${libs}" + # easier than parsing CMake booleans + local assertions=OFF + [[ ${cppdefs} == *-D_DEBUG* ]] && assertions=ON + # major + suffix + local shlib_name=LLVM-${version%%.*} + [[ ${version} == *git* ]] && shlib_name+="git${version##*git}" + + local components=( + "${libs[@]#LLVM}" "${targets[@]}" + # special component groups (grep for add_llvm_component_group) + all all-targets engine native nativecodegen + ) + + cat <<-EOF + #!/usr/bin/env sh + + echo "\${0} \${*}" >> "${T}/llvm-config-calls.txt" + + do_echo() { + echo " \${*}" >> "${T}/llvm-config-calls.txt" + echo "\${@}" + } + + for arg; do + case \${arg} in + --assertion-mode) + do_echo "${assertions}" + ;; + --bindir) + if [ -n "${bindir}" ]; then + do_echo "${bindir}" + else + do_echo "CBUILD LLVM not available" >&2 + exit 1 + fi + ;; + --build-mode) + do_echo RelWithDebInfo + ;; + --build-system) + do_echo cmake + ;; + --cflags|--cppflags) + do_echo "-I${includedir} ${cppdefs[*]}" + ;; + --cmakedir) + do_echo "${libdir}/cmake/llvm" + ;; + --components) + do_echo "${components[*],,}" + ;; + --cxxflags) + do_echo "-I${includedir} -std=c++17 ${cppdefs[*]}" + ;; + --has-rtti) + do_echo YES + ;; + --host-target) + do_echo "${target_triple}" + ;; + --ignore-libllvm) + # ignored + ;; + --includedir) + do_echo "${includedir}" + ;; + --ldflags) + do_echo "-L${libdir}" + ;; + --libdir) + do_echo "${libdir}" + ;; + --libfiles) + do_echo "${libdir}/lib${shlib_name}.so" + ;; + --libnames) + do_echo lib${shlib_name}.so + ;; + --libs) + do_echo "-l${shlib_name}" + ;; + --link-shared|--link-static) + # ignored + ;; + --obj-root|--prefix) + do_echo "${prefix}" + ;; + --shared-mode) + do_echo shared + ;; + --system-libs) + do_echo + ;; + --targets-built) + do_echo "${targets[*]}" + ;; + --version) + do_echo "${version}" + ;; + -*) + do_echo "Unsupported option: \${arg}" >&2 + exit 1 + ;; + *) + # ignore components, we always return the dylib + ;; + esac + done + EOF +} # @FUNCTION: llvm_cbuild_setup # @DESCRIPTION: # Prepend the PATH for selected LLVM version in CBUILD. @@ -251,11 +407,14 @@ llvm_cbuild_setup() { # @FUNCTION: llvm_chost_setup # @DESCRIPTION: # Set the environment for finding selected LLVM slot installed -# for CHOST. +# for CHOST. Create llvm-config wrappers to satisfy legacy lookups. # # This function is meant to be used when the package in question uses # LLVM compiles against and links to LLVM. It is called automatically # by llvm-r2_pkg_setup if LLVM is found installed in ESYSROOT. +# +# Note that the generated llvm-config may refer to CBUILD installation +# of LLVM via --bindir, if it is found available. llvm_chost_setup() { debug-print-function ${FUNCNAME} "$@" @@ -268,6 +427,18 @@ llvm_chost_setup() { export LLVM_ROOT="${esysroot_prefix}" export Clang_ROOT="${esysroot_prefix}" export LLD_ROOT="${esysroot_prefix}" + + # satisfies llvm-config calls, e.g. from meson + export PATH="${T}/llvm-bin:${PATH}" + mkdir "${T}"/llvm-bin || die + # we need to generate it per-ABI, since libdir changes + local ABI + for ABI in $(get_all_abis); do + local path="${T}/llvm-bin/$(get_abi_CHOST)-llvm-config" + generate_llvm_config > "${path}" || die + chmod +x "${path}" || die + done + ln -s "$(get_abi_CHOST)-llvm-config" "${T}/llvm-bin/llvm-config" || die } # @FUNCTION: llvm-r2_pkg_setup