Revert "sci-ml/ollama: treeclean, now in ::gentoo"

This reverts commit 0d5c4fec78.

Based on 2e79ca38f1, let's keep this
for now given the differences should be reconciled.

Signed-off-by: Sam James <sam@gentoo.org>
This commit is contained in:
Sam James
2026-07-12 21:31:15 +01:00
parent 132c9bb593
commit b953ae5355
12 changed files with 2021 additions and 0 deletions

6
sci-ml/ollama/Manifest Normal file
View File

@@ -0,0 +1,6 @@
DIST ollama-0.18.0-deps.tar.xz 84650388 BLAKE2B b83450c77d4b769b712d7cae5949a0b72931b03d131ec857c3f22d4e9f498a86b916aebdd26176294aca1133b6a58cfa063f58af232fdd30fd7f741fdc95dc85 SHA512 705c67b746e55b56273880fddb2afa18f6ad4989db67d425aadfd695807503861c38bf76da9bfe7d4118ac625b8554501cfa28fc334c7c7f6e09b96a84805691
DIST ollama-0.18.0.gh.tar.gz 23267563 BLAKE2B d9c9ee5ea09dd77bb7500b57d2383c6c1e572a643454fd35acec04bf034d617b1a796e6df3b0caba2b58927acfadcded0b89a7e7f1804be5645e74c8b1981019 SHA512 f4a0accadb5e4dd6a20c4ea82fc246da3e4fb618d975555705fe6b577abc4f66f9e542e55a98fd41e96fcfd3fd6cfc219251bec5f98439d495f4e5d2121fe164
DIST ollama-0.20.3-deps.tar.xz 84650388 BLAKE2B b83450c77d4b769b712d7cae5949a0b72931b03d131ec857c3f22d4e9f498a86b916aebdd26176294aca1133b6a58cfa063f58af232fdd30fd7f741fdc95dc85 SHA512 705c67b746e55b56273880fddb2afa18f6ad4989db67d425aadfd695807503861c38bf76da9bfe7d4118ac625b8554501cfa28fc334c7c7f6e09b96a84805691
DIST ollama-0.20.3.gh.tar.gz 26448858 BLAKE2B c8cd751cb1a840e1fa9b6337529b192bf1b235fdeb8959ef2dd881e503bcdcc63cfb2b61c2e31851c5992b0a6c8d204e6771ce0e993014b5df08e6122ffa641c SHA512 a722f677f296ec86296660f72798ca752e1389280febb6238d88c50a7f5711df67d7322e7effb39998e37672cd9d27fe587e26fdc265d29c7bb1f9b32fe2d5f1
DIST ollama-0.21.2-deps.tar.xz 84650388 BLAKE2B b83450c77d4b769b712d7cae5949a0b72931b03d131ec857c3f22d4e9f498a86b916aebdd26176294aca1133b6a58cfa063f58af232fdd30fd7f741fdc95dc85 SHA512 705c67b746e55b56273880fddb2afa18f6ad4989db67d425aadfd695807503861c38bf76da9bfe7d4118ac625b8554501cfa28fc334c7c7f6e09b96a84805691
DIST ollama-0.21.2.gh.tar.gz 27896062 BLAKE2B e02491c37d84aae6d88c48e9d631760d00327f2e0f2ef33baf24722e093aaaecf9e33e959e8548061f3350b12886bc6dcec5a9aea40e99f13a2577900981af89 SHA512 80493313eccd994a02db6bc2330594790f66466fdf9736802528dc813e1b70402d273acd63249112ab9b97b0e610a25469f69daff08448fa946c344bd45ad334

View File

