summaryrefslogtreecommitdiff
path: root/opencode.spec
blob: b77b67f592d413a53bb78c967b0378d2d467ee6a (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# Source build of opencode 1.19.5 for openEuler 24.03 LTS SP4 (x86_64 + aarch64).
#
# The opencode CLI is a Bun-compiled single binary produced from the upstream
# TypeScript monorepo. The SRPM itself is kept tiny: the upstream source archive
# is fetched in %prep (direct codeload first, then GitHub proxies), Node.js and
# Bun come from the Huawei Cloud mirrors, and the npm dependency tree is
# resolved from the Huawei npm mirror. The models.dev snapshot is shipped
# compressed in Source1 so no models.dev API call is needed while building.
#
# The upstream source is pruned to the CLI + embedded Web UI workspace closure
# (console/stats/desktop/docs/web/storybook/slack/identity/containers/cli/
# sdk-next/function removed). The ghostty-web dependency, which upstream pins
# to a GitHub commit, is switched to the published 0.3.0 npm package so the
# build does not need GitHub git access.
#
# Both supported architectures are built from the same SRPM: %ifarch selects the
# matching Node.js / Bun prebuilt artifacts and the Bun compile target
# (opencode-linux-x64 vs opencode-linux-arm64).

%global debug_package %{nil}
%global __strip /bin/true

%global node_version 24.18.0
%global bun_version 1.4.4

%ifarch x86_64
%global node_arch x64
%global bun_arch x64
%global node_sha256 55aa7153f9d88f28d765fcdad5ae6945b5c0f98a36881703817e4c450fa76742
%global bun_name bun-linux-x64
%global bun_sha256 93ca5a2abe45f3bcac6dd55baff8bb06c4ac824b70f89650b54e5c8b80dbef18
%endif

%ifarch aarch64
%global node_arch arm64
%global bun_arch arm64
%global node_sha256 58c9520501f6ae2b52d5b210444e24b9d0c029a58c5011b797bc1fe7105886f6
%global bun_name bun-linux-aarch64
%global bun_sha256 ab95e7e692a53d25a1baa98ee395a17f5f264aedfb3cb15811432d54142f70eb
%endif

Name:           opencode
Version:        1.19.5
Release:        1%{?dist}
Summary:        The open source coding agent

License:        MIT
URL:            https://github.com/anomalyco/opencode
# Source0 is a zero-byte placeholder; %prep fetches the real archive.
Source0:        opencode-1.19.5.tar.gz
Source1:        models-api.json.xz

ExclusiveArch:  x86_64 aarch64
BuildRequires:  bash
BuildRequires:  ca-certificates
BuildRequires:  chrpath
BuildRequires:  coreutils
BuildRequires:  cpio
BuildRequires:  curl
BuildRequires:  findutils
BuildRequires:  gcc
BuildRequires:  gcc-c++
BuildRequires:  git
BuildRequires:  glibc-devel
BuildRequires:  grep
BuildRequires:  gzip
BuildRequires:  make
BuildRequires:  patch
BuildRequires:  python3
BuildRequires:  sed
BuildRequires:  tar
BuildRequires:  unzip
BuildRequires:  which
BuildRequires:  xz
BuildRequires:  zip
Requires:       glibc

%description
opencode is an AI-powered development tool that runs coding agents in the
terminal. This package is compiled from the upstream TypeScript source using
Bun, and includes the embedded Web UI. It requires only glibc at runtime;
Node.js and Bun are not needed after installation.

%prep
cd %{_builddir}
src_ok=0
for url in \
  "https://codeload.github.com/anomalyco/opencode/tar.gz/refs/tags/v1.19.5" \
  "https://ghfast.top/https://github.com/anomalyco/opencode/archive/refs/tags/v1.19.5.tar.gz" \
  "https://gh-proxy.com/https://github.com/anomalyco/opencode/archive/refs/tags/v1.19.5.tar.gz" \
  "https://github.com/anomalyco/opencode/archive/refs/tags/v1.19.5.tar.gz"; do
  echo "Fetching source from ${url}"
  rm -f src.tar.gz
  if curl --fail --location --retry 2 --connect-timeout 30 --max-time 1800 \
       --output src.tar.gz "${url}"; then
    if tar -tzf src.tar.gz 2>/dev/null | head -1 | grep -q '^opencode-1.19.5/'; then
      src_ok=1
      break
    fi
  fi
  rm -f src.tar.gz
done
if [ "${src_ok}" != "1" ]; then
  echo "ERROR: no source mirror was reachable" >&2
  exit 1
fi
tar -xzf src.tar.gz
cd opencode-1.19.5

# Keep only the CLI + embedded-Web-UI workspace closure.
rm -rf packages/console packages/stats packages/enterprise packages/desktop \
       packages/docs packages/web packages/storybook packages/slack \
       packages/identity packages/containers packages/cli packages/sdk-next \
       packages/function

# Tests, docs, and marketing assets are not build inputs.
rm -rf packages/*/test packages/*/tests packages/*/e2e packages/*/test-browser \
       packages/*/bench packages/*/storybook packages/*/docs packages/*/examples \
       packages/*/example packages/*/__tests__ packages/*/README* \
       packages/*/*/test packages/*/*/tests packages/*/*/e2e \
       packages/*/*/README* sdks github nix infra specs .github README* \
       AGENTS.md CONTRIBUTING.md STATS.md CONTEXT.md perf screenshot-*.png

python3 - <<'PY'
import json
import os

path = "package.json"
data = json.load(open(path))
data["workspaces"]["packages"] = [
    x for x in data["workspaces"]["packages"]
    if x not in ("packages/console/*", "packages/stats/*", "packages/slack")
    and not (x == "packages/sdk/js" and not os.path.isdir(x))
]
json.dump(data, open(path, "w"), indent=2)
open(path, "a").write("\n")

path = "packages/app/package.json"
data = json.load(open(path))
data["dependencies"]["ghostty-web"] = "0.3.0"
json.dump(data, open(path, "w"), indent=2)
open(path, "a").write("\n")
PY

xz -dc %{SOURCE1} > models-api.json

%build
cd opencode-1.19.5
export HOME="%{_builddir}/%{name}-%{version}/.home"
mkdir -p "$HOME"

# Node.js %{node_version} (host architecture)
curl --fail --location --retry 3 --connect-timeout 30 --max-time 1800 \
  --output node.tar.xz \
  "https://mirrors.huaweicloud.com/nodejs/v%{node_version}/node-v%{node_version}-linux-%{node_arch}.tar.xz"
echo '%{node_sha256}  node.tar.xz' | sha256sum -c -
mkdir -p "$HOME/node"
tar -xJf node.tar.xz -C "$HOME/node" --strip-components=1
export PATH="$HOME/node/bin:$PATH"
node --version
npm --version

# Bun %{bun_version} from the npm platform package
curl --fail --location --retry 3 --connect-timeout 30 --max-time 1800 \
  --output bun.tgz \
  "https://mirrors.huaweicloud.com/repository/npm/@oven/%{bun_name}/-/%{bun_name}-%{bun_version}.tgz"
echo '%{bun_sha256}  bun.tgz' | sha256sum -c -
mkdir -p "$HOME/bun"
tar -xzf bun.tgz -C "$HOME/bun" --strip-components=1
export PATH="$HOME/bun/bin:$PATH"
bun --version

export npm_config_registry="https://mirrors.huaweicloud.com/repository/npm/"
export NPM_CONFIG_REGISTRY="$npm_config_registry"
export BUN_CONFIG_REGISTRY="$npm_config_registry"
export npm_config_prefix="$HOME/npm-global"
export NPM_CONFIG_PREFIX="$npm_config_prefix"
mkdir -p "$npm_config_prefix"
export PATH="$npm_config_prefix/bin:$PATH"
npm install -g node-gyp
node-gyp --version

export BUN_INSTALL_CACHE_DIR="$HOME/bun-cache"
export BUN_CONFIG_DISABLE_ANALYTICS=1
export MODELS_DEV_API_JSON="$PWD/models-api.json"
export OPENCODE_VERSION="%{version}"
export OPENCODE_CHANNEL="prod"
export USE_HARD_LINKS=false
export HUSKY=0

bun install
bun run --cwd packages/core fix-node-pty || :
cd packages/opencode
bun run script/build.ts --single

%install
cd opencode-1.19.5
install -Dpm 0755 packages/opencode/dist/opencode-linux-%{bun_arch}/bin/opencode %{buildroot}%{_bindir}/opencode
install -Dpm 0644 LICENSE %{buildroot}%{_datadir}/licenses/%{name}/LICENSE

%check
%{buildroot}%{_bindir}/opencode --version | grep -qx '%{version}'

%files
%license %{_datadir}/licenses/%{name}/LICENSE
%{_bindir}/opencode

%changelog
* Fri Nov 13 2026 user_4518c38f <user_4518c38f@copr.local> - 1.19.5-1
- Build opencode 1.19.5 from source for openEuler 24.03 LTS SP4 (x86_64, aarch64)
- Fetch upstream source at build time (direct codeload + GitHub proxy fallbacks);
  use Huawei Cloud Node/Bun/npm mirrors; switch ghostty-web to the published
  0.3.0 package; ship the models.dev snapshot in Source1