commit:     33f22ac2fd51aa5ad16ffd1840f0349ad8a2984f
Author:     sin-ack <sin-ack <AT> protonmail <DOT> com>
AuthorDate: Thu Jan  2 15:59:57 2025 +0000
Commit:     Joonas Niilola <juippis <AT> gentoo <DOT> org>
CommitDate: Wed Jan  8 06:32:59 2025 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=33f22ac2

zig-utils.eclass: add ZIG_NEEDS_LLVM variable

If set to a non-empty value, the package will BDEPEND on a Zig package
with LLVM enabled. This is currently required for packages that require
C/C++ source files to be compiled with Zig.

There's some special logic required to detect which Zig binary we should
actually use, because we may have dev-lang/zig[-llvm] installed with
dev-lang/zig-bin (in which case we would need to pick zig-bin over zig).

Tested in a clean stage3 chroot with dev-lang/zig[-llvm] and
dev-lang/zig-bin installed, in which case zig-utils.eclass will pick
zig-bin over zig.

Co-authored-by: Eric Joldasov <bratishkaerik <AT> landless-city.net>
Signed-off-by: sin-ack <sin-ack <AT> protonmail.com>
Signed-off-by: Joonas Niilola <juippis <AT> gentoo.org>

 eclass/zig-utils.eclass | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/eclass/zig-utils.eclass b/eclass/zig-utils.eclass
index ca72e89ed6ea..5502d997935e 100644
--- a/eclass/zig-utils.eclass
+++ b/eclass/zig-utils.eclass
@@ -1,4 +1,4 @@
-# Copyright 2024 Gentoo Authors
+# Copyright 2024-2025 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 # @ECLASS: zig-utils.eclass
@@ -54,6 +54,14 @@ inherit edo flag-o-matic linux-info
 # and most likely changed to more common in other eclasses ZIG_MIN/
 # ZIG_MAX form.
 
+# @ECLASS_VARIABLE: ZIG_NEEDS_LLVM
+# @PRE_INHERIT
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# If set to a non-empty value, the package will BDEPEND on a Zig package
+# with LLVM enabled.  This is currently required for packages that require
+# C/C++ source files to be compiled with Zig.
+
 # @ECLASS_VARIABLE: ZIG_OPTIONAL
 # @PRE_INHERIT
 # @DEFAULT_UNSET
@@ -69,9 +77,15 @@ inherit edo flag-o-matic linux-info
 # For zig.eclass users: see documentation in zig.eclass
 # instead.
 if [[ ! ${ZIG_OPTIONAL} ]]; then
+       _ZIG_USEDEP=""
+       if [[ ${ZIG_NEEDS_LLVM} ]]; then
+               _ZIG_USEDEP="[llvm(+)]"
+       fi
+
+       # NOTE: zig-bin is always built with LLVM support, so no USE needed.
        BDEPEND="
                || (
-                       dev-lang/zig:${ZIG_SLOT}
+                       dev-lang/zig:${ZIG_SLOT}${_ZIG_USEDEP}
                        dev-lang/zig-bin:${ZIG_SLOT}
                )
        "
@@ -440,6 +454,10 @@ zig-utils_find_installation() {
 
        local base_path="${BROOT}/usr/bin"
 
+       local -x ZIG_GLOBAL_CACHE_DIR="${T}/zig-detect"
+       mkdir -p "${ZIG_GLOBAL_CACHE_DIR}" || die
+       touch "${ZIG_GLOBAL_CACHE_DIR}/empty.zig" || die
+
        local selected_path selected_ver
        for selected_ver in "${zig_supported_versions[@]}"; do
                # Check if candidate satisfies ZIG_SLOT condition.
@@ -451,6 +469,9 @@ zig-utils_find_installation() {
                local candidate_path
                for candidate_path in 
"${base_path}"/zig{,-bin}-"${selected_ver}"; do
                        if [[ -x "${candidate_path}" ]]; then
+                               if [[ ${ZIG_NEEDS_LLVM} ]]; then
+                                       "${candidate_path}" test -fllvm 
-OReleaseSmall "${ZIG_GLOBAL_CACHE_DIR}/empty.zig" &> /dev/null || continue
+                               fi
                                selected_path="${candidate_path}"
                                break 2
                        fi

Reply via email to