@@ -0,0 +1,134 @@
From 7367444df7e44434569708b13ddf26b159e3ba50 Mon Sep 17 00:00:00 2001
From: Paul Zander <negril.nx+gentoo@gmail.com>
Date: Tue, 17 Feb 2026 12:52:29 +0100
Subject: [PATCH] make installing runtime deps optional
Signed-off-by: Paul Zander <negril.nx+gentoo@gmail.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7d53531b..ce7376d8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -78,6 +78,8 @@ set(GGML_VERSION_MINOR 0)
set(GGML_VERSION_PATCH 0)
set(GGML_VERSION "${GGML_VERSION_MAJOR}.${GGML_VERSION_MINOR}.${GGML_VERSION_PATCH}")
+option(OLLAMA_INSTALL_RUNTIME_DEPS "Install the dependencies of library as well" ON)
+
set(GGML_CPU ON)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/ml/backend/ggml/ggml/src)
set_property(TARGET ggml PROPERTY EXCLUDE_FROM_ALL TRUE)
@@ -88,12 +90,17 @@ if(NOT CPU_VARIANTS)
endif()
install(TARGETS ggml-base ${CPU_VARIANTS}
- RUNTIME_DEPENDENCIES
- PRE_EXCLUDE_REGEXES ".*"
- RUNTIME DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT CPU
+ RUNTIME_DEPENDENCY_SET base
LIBRARY DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT CPU
FRAMEWORK DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT CPU
)
+if(OLLAMA_INSTALL_RUNTIME_DEPS)
+install(RUNTIME_DEPENDENCY_SET base
+ PRE_EXCLUDE_REGEXES ".*"
+ RUNTIME DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT CPU
+ LIBRARY DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT CPU
+)
+endif()
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
@@ -104,13 +111,18 @@ if(CMAKE_CUDA_COMPILER)
find_package(CUDAToolkit)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/ml/backend/ggml/ggml/src/ggml-cuda)
install(TARGETS ggml-cuda
- RUNTIME_DEPENDENCIES
- DIRECTORIES ${CUDAToolkit_BIN_DIR} ${CUDAToolkit_BIN_DIR}/x64 ${CUDAToolkit_LIBRARY_DIR}
- PRE_INCLUDE_REGEXES cublas cublasLt cudart
- PRE_EXCLUDE_REGEXES ".*"
+ RUNTIME_DEPENDENCY_SET cuda
+ LIBRARY DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT CUDA
+ )
+ if(OLLAMA_INSTALL_RUNTIME_DEPS)
+ install(RUNTIME_DEPENDENCY_SET cuda
+ DIRECTORIES ${CUDAToolkit_BIN_DIR} ${CUDAToolkit_BIN_DIR}/x64 ${CUDAToolkit_LIBRARY_DIR}
+ PRE_INCLUDE_REGEXES cublas cublasLt cudart
+ PRE_EXCLUDE_REGEXES ".*"
RUNTIME DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT CUDA
LIBRARY DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT CUDA
)
+ endif()
endif()
set(WINDOWS_AMDGPU_TARGETS_EXCLUDE_REGEX "^gfx(908|90a|1200|1201):xnack[+-]$"
@@ -143,9 +155,9 @@ if(CMAKE_HIP_COMPILER)
install(TARGETS ggml-hip
RUNTIME_DEPENDENCY_SET rocm
- RUNTIME DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT HIP
LIBRARY DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT HIP
)
+ if(OLLAMA_INSTALL_RUNTIME_DEPS)
install(RUNTIME_DEPENDENCY_SET rocm
DIRECTORIES ${HIP_BIN_INSTALL_DIR} ${HIP_LIB_INSTALL_DIR}
PRE_INCLUDE_REGEXES hipblas rocblas amdhip64 rocsolver amd_comgr hsa-runtime64 rocsparse tinfo rocprofiler-register drm drm_amdgpu numa elf
@@ -161,6 +173,7 @@ if(CMAKE_HIP_COMPILER)
break()
endif()
endforeach()
+ endif()
endif()
endif()
@@ -169,12 +182,17 @@ if(NOT APPLE)
if(Vulkan_FOUND)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/ml/backend/ggml/ggml/src/ggml-vulkan)
install(TARGETS ggml-vulkan
- RUNTIME_DEPENDENCIES
- PRE_INCLUDE_REGEXES vulkan
- PRE_EXCLUDE_REGEXES ".*"
+ RUNTIME_DEPENDENCY_SET vulkan
+ LIBRARY DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT Vulkan
+ )
+ if(OLLAMA_INSTALL_RUNTIME_DEPS)
+ install(RUNTIME_DEPENDENCY_SET vulkan
+ PRE_INCLUDE_REGEXES vulkan
+ PRE_EXCLUDE_REGEXES ".*"
RUNTIME DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT Vulkan
LIBRARY DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT Vulkan
)
+ endif()
endif()
endif()
@@ -188,15 +206,21 @@ if(MLX_ENGINE)
find_package(CUDAToolkit)
install(TARGETS mlx mlxc
- RUNTIME_DEPENDENCIES
- DIRECTORIES ${MLX_RUNTIME_DIRS}
- PRE_INCLUDE_REGEXES ${MLX_INCLUDE_REGEXES}
- PRE_EXCLUDE_REGEXES ".*"
- RUNTIME DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT MLX
+ RUNTIME_DEPENDENCY_SET mlx
LIBRARY DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT MLX
FRAMEWORK DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT MLX
)
+ if(OLLAMA_INSTALL_RUNTIME_DEPS)
+ install(RUNTIME_DEPENDENCY_SET mlx
+ DIRECTORIES ${MLX_RUNTIME_DIRS}
+ PRE_INCLUDE_REGEXES ${MLX_INCLUDE_REGEXES}
+ PRE_EXCLUDE_REGEXES ".*"
+ RUNTIME DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT MLX
+ LIBRARY DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT MLX
+ )
+ endif()
+
# Install the Metal library for macOS arm64 (must be colocated with the binary)
# Metal backend is only built for arm64, not x86_64
if(APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
--
2.53.0

View File

@@ -0,0 +1,120 @@
From dc76193516672ab84fc0aed1d5b3076ce3f334e7 Mon Sep 17 00:00:00 2001
From: Paul Zander <negril.nx+gentoo@gmail.com>
Date: Tue, 17 Feb 2026 12:52:29 +0100
Subject: make installing runtime deps optional
Signed-off-by: Paul Zander <negril.nx+gentoo@gmail.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 40c22f4b..375ddff5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -84,6 +84,8 @@ set(GGML_VERSION_MINOR 0)
set(GGML_VERSION_PATCH 0)
set(GGML_VERSION "${GGML_VERSION_MAJOR}.${GGML_VERSION_MINOR}.${GGML_VERSION_PATCH}")
+option(OLLAMA_INSTALL_RUNTIME_DEPS "Install the dependencies of library as well" ON)
+
set(GGML_CPU ON)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/ml/backend/ggml/ggml/src)
set_property(TARGET ggml PROPERTY EXCLUDE_FROM_ALL TRUE)
@@ -102,12 +104,16 @@ foreach(variant ${CPU_VARIANTS})
endforeach()
install(TARGETS ggml-base ${CPU_VARIANTS}
- RUNTIME_DEPENDENCIES
- PRE_EXCLUDE_REGEXES ".*"
+ RUNTIME_DEPENDENCY_SET base
RUNTIME DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT CPU
LIBRARY DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT CPU
FRAMEWORK DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT CPU
)
+if(OLLAMA_INSTALL_RUNTIME_DEPS)
+install(RUNTIME_DEPENDENCY_SET base
+ PRE_EXCLUDE_REGEXES ".*"
+)
+endif()
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
@@ -119,13 +125,18 @@ if(CMAKE_CUDA_COMPILER)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/ml/backend/ggml/ggml/src/ggml-cuda)
target_include_directories(ggml-cuda PRIVATE ${GGML_INCLUDE_DIRS})
install(TARGETS ggml-cuda
+ RUNTIME_DEPENDENCY_SET cuda
+ RUNTIME DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT CUDA
+ LIBRARY DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT CUDA
+ )
+ if(OLLAMA_INSTALL_RUNTIME_DEPS)
+ install(RUNTIME_DEPENDENCY_SET cuda
RUNTIME_DEPENDENCIES
DIRECTORIES ${CUDAToolkit_BIN_DIR} ${CUDAToolkit_BIN_DIR}/x64 ${CUDAToolkit_LIBRARY_DIR}
PRE_INCLUDE_REGEXES cublas cublasLt cudart
PRE_EXCLUDE_REGEXES ".*"
- RUNTIME DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT CUDA
- LIBRARY DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT CUDA
)
+ endif()
endif()
set(WINDOWS_AMDGPU_TARGETS_EXCLUDE_REGEX "^gfx(908|90a|1200|1201):xnack[+-]$"
@@ -162,13 +173,12 @@ if(CMAKE_HIP_COMPILER)
RUNTIME DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT HIP
LIBRARY DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT HIP
)
+ if(OLLAMA_INSTALL_RUNTIME_DEPS)
install(RUNTIME_DEPENDENCY_SET rocm
DIRECTORIES ${HIP_BIN_INSTALL_DIR} ${HIP_LIB_INSTALL_DIR}
PRE_INCLUDE_REGEXES hipblas rocblas amdhip64 rocsolver amd_comgr hsa-runtime64 rocsparse tinfo rocprofiler-register roctx64 rocroller drm drm_amdgpu numa elf
PRE_EXCLUDE_REGEXES ".*"
POST_EXCLUDE_REGEXES "system32"
- RUNTIME DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT HIP
- LIBRARY DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT HIP
)
foreach(HIP_LIB_BIN_INSTALL_DIR IN ITEMS ${HIP_BIN_INSTALL_DIR} ${HIP_LIB_INSTALL_DIR})
@@ -177,6 +187,7 @@ if(CMAKE_HIP_COMPILER)
break()
endif()
endforeach()
+ endif()
endif()
endif()
@@ -186,12 +197,16 @@ if(NOT APPLE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/ml/backend/ggml/ggml/src/ggml-vulkan)
target_include_directories(ggml-vulkan PRIVATE ${GGML_INCLUDE_DIRS})
install(TARGETS ggml-vulkan
- RUNTIME_DEPENDENCIES
- PRE_INCLUDE_REGEXES vulkan
- PRE_EXCLUDE_REGEXES ".*"
+ RUNTIME_DEPENDENCY_SET vulkan
RUNTIME DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT Vulkan
LIBRARY DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT Vulkan
)
+ if(OLLAMA_INSTALL_RUNTIME_DEPS)
+ install(RUNTIME_DEPENDENCY_SET vulkan
+ PRE_INCLUDE_REGEXES vulkan
+ PRE_EXCLUDE_REGEXES ".*"
+ )
+ endif()
endif()
endif()
@@ -236,6 +251,7 @@ if(MLX_ENGINE)
LIBRARY DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT MLX
FRAMEWORK DESTINATION ${OLLAMA_INSTALL_DIR} COMPONENT MLX
)
+ if(OLLAMA_INSTALL_RUNTIME_DEPS)
install(RUNTIME_DEPENDENCY_SET mlx_runtime_deps
DIRECTORIES ${MLX_RUNTIME_DIRS}
PRE_INCLUDE_REGEXES ${MLX_INCLUDE_REGEXES}
@@ -375,4 +391,5 @@ if(MLX_ENGINE)
COMPONENT MLX_VENDOR)
endif()
endif()
+ endif()
endif()
--
2.54.0

