commit:     5551581b60999fdaf3fd50b7990472e2d477f44f
Author:     Paul Zander <negril.nx+gentoo <AT> gmail <DOT> com>
AuthorDate: Sun Jun  8 12:03:03 2025 +0000
Commit:     David Roman <davidroman96 <AT> gmail <DOT> com>
CommitDate: Wed Jun 11 11:50:48 2025 +0000
URL:        https://gitweb.gentoo.org/repo/proj/guru.git/commit/?id=5551581b

sci-ml/ollama: add 0.9.0

Signed-off-by: Paul Zander <negril.nx+gentoo <AT> gmail.com>

 sci-ml/ollama/Manifest            |   2 +
 sci-ml/ollama/ollama-0.9.0.ebuild | 308 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 310 insertions(+)

diff --git a/sci-ml/ollama/Manifest b/sci-ml/ollama/Manifest
index a3655f32bb..8ee307089a 100644
--- a/sci-ml/ollama/Manifest
+++ b/sci-ml/ollama/Manifest
@@ -10,3 +10,5 @@ DIST ollama-0.7.1-vendor.tar.xz 4410404 BLAKE2B 
5174658814f562ed2d57e4af911231c8
 DIST ollama-0.7.1.gh.tar.gz 8359685 BLAKE2B 
43a6cbd3d5af6f25fa85263d02573ac843d11e22ffe1dfd16f8129ea4f64b806b37defbaee10e940ddffe4289e949316f135cdbcf9c94d302ff6864d2c904557
 SHA512 
58f8fcbd65a3457d0bae1106589cb585ef4afca7e637458a538fc21dd402a4b7ad1a0a99979abda330a65dcac238729eff8d0708fa3085554a9af81f70fbd015
 DIST ollama-0.8.0-vendor.tar.xz 4407120 BLAKE2B 
db48867f9cbb01fff84d79c278bae4c3e6d069f28153fcdeaf0c74a7ecc0bb75d1d4027a0d08b21fe1c1d9b8d1fbaf55fb3c450415d208d20823a577bb739be2
 SHA512 
8ff8442bcf5fc84f66f39b2208b9b1c3cd7f33df5ce76d1dd1ae0676b95c543407ee08a7258e7c70fff519eb3a22eb5378e04187ebc9d0806868bd51fd060e75
 DIST ollama-0.8.0.gh.tar.gz 8345667 BLAKE2B 
d04b498ef5e108e6740d7c79efd1e100bf8cf004f736d31964318b9fe3f5860b91e221488e24e07abe2f28668c0d04aa333b9a5829957eaaeb7c00078f76e2c4
 SHA512 
c5a45fb86ec8472fe27dd2e4f3f597a7bfb5fa4a954332b4cde3ffa961feb8983ffeeec213bd2e59a02896dba683e9462572bb4a1b0e931e67adca3120a0b830
+DIST ollama-0.9.0-vendor.tar.xz 4412428 BLAKE2B 
8d84c7020d350cf6aaf67216ef37be69676ca781b30ab8768d36776b19e7b988a662cf34bbebd514809c91f9e81bd6fb2c1e2b17f4fb668cc25e261553597dfd
 SHA512 
7127e2e7fc3e9a13f3b6e0124c5ab8f41f4444a4b5ba30bef24d0c6b7caa52db9840e11133ff09850094997f88c6c6ca9cadf17b5129c65b295f4c34594d37d3
+DIST ollama-0.9.0.gh.tar.gz 8353746 BLAKE2B 
14b685fdc017c0a0485917d3690430e5205366de94291623f07cb3b9c9862ba96894b62ba4798876f841cb3a3ee7497dbae71b253bfb513556bdfc9153deb45c
 SHA512 
32ef42663ea831556fa033bc03a481d103f09e8f5c16f611b3f2308ae80c81daec924192800a2f7c22f70ac86c5440377f892a88cce522223cbbdff793114091

