public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: "Michał Górny" <mgorny@gentoo.org>
Subject: [gentoo-dev] [PATCH 06/11] llvm-r2.eclass: Add llvm_chost_setup, set CMake path variables
Date: Sat, 21 Dec 2024 16:48:39 +0100	[thread overview]
Message-ID: <20241221160053.780079-7-mgorny@gentoo.org> (raw)
In-Reply-To: <20241221160053.780079-1-mgorny@gentoo.org>

Add a llvm_chost_setup function that handles CHOST-specific setup.
Initially, this means setting CMake variables that control
`find_package()` lookups.

Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
 eclass/llvm-r2.eclass | 37 ++++++++++++++++++++++++++++++-------
 1 file changed, 30 insertions(+), 7 deletions(-)

diff --git a/eclass/llvm-r2.eclass b/eclass/llvm-r2.eclass
index 93c16e75be83..91e841821331 100644
--- a/eclass/llvm-r2.eclass
+++ b/eclass/llvm-r2.eclass
@@ -248,16 +248,35 @@ llvm_cbuild_setup() {
 	llvm_prepend_path -b "${LLVM_SLOT}"
 }
 
-# @FUNCTION: llvm-r2_pkg_setup
+# @FUNCTION: llvm_chost_setup
 # @DESCRIPTION:
-# Prepend the appropriate executable directory for the selected LLVM
-# slot to PATH.
+# Set the environment for finding selected LLVM slot installed
+# for CHOST.
 #
-# The PATH manipulation is only done for source builds. The function
-# is a no-op when installing a binary package.
+# 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.
+llvm_chost_setup() {
+	debug-print-function ${FUNCNAME} "$@"
+
+	local esysroot_prefix=$(get_llvm_prefix -d)
+	einfo "Using ${esysroot_prefix} for CHOST LLVM ${LLVM_SLOT}"
+	[[ -d ${esysroot_prefix} ]] ||
+		die "LLVM ${LLVM_SLOT} not found installed in ESYSROOT (expected: ${esysroot_prefix})"
+
+	# satisfies find_package() in CMake
+	export LLVM_ROOT="${esysroot_prefix}"
+	export Clang_ROOT="${esysroot_prefix}"
+	export LLD_ROOT="${esysroot_prefix}"
+}
+
+# @FUNCTION: llvm-r2_pkg_setup
+# @DESCRIPTION:
+# Handle all supported setup actions automatically.  If LLVM is found
+# installed for CBUILD, call llvm_cbuild_setup.  If it is found
+# installed for CHOST, call llvm_chost_setup.
 #
-# If any other behavior is desired, the contents of the function
-# should be inlined into the ebuild and modified as necessary.
+# This function is a no-op when installing a binary package.
 #
 # Note that this function is not exported if LLVM_OPTIONAL is set.
 # In that case, it needs to be called manually.
@@ -270,6 +289,10 @@ llvm-r2_pkg_setup() {
 		if [[ -d $(get_llvm_prefix -b)/bin ]]; then
 			llvm_cbuild_setup
 		fi
+
+		if [[ -d $(get_llvm_prefix -d) ]]; then
+			llvm_chost_setup
+		fi
 	fi
 }
 
-- 
2.47.1



  parent reply	other threads:[~2024-12-21 16:02 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 ` Michał Górny [this message]
2024-12-21 15:48 ` [gentoo-dev] [PATCH 07/11] llvm-r2.eclass: Generate a llvm-config script for CHOST Michał Górny
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-7-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