View File

@@ -0,0 +1,26 @@
From 3e250053458fa33c97023ff8943e8c5daa4beeca Mon Sep 17 00:00:00 2001
From: Paul Zander <negril.nx+gentoo@gmail.com>
Date: Mon, 31 Mar 2025 18:07:47 +0200
Subject: [PATCH] use GNUInstallDirs
Signed-off-by: Paul Zander <negril.nx+gentoo@gmail.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9e107fe..79407ea 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -35,8 +35,9 @@ if (CMAKE_OSX_ARCHITECTURES MATCHES "x86_64")
set(CMAKE_INSTALL_RPATH "@loader_path")
endif()
-set(OLLAMA_BUILD_DIR ${CMAKE_BINARY_DIR}/lib/ollama)
-set(OLLAMA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib/ollama/${OLLAMA_RUNNER_DIR})
+include(GNUInstallDirs)
+set(OLLAMA_BUILD_DIR ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/ollama)
+set(OLLAMA_INSTALL_DIR ${CMAKE_INSTALL_FULL_LIBDIR}/ollama/${OLLAMA_RUNNER_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OLLAMA_BUILD_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${OLLAMA_BUILD_DIR})
--
2.49.0

View File

@@ -0,0 +1,11 @@
# Ollama allows cross-origin requests from 127.0.0.1 and 0.0.0.0 by default.
# Additional origins can be configured with OLLAMA_ORIGINS.
# export OLLAMA_ORIGINS="<ip>"
# log to syslog
# output_logger="logger -t \"$RC_SVCNAME\" -p daemon.info"
# error_logger="logger -t \"$RC_SVCNAME\" -p daemon.err"
# log to file
output_log="/var/log/ollama/ollama.log"
error_log="/var/log/ollama/ollama.log"

View File

@@ -0,0 +1,9 @@
#!/sbin/openrc-run
# Copyright 1999-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License, v2
supervisor=supervise-daemon
description="Ollama Service"
command="/usr/bin/ollama"
command_args="serve"
command_user="ollama:ollama"

View File

@@ -0,0 +1,14 @@
[Unit]
Description=Ollama Service
After=network-online.target
[Service]
ExecStart=/usr/bin/ollama serve
User=ollama
Group=ollama
Restart=always
RestartSec=3
Environment="PATH=$PATH"
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE pkgmetadata SYSTEM "https://www.gentoo.org/dtd/metadata.dtd">
<pkgmetadata>
<maintainer type="person">
<email>negril.nx+gentoo@gmail.com</email>
<name>Paul Zander</name>
</maintainer>
<use>
<flag name="blis">Use <pkg>sci-libs/blis</pkg> as blas provider</flag>
<flag name="cuda">Enable NVIDIA CUDA support</flag>
<flag name="flexiblas">Use <pkg>sci-libs/flexiblas</pkg> as blas provider</flag>
<flag name="mkl">Use <pkg>sci-libs/mkl</pkg> for blas, lapack and sparse blas routines</flag>
<flag name="openblas">Use <pkg>sci-libs/openblas</pkg> as blas provider</flag>
<flag name="rocm">Enable ROCm gpu computing support</flag>
</use>
<upstream>
<remote-id type="github">ollama/ollama</remote-id>
</upstream>
</pkgmetadata>

View File

@@ -0,0 +1,416 @@
# Copyright 2024-2026 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 flag-o-matic go-module linux-info 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
MY_PV="${PV/_rc/-rc}"
MY_P="${PN}-${MY_PV}"
SRC_URI="
https://github.com/ollama/${PN}/archive/refs/tags/v${MY_PV}.tar.gz -> ${MY_P}.gh.tar.gz
https://github.com/gentoo-golang-dist/${PN}/releases/download/v${MY_PV}/${MY_P}-deps.tar.xz
"
if [[ ${PV} != *_rc* ]]; then
KEYWORDS="~amd64"
fi
fi
LICENSE="MIT"
SLOT="0"
IUSE="cuda rocm vulkan"
# IUSE+=" opencl"
BLAS_BACKENDS="blis mkl openblas"
BLAS_REQUIRED_USE="blas? ( ?? ( ${BLAS_BACKENDS} ) )"
IUSE+=" blas flexiblas ${BLAS_BACKENDS}"
REQUIRED_USE+=" ${BLAS_REQUIRED_USE}"
declare -rgA CPU_FEATURES=(
[AVX2]="x86"
[AVX512F]="x86"
[AVX512_VBMI]="x86;avx512vbmi"
[AVX512_VNNI]="x86"
[AVX]="x86"
[AVX_VNNI]="x86"
[BMI2]="x86"
[F16C]="x86"
[FMA]="x86;fma3"
[SSE42]="x86;sse4_2"
)
add_cpu_features_use() {
for flag in "${!CPU_FEATURES[@]}"; do
IFS=$';' read -rd '' arch use < <(printf %s "${CPU_FEATURES[${flag}]}")
IUSE+=" cpu_flags_${arch}_${use:-${flag,,}}"
done
}
add_cpu_features_use
RESTRICT="mirror test"
# FindBLAS.cmake
# If Fortran is an enabled compiler it sets BLAS_mkl_THREADING to gnu. -> sci-libs/mkl[gnu-openmp]
# If Fortran is not an enabled compiler it sets BLAS_mkl_THREADING to intel. -> sci-libs/mkl[llvm-openmp]
COMMON_DEPEND="
blas? (
blis? (
sci-libs/blis:=
)
flexiblas? (
sci-libs/flexiblas[blis?,mkl?,openblas?]
)
mkl? (
sci-libs/mkl[llvm-openmp]
)
openblas? (
sci-libs/openblas
)
virtual/blas[flexiblas=]
)
cuda? (
dev-util/nvidia-cuda-toolkit:=
)
rocm? (
>=dev-util/hip-${ROCM_VERSION}:=
>=sci-libs/hipBLAS-${ROCM_VERSION}:=
>=sci-libs/rocBLAS-${ROCM_VERSION}:=
)
"
DEPEND="
${COMMON_DEPEND}
>=dev-lang/go-1.23.4
"
BDEPEND="
vulkan? (
dev-util/vulkan-headers
media-libs/shaderc
)
"
RDEPEND="
${COMMON_DEPEND}
acct-group/${PN}
>=acct-user/${PN}-3[cuda?]
"
PATCHES=(
"${FILESDIR}/${PN}-9999-use-GNUInstallDirs.patch"
"${FILESDIR}/${PN}-0.18.0-make-installing-runtime-deps-optional.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
}
pkg_setup() {
if use rocm; then
linux-info_pkg_setup
if linux-info_get_any_version && linux_config_exists; then
if ! linux_chkconfig_present HSA_AMD_SVM; then
ewarn "To use ROCm/HIP, you need to have HSA_AMD_SVM option enabled in your kernel."
fi
fi
fi
}
src_unpack() {
# Already filter lto flags for ROCM
# 963401
if use rocm; then
# copied from _rocm_strip_unsupported_flags
strip-unsupported-flags
export CXXFLAGS="$(test-flags-HIPCXX "${CXXFLAGS}")"
fi
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" \
-i CMakeLists.txt || die "Disable CCACHE sed failed"
# TODO see src_unpack?
sed \
-e "s/ -O3//g" \
-i \
ml/backend/ggml/ggml/src/ggml-cpu/cpu.go \
|| die "-O3 sed failed"
# grep -Rl -e 'lib/ollama' -e '"..", "lib"' --include '*.go'
sed \
-e "s/\"..\", \"lib\"/\"..\", \"$(get_libdir)\"/" \
-e "s#\"lib/ollama\"#\"$(get_libdir)/ollama\"#" \
-i \
ml/backend/ggml/ggml/src/ggml.go \
ml/path.go \
|| die "libdir sed failed"
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
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=(
-DOLLAMA_INSTALL_RUNTIME_DEPS="no"
-DGGML_CCACHE="no"
# backends end up in /usr/bin otherwise
-DGGML_BACKEND_DL="yes"
# TODO causes duplicate install warning but breaks detection otherwise ollama/issues/13614
-DGGML_BACKEND_DIR="${EPREFIX}/usr/$(get_libdir)/${PN}"
# -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)"
"$(cmake_use_find_package vulkan Vulkan)"
)
if tc-is-lto ; then
mycmakeargs+=(
-DGGML_LTO="yes"
)
fi
if use blas; then
if use flexiblas ; then
mycmakeargs+=(
-DGGML_BLAS_VENDOR="FlexiBLAS"
)
elif use blis ; then
mycmakeargs+=(
-DGGML_BLAS_VENDOR="FLAME"
)
elif use mkl ; then
mycmakeargs+=(
-DGGML_BLAS_VENDOR="Intel10_64lp"
)
# elif use nvhpc ; then
# mycmakeargs+=(
# -DGGML_BLAS_VENDOR="NVHPC"
# )
elif use openblas ; then
mycmakeargs+=(
-DGGML_BLAS_VENDOR="OpenBLAS"
)
else
mycmakeargs+=(
-DGGML_BLAS_VENDOR="Generic"
)
fi
fi
if use cuda; then
local -x CUDAHOSTCXX CUDAHOSTLD
CUDAHOSTCXX="$(cuda_gccdir)"
CUDAHOSTLD="$(tc-getCXX)"
# default to all-major for now until cuda.eclass is updated
if [[ ! -v CUDAARCHS ]]; then
local CUDAARCHS="all-major"
fi
mycmakeargs+=(
-DCMAKE_CUDA_ARCHITECTURES="${CUDAARCHS}"
)
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"
else
mycmakeargs+=(
-DCMAKE_HIP_COMPILER="NOTFOUND"
)
fi
cmake_src_configure
}
src_compile() {
# export version information
# https://github.com/gentoo/guru/pull/205
# https://forums.gentoo.org/viewtopic-p-8831646.html
local VERSION
if [[ "${PV}" == *9999* ]]; then
VERSION="$(
git describe --tags --first-parent --abbrev=7 --long --dirty --always \
| sed -e "s/^v//g"
)"
else
VERSION="${PVR}"
fi
local EXTRA_GOFLAGS_LD=(
# "-w" # disable DWARF generation
# "-s" # disable symbol table
"-X=github.com/ollama/ollama/version.Version=${VERSION}"
"-X=github.com/ollama/ollama/server.mode=release"
)
GOFLAGS+=" '-ldflags=${EXTRA_GOFLAGS_LD[*]}'"
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
}

