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 9F8531580FD for ; Sat, 21 Dec 2024 16:03:11 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 25D7BE09FB; Sat, 21 Dec 2024 16:01:06 +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 D1C50E09F3 for ; Sat, 21 Dec 2024 16:01:05 +0000 (UTC) From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= To: gentoo-dev@lists.gentoo.org Cc: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Subject: [gentoo-dev] [PATCH 07/11] llvm-r2.eclass: Generate a llvm-config script for CHOST Date: Sat, 21 Dec 2024 16:48:40 +0100 Message-ID: <20241221160053.780079-8-mgorny@gentoo.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241221160053.780079-1-mgorny@gentoo.org> References: <20241221160053.780079-1-mgorny@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Archives-Salt: 8cde84f7-52a1-4642-9a65-751293d23246 X-Archives-Hash: c9c11c920357ca37121f285b5309b036 Signed-off-by: Michał Górny --- 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 -- 2.47.1