summaryrefslogtreecommitdiff
path: root/ollama.spec
blob: a0a5f4f339284b13a3e9f7ae3c4ebdc58aaf6304 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# topdir: ollama-0.40.13
# 构建系统:CMake superbuild(Go 二进制 + llama.cpp CPU 推理后端)
# 离线适配:vendor tarball(Source1)+ llama.cpp 预打包(Source2)

Name:           ollama
Version:        0.40.13
Release:        2%{?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}

# 解压 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

# 适配 chroot golang 1.21.4:上游 go.mod 声明 go 1.26.10
# vendor 模式(-mod=vendor)下 go build 不检查 vendor 中各依赖模块的
# go 版本要求,仅校验主模块 go.mod 的 go 版本声明。降级主模块 go 版本
# 声明以通过 go 1.21.4 工具链的版本检查。
sed -i 's/^go 1\.26\.10$/go 1.21/' go.mod

%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 <ai-importer@openeuler.org> - 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 <ai-importer@openeuler.org> - 0.40.13-1
- Initial package of ollama 0.40.13