View File

@@ -0,0 +1,422 @@
# Copyright 2024-2026 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 flag-o-matic go-module linux-info 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
MY_PV="${PV/_rc/-rc}"
MY_P="${PN}-${MY_PV}"
SRC_URI="
https://github.com/ollama/${PN}/archive/refs/tags/v${MY_PV}.tar.gz -> ${MY_P}.gh.tar.gz
https://github.com/gentoo-golang-dist/${PN}/releases/download/v${MY_PV}/${MY_P}-deps.tar.xz
"
if [[ ${PV} != *_rc* ]]; then
KEYWORDS="~amd64"
fi
fi
LICENSE="MIT"
SLOT="0"
IUSE="cuda rocm vulkan"
# IUSE+=" opencl"
BLAS_BACKENDS="blis mkl openblas"
BLAS_REQUIRED_USE="blas? ( ?? ( ${BLAS_BACKENDS} ) )"
IUSE+=" blas flexiblas ${BLAS_BACKENDS}"
REQUIRED_USE+=" ${BLAS_REQUIRED_USE}"
declare -rgA CPU_FEATURES=(
[AVX2]="x86"
[AVX512F]="x86"
[AVX512_VBMI]="x86;avx512vbmi"
[AVX512_VNNI]="x86"
[AVX]="x86"
[AVX_VNNI]="x86"
[BMI2]="x86"
[F16C]="x86"
[FMA]="x86;fma3"
[SSE42]="x86;sse4_2"
)
add_cpu_features_use() {
for flag in "${!CPU_FEATURES[@]}"; do
IFS=$';' read -rd '' arch use < <(printf %s "${CPU_FEATURES[${flag}]}")
IUSE+=" cpu_flags_${arch}_${use:-${flag,,}}"
done
}
add_cpu_features_use
RESTRICT="mirror test"
# FindBLAS.cmake
# If Fortran is an enabled compiler it sets BLAS_mkl_THREADING to gnu. -> sci-libs/mkl[gnu-openmp]
# If Fortran is not an enabled compiler it sets BLAS_mkl_THREADING to intel. -> sci-libs/mkl[llvm-openmp]
COMMON_DEPEND="
blas? (
blis? (
sci-libs/blis:=
)
flexiblas? (
sci-libs/flexiblas[blis?,mkl?,openblas?]
)
mkl? (
sci-libs/mkl[llvm-openmp]
)
openblas? (
sci-libs/openblas
)
virtual/blas[flexiblas=]
)
cuda? (
dev-util/nvidia-cuda-toolkit:=
)
rocm? (
>=dev-util/hip-${ROCM_VERSION}:=
>=sci-libs/hipBLAS-${ROCM_VERSION}:=
>=sci-libs/rocBLAS-${ROCM_VERSION}:=
)
"
DEPEND="
${COMMON_DEPEND}
>=dev-lang/go-1.23.4
"
BDEPEND="
vulkan? (
dev-util/vulkan-headers
media-libs/shaderc
)
"
RDEPEND="
${COMMON_DEPEND}
acct-group/${PN}
>=acct-user/${PN}-3[cuda?]
"
PATCHES=(
"${FILESDIR}/${PN}-9999-use-GNUInstallDirs.patch"
"${FILESDIR}/${PN}-0.18.0-make-installing-runtime-deps-optional.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
}
pkg_setup() {
if use rocm; then
linux-info_pkg_setup
if linux-info_get_any_version && linux_config_exists; then
if ! linux_chkconfig_present HSA_AMD_SVM; then
ewarn "To use ROCm/HIP, you need to have HSA_AMD_SVM option enabled in your kernel."
fi
fi
fi
}
src_unpack() {
# Already filter lto flags for ROCM
# 963401
if use rocm; then
# copied from _rocm_strip_unsupported_flags
strip-unsupported-flags
export CXXFLAGS="$(test-flags-HIPCXX "${CXXFLAGS}")"
fi
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" \
-i CMakeLists.txt || die "Disable CCACHE sed failed"
# TODO see src_unpack?
sed \
-e "s/ -O3//g" \
-i \
ml/backend/ggml/ggml/src/ggml-cpu/cpu.go \
|| die "-O3 sed failed"
# grep -Rl -e 'lib/ollama' -e '"..", "lib"' --include '*.go'
sed \
-e "s/\"..\", \"lib\"/\"..\", \"$(get_libdir)\"/" \
-e "s#\"lib/ollama\"#\"$(get_libdir)/ollama\"#" \
-i \
ml/backend/ggml/ggml/src/ggml.go \
ml/path.go \
|| die "libdir sed failed"
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
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=(
-DOLLAMA_INSTALL_RUNTIME_DEPS="no"
-DGGML_CCACHE="no"
# backends end up in /usr/bin otherwise
-DGGML_BACKEND_DL="yes"
# TODO causes duplicate install warning but breaks detection otherwise ollama/issues/13614
-DGGML_BACKEND_DIR="${EPREFIX}/usr/$(get_libdir)/${PN}"
# -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)"
"$(cmake_use_find_package vulkan Vulkan)"
)
if tc-is-lto ; then
mycmakeargs+=(
-DGGML_LTO="yes"
)
fi
if use blas; then
if use flexiblas ; then
mycmakeargs+=(
-DGGML_BLAS_VENDOR="FlexiBLAS"
)
elif use blis ; then
mycmakeargs+=(
-DGGML_BLAS_VENDOR="FLAME"
)
elif use mkl ; then
mycmakeargs+=(
-DGGML_BLAS_VENDOR="Intel10_64lp"
)
# elif use nvhpc ; then
# mycmakeargs+=(
# -DGGML_BLAS_VENDOR="NVHPC"
# )
elif use openblas ; then
mycmakeargs+=(
-DGGML_BLAS_VENDOR="OpenBLAS"
)
else
mycmakeargs+=(
-DGGML_BLAS_VENDOR="Generic"
)
fi
fi
if use cuda; then
local -x CUDAHOSTCXX CUDAHOSTLD
CUDAHOSTCXX="$(cuda_gccdir)"
CUDAHOSTLD="$(tc-getCXX)"
# default to all-major for now until cuda.eclass is updated
if [[ ! -v CUDAARCHS ]]; then
local CUDAARCHS="all-major"
fi
mycmakeargs+=(
-DCMAKE_CUDA_ARCHITECTURES="${CUDAARCHS}"
)
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"
else
mycmakeargs+=(
-DCMAKE_HIP_COMPILER="NOTFOUND"
)
fi
cmake_src_configure
}
src_compile() {
# export version information
# https://github.com/gentoo/guru/pull/205
# https://forums.gentoo.org/viewtopic-p-8831646.html
local VERSION
if [[ "${PV}" == *9999* ]]; then
VERSION="$(
git describe --tags --first-parent --abbrev=7 --long --dirty --always \
| sed -e "s/^v//g"
)"
else
VERSION="${PVR}"
fi
local EXTRA_GOFLAGS_LD=(
# "-w" # disable DWARF generation
# "-s" # disable symbol table
"-X=github.com/ollama/ollama/version.Version=${VERSION}"
"-X=github.com/ollama/ollama/server.mode=release"
)
GOFLAGS+=" '-ldflags=${EXTRA_GOFLAGS_LD[*]}'"
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
einfo
einfo "Ollama binds 127.0.0.1 port 11434 by default."
einfo "Change the bind address with the OLLAMA_HOST environment variable."
einfo "See https://docs.ollama.com/faq for more info"
einfo
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
}