diff --git a/sci-ml/ollama/ollama-0.9.0.ebuild 
b/sci-ml/ollama/ollama-0.9.0.ebuild
new file mode 100644
index 0000000000..81e1307e83
--- /dev/null
+++ b/sci-ml/ollama/ollama-0.9.0.ebuild
@@ -0,0 +1,308 @@
+# Copyright 2024-2025 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+# supports ROCM/HIP >=5.5, but we define 6.1 due to the eclass
+ROCM_VERSION=6.1
+inherit cuda rocm
+inherit cmake
+inherit go-module systemd toolchain-funcs
+
+DESCRIPTION="Get up and running with Llama 3, Mistral, Gemma, and other 
language models."
+HOMEPAGE="https://ollama.com";
+
+if [[ ${PV} == *9999* ]]; then
+       inherit git-r3
+       EGIT_REPO_URI="https://github.com/ollama/ollama.git";
+else
+       SRC_URI="
+               https://github.com/ollama/${PN}/archive/refs/tags/v${PV}.tar.gz 
-> ${P}.gh.tar.gz
+               
https://github.com/negril/gentoo-overlay-vendored/raw/refs/heads/blobs/${P}-vendor.tar.xz
+       "
+       KEYWORDS="~amd64"
+fi
+
+LICENSE="MIT"
+SLOT="0"
+
+X86_CPU_FLAGS=(
+       sse4_2
+       avx
+       f16c
+       avx2
+       bmi2
+       fma3
+       avx512f
+       avx512vbmi
+       avx512_vnni
+       avx_vnni
+)
+CPU_FLAGS=( "${X86_CPU_FLAGS[@]/#/cpu_flags_x86_}" )
+IUSE="${CPU_FLAGS[*]} cuda blas mkl rocm"
+# IUSE+=" opencl vulkan"
+
+RESTRICT="test"
+
+COMMON_DEPEND="
+       cuda? (
+               dev-util/nvidia-cuda-toolkit:=
+       )
+       blas? (
+               !mkl? (
+                       virtual/blas
+               )
+               mkl? (
+                       sci-libs/mkl
+               )
+       )
+       rocm? (
+               >=sci-libs/hipBLAS-5.5:=[${ROCM_USEDEP}]
+       )
+"
+
+DEPEND="
+       ${COMMON_DEPEND}
+       >=dev-lang/go-1.23.4
+"
+
+RDEPEND="
+       ${COMMON_DEPEND}
+       acct-group/${PN}
+       >=acct-user/${PN}-3[cuda?]
+"
+
+PATCHES=(
+       "${FILESDIR}/${PN}-0.6.3-use-GNUInstallDirs.patch"
+)
+
+pkg_pretend() {
+       if use amd64; then
+               if use cpu_flags_x86_f16c && use cpu_flags_x86_avx2 && use 
cpu_flags_x86_fma3 && ! use cpu_flags_x86_bmi2; then
+                       ewarn
+                       ewarn "CPU_FLAGS_X86: bmi2 not enabled."
+                       ewarn "  Not building haswell runner."
+                       ewarn "  Not building skylakex runner."
+                       ewarn "  Not building icelake runner."
+                       ewarn "  Not building alderlake runner."
+                       ewarn
+                       if grep bmi2 /proc/cpuinfo > /dev/null; then
+                               ewarn "bmi2 found in /proc/cpuinfo"
+                               ewarn
+                       fi
+               fi
+       fi
+}
+
+src_unpack() {
+       if [[ "${PV}" == *9999* ]]; then
+               git-r3_src_unpack
+               go-module_live_vendor
+       else
+               go-module_src_unpack
+       fi
+}
+
+src_prepare() {
+       cmake_src_prepare
+
+       sed \
+               -e "/set(GGML_CCACHE/s/ON/OFF/g" \
+               -e "/PRE_INCLUDE_REGEXES.*cu/d" \
+               -e "/PRE_INCLUDE_REGEXES.*hip/d" \
+               -i CMakeLists.txt || die sed
+
+       sed \
+               -e "s/ -O3//g" \
+               -i ml/backend/ggml/ggml/src/ggml-cpu/cpu.go || die sed
+
+       # fix library location
+       sed \
+               -e "s#lib/ollama#$(get_libdir)/ollama#g" \
+               -i CMakeLists.txt || die sed
+
+       sed \
+               -e "s/\"..\", \"lib\"/\"..\", \"$(get_libdir)\"/" \
+               -e "s#\"lib/ollama\"#\"$(get_libdir)/ollama\"#" \
+               -i \
+                       ml/backend/ggml/ggml/src/ggml.go \
+                       discover/path.go \
+               || die
+
+       if use amd64; then
+               if
+                       ! use cpu_flags_x86_sse4_2; then
+                       sed -e "/ggml_add_cpu_backend_variant(sse42/s/^/# /g" 
-i ml/backend/ggml/ggml/src/CMakeLists.txt || die
+                       # SSE42)
+               fi
+               if
+                       ! use cpu_flags_x86_sse4_2 ||
+                       ! use cpu_flags_x86_avx; then
+                       sed -e "/ggml_add_cpu_backend_variant(sandybridge/s/^/# 
/g" -i ml/backend/ggml/ggml/src/CMakeLists.txt || die
+                       # SSE42 AVX)
+               fi
+               if
+                       ! use cpu_flags_x86_sse4_2 ||
+                       ! use cpu_flags_x86_avx ||
+                       ! use cpu_flags_x86_f16c ||
+                       ! use cpu_flags_x86_avx2 ||
+                       ! use cpu_flags_x86_bmi2 ||
+                       ! use cpu_flags_x86_fma3; then
+                       sed -e "/ggml_add_cpu_backend_variant(haswell/s/^/# /g" 
-i ml/backend/ggml/ggml/src/CMakeLists.txt || die
+                       # SSE42 AVX F16C AVX2 BMI2 FMA)
+               fi
+               if
+                       ! use cpu_flags_x86_sse4_2 ||
+                       ! use cpu_flags_x86_avx ||
+                       ! use cpu_flags_x86_f16c ||
+                       ! use cpu_flags_x86_avx2 ||
+                       ! use cpu_flags_x86_bmi2 ||
+                       ! use cpu_flags_x86_fma3 ||
+                       ! use cpu_flags_x86_avx512f; then
+                       sed -e "/ggml_add_cpu_backend_variant(skylakex/s/^/# 
/g" -i ml/backend/ggml/ggml/src/CMakeLists.txt ||  die
+                       # SSE42 AVX F16C AVX2 BMI2 FMA AVX512)
+               fi
+               if
+                       ! use cpu_flags_x86_sse4_2 ||
+                       ! use cpu_flags_x86_avx ||
+                       ! use cpu_flags_x86_f16c ||
+                       ! use cpu_flags_x86_avx2 ||
+                       ! use cpu_flags_x86_bmi2 ||
+                       ! use cpu_flags_x86_fma3 ||
+                       ! use cpu_flags_x86_avx512f ||
+                       ! use cpu_flags_x86_avx512vbmi ||
+                       ! use cpu_flags_x86_avx512_vnni; then
+                       sed -e "/ggml_add_cpu_backend_variant(icelake/s/^/# /g" 
-i ml/backend/ggml/ggml/src/CMakeLists.txt || die
+                       # SSE42 AVX F16C AVX2 BMI2 FMA AVX512 AVX512_VBMI 
AVX512_VNNI)
+               fi
+               if
+                       ! use cpu_flags_x86_sse4_2 ||
+                       ! use cpu_flags_x86_avx ||
+                       ! use cpu_flags_x86_f16c ||
+                       ! use cpu_flags_x86_avx2 ||
+                       ! use cpu_flags_x86_bmi2 ||
+                       ! use cpu_flags_x86_fma3 ||
+                       ! use cpu_flags_x86_avx_vnni; then
+                       sed -e "/ggml_add_cpu_backend_variant(alderlake/s/^/# 
/g" -i ml/backend/ggml/ggml/src/CMakeLists.txt || die
+                       # SSE42 AVX F16C AVX2 BMI2 FMA AVX_VNNI)
+               fi
+
+               # ml/backend/ggml/ggml/src/CMakeLists.txt
+       fi
+
+       # default
+       # return
+       if use cuda; then
+               cuda_src_prepare
+       fi
+
+       if use rocm; then
+               # --hip-version gets appended to the compile flags which isn't 
a known flag.
+               # This causes rocm builds to fail because 
-Wunused-command-line-argument is turned on.
+               # Use nuclear option to fix this.
+               # Disable -Werror's from go modules.
+               find "${S}" -name ".go" -exec sed -i "s/ -Werror / /g" {} + || 
die
+       fi
+}
+
+src_configure() {
+       local mycmakeargs=(
+               -DGGML_CCACHE="no"
+
+               # -DGGML_CPU="yes"
+               -DGGML_BLAS="$(usex blas)"
+               # -DGGML_CUDA="$(usex cuda)"
+               # -DGGML_HIP="$(usex rocm)"
+
+               # -DGGML_METAL="yes" # apple
+               # missing from ml/backend/ggml/ggml/src/
+               # -DGGML_CANN="yes"
+               # -DGGML_MUSA="yes"
+               # -DGGML_RPC="yes"
+               # -DGGML_SYCL="yes"
+               # -DGGML_KOMPUTE="$(usex kompute)"
+               # -DGGML_OPENCL="$(usex opencl)"
+               # -DGGML_VULKAN="$(usex vulkan)"
+       )
+
+       if use blas; then
+               if use mkl; then
+                       mycmakeargs+=(
+                               -DGGML_BLAS_VENDOR="Intel"
+                       )
+               else
+                       mycmakeargs+=(
+                               -DGGML_BLAS_VENDOR="Generic"
+                       )
+               fi
+       fi
+       if use cuda; then
+               local -x CUDAHOSTCXX CUDAHOSTLD
+               CUDAHOSTCXX="$(cuda_gccdir)"
+               CUDAHOSTLD="$(tc-getCXX)"
+
+               cuda_add_sandbox -w
+               addpredict "/dev/char/"
+       else
+               mycmakeargs+=(
+                       -DCMAKE_CUDA_COMPILER="NOTFOUND"
+               )
+       fi
+
+       if use rocm; then
+               mycmakeargs+=(
+                       -DCMAKE_HIP_ARCHITECTURES="$(get_amdgpu_flags)"
+                       -DCMAKE_HIP_PLATFORM="amd"
+                       # ollama doesn't honor the default cmake options
+                       -DAMDGPU_TARGETS="$(get_amdgpu_flags)"
+               )
+
+               local -x HIP_PATH="${ESYSROOT}/usr"
+
+               check_amdgpu
+       else
+               mycmakeargs+=(
+                       -DCMAKE_HIP_COMPILER="NOTFOUND"
+               )
+       fi
+
+       cmake_src_configure
+}
+
+src_compile() {
+       ego build
+
+       cmake_src_compile
+}
+
+src_install() {
+       dobin ollama
+
+       cmake_src_install
+
+       newinitd "${FILESDIR}/ollama.init" "${PN}"
+       newconfd "${FILESDIR}/ollama.confd" "${PN}"
+
+       systemd_dounit "${FILESDIR}/ollama.service"
+}
+
+pkg_preinst() {
+       keepdir /var/log/ollama
+       fperms 750 /var/log/ollama
+       fowners "${PN}:${PN}" /var/log/ollama
+}
+
+pkg_postinst() {
+       if [[ -z ${REPLACING_VERSIONS} ]] ; then
+               einfo "Quick guide:"
+               einfo "\tollama serve"
+               einfo "\tollama run llama3:70b"
+               einfo
+               einfo "See available models at https://ollama.com/library";
+       fi
+
+       if use cuda ; then
+               einfo "When using cuda the user running ${PN} has to be in the 
video group or it won't detect devices."
+               einfo "The ebuild ensures this for user ${PN} via 
acct-user/${PN}[cuda]"
+       fi
+}

Reply via email to