summaryrefslogtreecommitdiff
path: root/ollama.spec
blob: 2a3475051f1e55d8c623fac41766e7e92eb51492 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# topdir: ollama-0.40.13
# 构建系统:CMake superbuild(Go 二进制 + llama.cpp CPU 推理后端)
# 离线适配:vendor tarball(Source1)+ llama.cpp 预打包(Source2)

Name:           ollama
Version:        0.40.13
Release:        4%{?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 源码及 vendored 依赖(golang.org/x/sys、klauspost/compress、
# go-playground/validator、quic-go 等)大量使用 range-over-integer(go 1.22+)
# 和 range-over-func iter.Seq2(go 1.23+)语法。go.mod 的 go 指令同时决定
# 编译器的 -lang 语言版本:若降级到 go 1.21,则 -lang=go1.21 不支持这些语法,
# 导致 66+ 处 "cannot range over N: requires go1.22/go1.23 or later" 编译错误。
#
# 修复:1) 主模块 go.mod 降级 go 1.26.10 -> go 1.24(通过 go 1.24.2 版本检查,
#          且 -lang=go1.24 启用 range-over-int 与 range-over-func 语法支持);
#       2) vendor/modules.txt 中所有 go >= 1.25 的逐模块声明降级为 go 1.21
#          (仅影响版本校验,不影响编译器 -lang;go 1.24.x 声明保留,
#           1.24.2 >= 1.24.x 通过校验)。
sed -i 's/^go 1\.26\.10$/go 1.24/' 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 <ai-importer@openeuler.org> - 0.40.13-4
- Fix Go compilation: go.mod go directive downgraded to go 1.24 (not 1.21)
  because ollama source and vendored deps use range-over-integer (go 1.22+)
  and range-over-func iter.Seq2 (go 1.23+) syntax. go 1.21 sets -lang=go1.21
  which rejects these features (66+ "cannot range over" errors). go 1.24
  passes the 1.24.2 version check and enables the required language features.

* Thu Oct 29 2026 AI Importer <ai-importer@openeuler.org> - 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 <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