View File

@@ -0,0 +1,422 @@
# Copyright 2024-2026 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 flag-o-matic go-module linux-info 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
MY_PV="${PV/_rc/-rc}"
MY_P="${PN}-${MY_PV}"
SRC_URI="
https://github.com/ollama/${PN}/archive/refs/tags/v${MY_PV}.tar.gz -> ${MY_P}.gh.tar.gz
https://github.com/gentoo-golang-dist/${PN}/releases/download/v${MY_PV}/${MY_P}-deps.tar.xz
"
if [[ ${PV} != *_rc* ]]; then
KEYWORDS="~amd64"
fi
fi
LICENSE="MIT"
SLOT="0"
IUSE="cuda rocm vulkan"
# IUSE+=" opencl"
BLAS_BACKENDS="blis mkl openblas"
BLAS_REQUIRED_USE="blas? ( ?? ( ${BLAS_BACKENDS} ) )"
IUSE+=" blas flexiblas ${BLAS_BACKENDS}"
REQUIRED_USE+=" ${BLAS_REQUIRED_USE}"
declare -rgA CPU_FEATURES=(
[AVX2]="x86"
[AVX512F]="x86"
[AVX512_VBMI]="x86;avx512vbmi"
[AVX512_VNNI]="x86"
[AVX]="x86"
[AVX_VNNI]="x86"
[BMI2]="x86"
[F16C]="x86"
[FMA]="x86;fma3"
[SSE42]="x86;sse4_2"
)
add_cpu_features_use() {
for flag in "${!CPU_FEATURES[@]}"; do
IFS=$';' read -rd '' arch use < <(printf %s "${CPU_FEATURES[${flag}]}")
IUSE+=" cpu_flags_${arch}_${use:-${flag,,}}"
done
}
add_cpu_features_use
RESTRICT="mirror test"
# FindBLAS.cmake
# If Fortran is an enabled compiler it sets BLAS_mkl_THREADING to gnu. -> sci-libs/mkl[gnu-openmp]
# If Fortran is not an enabled compiler it sets BLAS_mkl_THREADING to intel. -> sci-libs/mkl[llvm-openmp]
COMMON_DEPEND="
blas? (
blis? (
sci-libs/blis:=
)
flexiblas? (
sci-libs/flexiblas[blis?,mkl?,openblas?]
)
mkl? (
sci-libs/mkl[llvm-openmp]
)
openblas? (
sci-libs/openblas
)
virtual/blas[flexiblas=]
)
cuda? (
dev-util/nvidia-cuda-toolkit:=
)
rocm? (
>=dev-util/hip-${ROCM_VERSION}:=
>=sci-libs/hipBLAS-${ROCM_VERSION}:=
>=sci-libs/rocBLAS-${ROCM_VERSION}:=
)
"
DEPEND="
${COMMON_DEPEND}
>=dev-lang/go-1.24.1
"
BDEPEND="
vulkan? (
dev-util/vulkan-headers
media-libs/shaderc
)
"
RDEPEND="
${COMMON_DEPEND}
acct-group/${PN}
>=acct-user/${PN}-3[cuda?]
"
PATCHES=(
"${FILESDIR}/${PN}-9999-use-GNUInstallDirs.patch"
"${FILESDIR}/${PN}-0.18.0-make-installing-runtime-deps-optional.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
}
pkg_setup() {
if use rocm; then
linux-info_pkg_setup
if linux-info_get_any_version && linux_config_exists; then
if ! linux_chkconfig_present HSA_AMD_SVM; then
ewarn "To use ROCm/HIP, you need to have HSA_AMD_SVM option enabled in your kernel."
fi
fi
fi
}
src_unpack() {
# Already filter lto flags for ROCM
# 963401
if use rocm; then
# copied from _rocm_strip_unsupported_flags
strip-unsupported-flags
export CXXFLAGS="$(test-flags-HIPCXX "${CXXFLAGS}")"
fi
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" \
-i CMakeLists.txt || die "Disable CCACHE sed failed"
# TODO see src_unpack?
sed \
-e "s/ -O3//g" \
-i \
ml/backend/ggml/ggml/src/ggml-cpu/cpu.go \
|| die "-O3 sed failed"
# grep -Rl -e 'lib/ollama' -e '"..", "lib"' --include '*.go'
sed \
-e "s/\"..\", \"lib\"/\"..\", \"$(get_libdir)\"/" \
-e "s#\"lib/ollama\"#\"$(get_libdir)/ollama\"#" \
-i \
ml/backend/ggml/ggml/src/ggml.go \
ml/path.go \
|| die "libdir sed failed"
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
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=(
-DOLLAMA_INSTALL_RUNTIME_DEPS="no"
-DGGML_CCACHE="no"
# backends end up in /usr/bin otherwise
-DGGML_BACKEND_DL="yes"
# TODO causes duplicate install warning but breaks detection otherwise ollama/issues/13614
-DGGML_BACKEND_DIR="${EPREFIX}/usr/$(get_libdir)/${PN}"
# -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)"
"$(cmake_use_find_package vulkan Vulkan)"
)
if tc-is-lto ; then
mycmakeargs+=(
-DGGML_LTO="yes"
)
fi
if use blas; then
if use flexiblas ; then
mycmakeargs+=(
-DGGML_BLAS_VENDOR="FlexiBLAS"
)
elif use blis ; then
mycmakeargs+=(
-DGGML_BLAS_VENDOR="FLAME"
)
elif use mkl ; then
mycmakeargs+=(
-DGGML_BLAS_VENDOR="Intel10_64lp"
)
# elif use nvhpc ; then
# mycmakeargs+=(
# -DGGML_BLAS_VENDOR="NVHPC"
# )
elif use openblas ; then
mycmakeargs+=(
-DGGML_BLAS_VENDOR="OpenBLAS"
)
else
mycmakeargs+=(
-DGGML_BLAS_VENDOR="Generic"
)
fi
fi
if use cuda; then
local -x CUDAHOSTCXX CUDAHOSTLD
CUDAHOSTCXX="$(cuda_gccdir)"
CUDAHOSTLD="$(tc-getCXX)"
# default to all-major for now until cuda.eclass is updated
if [[ ! -v CUDAARCHS ]]; then
local CUDAARCHS="all-major"
fi
mycmakeargs+=(
-DCMAKE_CUDA_ARCHITECTURES="${CUDAARCHS}"
)
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"
else
mycmakeargs+=(
-DCMAKE_HIP_COMPILER="NOTFOUND"
)
fi
cmake_src_configure
}
src_compile() {
# export version information
# https://github.com/gentoo/guru/pull/205
# https://forums.gentoo.org/viewtopic-p-8831646.html
local VERSION
if [[ "${PV}" == *9999* ]]; then
VERSION="$(
git describe --tags --first-parent --abbrev=7 --long --dirty --always \
| sed -e "s/^v//g"
)"
else
VERSION="${PVR}"
fi
local EXTRA_GOFLAGS_LD=(
# "-w" # disable DWARF generation
# "-s" # disable symbol table
"-X=github.com/ollama/ollama/version.Version=${VERSION}"
"-X=github.com/ollama/ollama/server.mode=release"
)
GOFLAGS+=" '-ldflags=${EXTRA_GOFLAGS_LD[*]}'"
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
einfo
einfo "Ollama binds 127.0.0.1 port 11434 by default."
einfo "Change the bind address with the OLLAMA_HOST environment variable."
einfo "See https://docs.ollama.com/faq for more info"
einfo
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
}

