# topdir: ollama-0.40.13 # 构建系统:CMake superbuild(Go 二进制 + llama.cpp CPU 推理后端) # 离线适配:vendor tarball(Source1)+ llama.cpp 预打包(Source2) Name: ollama Version: 0.40.13 Release: 3%{?dist} Summary: Lightweight framework for running large language models locally License: MIT URL: https://github.com/ollama/ollama Source0: https://github.com/ollama/ollama/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz # Source1: Go vendor 依赖(本地 go mod vendor 预生成,离线构建必需) Source1: %{name}-vendor.tar.gz # Source2: llama.cpp 源码(pin b11963,避免 COPR 离线构建时 CMake ExternalProject 联网下载) Source2: llama_cpp_b11963.tar.gz BuildRequires: golang BuildRequires: gcc BuildRequires: gcc-c++ BuildRequires: cmake BuildRequires: make BuildRequires: glibc-devel BuildRequires: sqlite-devel %description Ollama is a lightweight, extensible framework for building and running large language models locally. It provides a simple API for creating, running, and managing models, with a clean CLI and REST interface. This package builds the CPU-only inference backend based on llama.cpp. %prep %autosetup -n %{name}-%{version} # 解压 Go vendor 依赖(离线 -mod=vendor 构建必需) tar xf %{SOURCE1} # 适配 chroot golang(构建日志显示 running go 1.24.2):上游 go.mod 声明 go 1.26.10, # 且 vendor/modules.txt 中多个依赖(gin-contrib/cors、gin-gonic/gin 等 16 个模块) # 声明 go >= 1.25/1.26。GOTOOLCHAIN=local 下 go 工具链会逐模块校验 # vendor/modules.txt 的 go 版本要求(-mod=vendor 不豁免该校验),running go # 1.24.2 < 1.25 → 构建 ollama-go 失败: # go: github.com/gin-contrib/cors in vendor/modules.txt requires go >= 1.26.0 # (running go 1.24.2; GOTOOLCHAIN=local) # 修复:1) 主模块 go.mod 降级 go 1.26.10 -> go 1.21(通过 go 1.24.2 版本检查); # 2) vendor/modules.txt 中所有 go >= 1.25 的逐模块声明降级为 go 1.21 # (go 1.24.x 声明保留,1.24.2 >= 1.24.x 通过校验)。 sed -i 's/^go 1\.26\.10$/go 1.21/' go.mod sed -i -E 's/## explicit; go 1\.2[5-9](\.[0-9]+)?/## explicit; go 1.21/' vendor/modules.txt # 解压 llama.cpp 源码到 llama_cpp/ 子目录 # CMake ExternalProject 通过 OLLAMA_LLAMA_CPP_SOURCE 环境变量引用此目录, # 避免 COPR 离线构建时尝试 git clone github.com/ggml-org/llama.cpp # tarball 顶层目录为 llama.cpp-b11963/,--strip-components=1 去除 mkdir llama_cpp tar xf %{SOURCE2} -C llama_cpp --strip-components=1 %build # Go 离线构建环境配置 # GOTOOLCHAIN=local:禁止 go 自动下载更高版本工具链 # GOFLAGS:-mod=vendor 使用 vendor 目录;-buildvcs=false 关闭 VCS 元数据探测(tarball 构建必需) export GOTOOLCHAIN=local export GOFLAGS="-mod=vendor -buildvcs=false" export CGO_ENABLED=1 # 指定本地 llama.cpp 源码目录,跳过 CMake ExternalProject 联网下载 export OLLAMA_LLAMA_CPP_SOURCE=%{_builddir}/%{name}-%{version}/llama_cpp # CMake superbuild:编排 Go CLI 二进制 + llama.cpp CPU 后端(llama-server、llama-quantize) # OLLAMA_LIB_DIR 必须使用相对路径(%{_lib}/ollama 展开为 lib64/ollama),不能使用 # 绝对路径(%{_libdir}/ollama 展开为 /usr/lib64/ollama)。CMake 的 install(TARGETS # ... DESTINATION) 在目标为绝对路径时会跳过 CMAKE_INSTALL_PREFIX,导致 # ExternalProject 的 install 步骤在 build 阶段直接尝试写入 /usr/lib64/ollama # 而非 staging 目录,非 root 构建环境下因权限不足失败。使用相对路径后, # ExternalProject 会安装到 staging 目录,顶层 install 步骤再通过 DESTDIR # 将文件安装到 buildroot 下正确位置。 cmake -B build -S . \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=%{_prefix} \ -DOLLAMA_VERSION=%{version} \ -DOLLAMA_LIB_DIR=%{_lib}/ollama cmake --build build --parallel %{?_smp_build_ncpus} %install DESTDIR=%{buildroot} cmake --install build %files %license LICENSE %doc README.md %{_bindir}/%{name} %{_libdir}/ollama/ %changelog * Thu Oct 29 2026 AI Importer - 0.40.13-3 - Fix go vendor/modules.txt per-module go version check: downgrade all go >= 1.25 declarations to go 1.21 so the chroot go toolchain (1.24.2, GOTOOLCHAIN=local) passes the vendor version check. -mod=vendor does not exempt per-module go version requirements in vendor/modules.txt. * Thu Oct 29 2026 AI Importer - 0.40.13-2 - Fix CMake ExternalProject install failure: use relative OLLAMA_LIB_DIR (%{_lib}/ollama) instead of absolute path (%{_libdir}/ollama) to prevent install(TARGETS) from bypassing CMAKE_INSTALL_PREFIX during %build staging * Thu Oct 29 2026 AI Importer - 0.40.13-1 - Initial package of ollama 0.40.13