commit:     c136dc6fcea6f18a2857c2de4b58ff5cbb1a008e
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Sat Aug 23 17:53:23 2025 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Sat Aug 23 18:43:19 2025 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=c136dc6f

sci-libs/flexiblas: Enable mkl, add more checks

Enable support for mkl, including gnu-openmp and tbb variants.
Unfortunately, the "iomp" variant that we're hijacking
for llvm-runtimes/openmp is only supported with Intel compilers
in FlexiBLAS.

Prepare the tests for nonfatal runs, once cmake.eclass is fixed.
Skip testing on mkl since it's known to fail.

Add install-time built backend verification to catch failed CMake
checks even if the user isn't running tests.

Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 sci-libs/flexiblas/flexiblas-3.4.82.ebuild | 83 ++++++++++++++++++++++++++----
 sci-libs/flexiblas/metadata.xml            |  5 ++
 2 files changed, 78 insertions(+), 10 deletions(-)

diff --git a/sci-libs/flexiblas/flexiblas-3.4.82.ebuild 
b/sci-libs/flexiblas/flexiblas-3.4.82.ebuild
index 4567dfaaddb1..015a92dfda1f 100644
--- a/sci-libs/flexiblas/flexiblas-3.4.82.ebuild
+++ b/sci-libs/flexiblas/flexiblas-3.4.82.ebuild
@@ -3,7 +3,7 @@
 
 EAPI=8
 
-inherit cmake toolchain-funcs
+inherit cmake multilib toolchain-funcs
 
 MY_P=flexiblas-release-v${PV}
 DESCRIPTION="A BLAS and LAPACK wrapper library with runtime exchangable 
backends"
@@ -19,13 +19,18 @@ S=${WORKDIR}/${MY_P}
 # BSD for vendored cblas/lapacke
 LICENSE="LGPL-3+ BSD"
 SLOT="0"
-# TODO: mkl, 64bit-index
-IUSE="blis openblas openmp test"
+# TODO: 64bit-index
+IUSE="blis mkl openblas openmp tbb test"
 RESTRICT="!test? ( test )"
 
+# flexiblas only supports gnu-openmp using clang/gcc
 DEPEND="
        sci-libs/lapack:=[deprecated]
        blis? ( sci-libs/blis:=[-64bit-index] )
+       mkl? (
+               sci-libs/mkl:=[tbb?]
+               openmp? ( sci-libs/mkl[gnu-openmp] )
+       )
        openblas? ( sci-libs/openblas:= )
 "
 RDEPEND="
@@ -53,8 +58,8 @@ src_prepare() {
 }
 
 src_configure() {
-       EXTRA_BACKENDS=( $(usev blis) $(usev openblas) )
-       local extra=${EXTRA_BACKENDS[*]}
+       BACKENDS=( $(usev blis) $(usev openblas) )
+       local extra=${BACKENDS[*]}
        local libdir="${ESYSROOT}/usr/$(get_libdir)"
        local mycmakeargs=(
                -DTESTS=$(usex test)
@@ -64,9 +69,25 @@ src_configure() {
                -DLAPACK=ON
                -DLINK_OPENMP=$(usex openmp)
                -DEXAMPLES=OFF
-               # disable autodetection, we don't want automagic deps
-               # plus openblas/blis gets hardcoded as openmp/pthread/serial
-               -DBLAS_AUTO_DETECT=OFF
+               # we need to enable autodetection for mkl
+               -DBLAS_AUTO_DETECT=ON
+               # ...so we need to explicitly disable autodetecting other 
libraries
+               # that would be pinned to their openmp/pthread/serial variants
+               -DOpenBLASSerial=OFF
+               -DOpenBLASPThread=OFF
+               -DOpenBLASOpenMP=OFF
+               -DBlisSerial=OFF
+               -DBlisPThread=OFF
+               -DBlisOpenMP=OFF
+               # variants we use autodetection for
+               -DMklSerial=$(usex mkl ON OFF)
+               -DMklOpenMP=$(usex mkl "$(usex openmp ON OFF)" OFF)
+               -DMklTBB=$(usex mkl "$(usex tbb ON OFF)" OFF)
+               # unsupported
+               -DCMAKE_DISABLE_FIND_PACKAGE_nvpl=ON
+               -DATLAS=OFF
+               -DTATLAS=OFF
+               # and then enable our custom names via EXTRA
                -DEXTRA="${extra// /;}"
                # respect CFLAGS
                -DLTO=OFF
@@ -79,22 +100,64 @@ src_configure() {
        )
 
        cmake_src_configure
+
+       BACKENDS+=( netlib )
+       if use mkl; then
+               BACKENDS+=(
+                       MklSerial
+                       $(usev openmp MklOpenMP)
+                       $(usev tbb MklTBB)
+               )
+       fi
 }
 
 src_test() {
        # We run tests in parallel, so avoid having n^2 threads.
        local -x BLIS_NUM_THREADS=1
+       local -x MKL_NUM_THREADS=1
        local -x OMP_NUM_THREADS=1
        local -x OPENBLAS_NUM_THREADS=1
 
+       local failures=()
        local backend
-       for backend in netlib "${EXTRA_BACKENDS[@]}"; do
+       for backend in "${BACKENDS[@]}"; do
+               # TODO: remove this, and XFAIL them properly when cmake.eclass
+               # is fixed to respect nonfatal, https://bugs.gentoo.org/961929
+               if [[ ${backend} == Mkl* ]]; then
+                       einfo "Skipping ${backend} tests, XFAIL"
+                       continue
+               fi
+
                local -x FLEXIBLAS_TEST=${backend}
                local log=${BUILD_DIR}/Testing/Temporary/LastTest.log
                einfo "Testing backend ${backend}"
-               cmake_src_test
+               if ! nonfatal cmake_src_test; then
+                       failures+=( "${backend}" )
+               fi
                if grep -q 'BLAS backend .* not found' "${log}"; then
                        die "Backend ${backend} failed to load while testing, 
see ${log}"
                fi
        done
+
+       if [[ ${failures[@]} ]]; then
+               die "Test runs failed for backends: ${failures[*]}"
+       fi
+}
+
+src_install() {
+       cmake_src_install
+
+       # verify built backends
+       cd "${ED}/usr/$(get_libdir)/flexiblas" || die
+       local missing=()
+       local backend
+       for backend in "${BACKENDS[@]}"; do
+               if [[ ! -f libflexiblas_${backend,,}$(get_libname) ]]; then
+                       missing+=( "${backend}" )
+               fi
+       done
+
+       if [[ ${missing[@]} ]]; then
+               die "Not all requested backends built. Missing: ${missing[*]}"
+       fi
 }

diff --git a/sci-libs/flexiblas/metadata.xml b/sci-libs/flexiblas/metadata.xml
index c91166300541..5d259655d445 100644
--- a/sci-libs/flexiblas/metadata.xml
+++ b/sci-libs/flexiblas/metadata.xml
@@ -7,6 +7,11 @@
        </maintainer>
        <use>
                <flag name="blis">Support <pkg>sci-libs/blis</pkg> 
provider</flag>
+               <flag name="mkl">Support <pkg>sci-libs/mkl</pkg> provider</flag>
                <flag name="openblas">Support <pkg>sci-libs/openblas</pkg> 
provider</flag>
+               <flag name="tbb">
+                       Support <pkg>sci-libs/mkl</pkg> with 
<pkg>dev-cpp/tbb</pkg>
+                       threading.
+               </flag>
        </use>
 </pkgmetadata>

Reply via email to