View File

@@ -0,0 +1,422 @@
# Copyright 2024-2026 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 flag-o-matic go-module linux-info 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
MY_PV="${PV/_rc/-rc}"
MY_P="${PN}-${MY_PV}"
SRC_URI="
https://github.com/ollama/${PN}/archive/refs/tags/v${MY_PV}.tar.gz -> ${MY_P}.gh.tar.gz
https://github.com/gentoo-golang-dist/${PN}/releases/download/v${MY_PV}/${MY_P}-deps.tar.xz
"
if [[ ${PV} != *_rc* ]]; then
KEYWORDS="~amd64"
fi
fi
LICENSE="MIT"
SLOT="0"
IUSE="cuda rocm vulkan"
# IUSE+=" opencl"
BLAS_BACKENDS="blis mkl openblas"
BLAS_REQUIRED_USE="blas? ( ?? ( ${BLAS_BACKENDS} ) )"
IUSE+=" blas flexiblas ${BLAS_BACKENDS}"
REQUIRED_USE+=" ${BLAS_REQUIRED_USE}"
declare -rgA CPU_FEATURES=(
[AVX2]="x86"
[AVX512F]="x86"
[AVX512_VBMI]="x86;avx512vbmi"
[AVX512_VNNI]="x86"
[AVX]="x86"
[AVX_VNNI]="x86"
[BMI2]="x86"
[F16C]="x86"
[FMA]="x86;fma3"
[SSE42]="x86;sse4_2"
)
add_cpu_features_use() {
for flag in "${!CPU_FEATURES[@]}"; do
IFS=$';' read -rd '' arch use < <(printf %s "${CPU_FEATURES[${flag}]}")
IUSE+=" cpu_flags_${arch}_${use:-${flag,,}}"
done
}
add_cpu_features_use
RESTRICT="mirror test"
# FindBLAS.cmake
# If Fortran is an enabled compiler it sets BLAS_mkl_THREADING to gnu. -> sci-libs/mkl[gnu-openmp]
# If Fortran is not an enabled compiler it sets BLAS_mkl_THREADING to intel. -> sci-libs/mkl[llvm-openmp]
COMMON_DEPEND="
blas? (
blis? (
sci-libs/blis:=
)
flexiblas? (
sci-libs/flexiblas[blis?,mkl?,openblas?]
)
mkl? (
sci-libs/mkl[llvm-openmp]
)
openblas? (
sci-libs/openblas
)
virtual/blas[flexiblas=]
)
cuda? (
dev-util/nvidia-cuda-toolkit:=
)
rocm? (
>=dev-util/hip-${ROCM_VERSION}:=
>=sci-libs/hipBLAS-${ROCM_VERSION}:=
>=sci-libs/rocBLAS-${ROCM_VERSION}:=
)
"
DEPEND="
${COMMON_DEPEND}
>=dev-lang/go-1.23.4
"
BDEPEND="
vulkan? (
dev-util/vulkan-headers
media-libs/shaderc
)
"
RDEPEND="
${COMMON_DEPEND}
acct-group/${PN}
>=acct-user/${PN}-3[cuda?]
"
PATCHES=(
"${FILESDIR}/${PN}-9999-use-GNUInstallDirs.patch"
"${FILESDIR}/${PN}-9999-make-installing-runtime-deps-optional.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
}
pkg_setup() {
if use rocm; then
linux-info_pkg_setup
if linux-info_get_any_version && linux_config_exists; then
if ! linux_chkconfig_present HSA_AMD_SVM; then
ewarn "To use ROCm/HIP, you need to have HSA_AMD_SVM option enabled in your kernel."
fi
fi
fi
}
src_unpack() {
# Already filter lto flags for ROCM
# 963401
if use rocm; then
# copied from _rocm_strip_unsupported_flags
strip-unsupported-flags
export CXXFLAGS="$(test-flags-HIPCXX "${CXXFLAGS}")"
fi
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" \
-i CMakeLists.txt || die "Disable CCACHE sed failed"
# TODO see src_unpack?
sed \
-e "s/ -O3//g" \
-i \
ml/backend/ggml/ggml/src/ggml-cpu/cpu.go \
|| die "-O3 sed failed"
# grep -Rl -e 'lib/ollama' -e '"..", "lib"' --include '*.go'
sed \
-e "s/\"..\", \"lib\"/\"..\", \"$(get_libdir)\"/" \
-e "s#\"lib/ollama\"#\"$(get_libdir)/ollama\"#" \
-i \
ml/backend/ggml/ggml/src/ggml.go \
ml/path.go \
|| die "libdir sed failed"
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
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=(
-DOLLAMA_INSTALL_RUNTIME_DEPS="no"
-DGGML_CCACHE="no"
# backends end up in /usr/bin otherwise
-DGGML_BACKEND_DL="yes"
# TODO causes duplicate install warning but breaks detection otherwise ollama/issues/13614
-DGGML_BACKEND_DIR="${EPREFIX}/usr/$(get_libdir)/${PN}"
# -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)"
"$(cmake_use_find_package vulkan Vulkan)"
)
if tc-is-lto ; then
mycmakeargs+=(
-DGGML_LTO="yes"
)
fi
if use blas; then
if use flexiblas ; then
mycmakeargs+=(
-DGGML_BLAS_VENDOR="FlexiBLAS"
)
elif use blis ; then
mycmakeargs+=(
-DGGML_BLAS_VENDOR="FLAME"
)
elif use mkl ; then
mycmakeargs+=(
-DGGML_BLAS_VENDOR="Intel10_64lp"
)
# elif use nvhpc ; then
# mycmakeargs+=(
# -DGGML_BLAS_VENDOR="NVHPC"
# )
elif use openblas ; then
mycmakeargs+=(
-DGGML_BLAS_VENDOR="OpenBLAS"
)
else
mycmakeargs+=(
-DGGML_BLAS_VENDOR="Generic"
)
fi
fi
if use cuda; then
local -x CUDAHOSTCXX CUDAHOSTLD
CUDAHOSTCXX="$(cuda_gccdir)"
CUDAHOSTLD="$(tc-getCXX)"
# default to all-major for now until cuda.eclass is updated
if [[ ! -v CUDAARCHS ]]; then
local CUDAARCHS="all-major"
fi
mycmakeargs+=(
-DCMAKE_CUDA_ARCHITECTURES="${CUDAARCHS}"
)
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"
else
mycmakeargs+=(
-DCMAKE_HIP_COMPILER="NOTFOUND"
)
fi
cmake_src_configure
}
src_compile() {
# export version information
# https://github.com/gentoo/guru/pull/205
# https://forums.gentoo.org/viewtopic-p-8831646.html
local VERSION
if [[ "${PV}" == *9999* ]]; then
VERSION="$(
git describe --tags --first-parent --abbrev=7 --long --dirty --always \
| sed -e "s/^v//g"
)"
else
VERSION="${PVR}"
fi
local EXTRA_GOFLAGS_LD=(
# "-w" # disable DWARF generation
# "-s" # disable symbol table
"-X=github.com/ollama/ollama/version.Version=${VERSION}"
"-X=github.com/ollama/ollama/server.mode=release"
)
GOFLAGS+=" '-ldflags=${EXTRA_GOFLAGS_LD[*]}'"
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
einfo
einfo "Ollama binds 127.0.0.1 port 11434 by default."
einfo "Change the bind address with the OLLAMA_HOST environment variable."
einfo "See https://docs.ollama.com/faq for more info"
einfo
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
}