From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: "Michał Górny" <mgorny@gentoo.org>
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 [thread overview]
Message-ID: <20241221160053.780079-8-mgorny@gentoo.org> (raw)
In-Reply-To: <20241221160053.780079-1-mgorny@gentoo.org>
Signed-off-by: Michał Górny <mgorny@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
--
2.47.1
next prev parent reply other threads:[~2024-12-21 16:03 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-21 15:48 [gentoo-dev] [PATCH 00/11] llvm-r2.eclass, to unmess pkg_setup and fix cross Michał Górny
2024-12-21 15:48 ` [gentoo-dev] [PATCH 01/11] llvm-r1.eclass: Fix list in eclassdoc Michał Górny
2024-12-21 15:48 ` [gentoo-dev] [PATCH 02/11] llvm-r2.eclass: Copy from llvm-r1.eclass Michał Górny
2024-12-21 15:48 ` [gentoo-dev] [PATCH 03/11] HACK! llvm-r1 -> llvm-r2 (to ease testing) Michał Górny
2024-12-21 15:48 ` [gentoo-dev] [PATCH 04/11] llvm-utils.eclass: Support -b/-d to llvm_prepend_path Michał Górny
2024-12-21 15:48 ` [gentoo-dev] [PATCH 05/11] llvm-r2.eclass: Readjust for BROOT, split to llvm_cbuild_setup Michał Górny
2024-12-21 15:48 ` [gentoo-dev] [PATCH 06/11] llvm-r2.eclass: Add llvm_chost_setup, set CMake path variables Michał Górny
2024-12-21 15:48 ` Michał Górny [this message]
2024-12-21 15:48 ` [gentoo-dev] [PATCH 08/11] llvm-r2.eclass: Update top-level docs for CBUILD/CHOST support Michał Górny
2024-12-21 15:48 ` [gentoo-dev] [PATCH 09/11] llvm-r2.eclass: Remove obsolete Meson LLVM_CONFIG hack Michał Górny
2024-12-21 15:48 ` [gentoo-dev] [PATCH 10/11] eclass/tests: Copy llvm-r1 tests to llvm-r2.sh Michał Górny
2024-12-21 15:48 ` [gentoo-dev] [PATCH 11/11] eclass/tests/llvm-r2.sh: Add tests for llvm-config Michał Górny
2024-12-30 11:35 ` [gentoo-dev] [PATCH 00/11] llvm-r2.eclass, to unmess pkg_setup and fix cross Michał Górny
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241221160053.780079-8-mgorny@gentoo.org \
--to=mgorny@gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox