Skip to content

Commit f2a00ef

Browse files
Peefyclaude
andauthored
feat(release): vendor prebuilt runtimes on release branches only (#407)
go/lib/<platform>/ and wasm/kcl.wasm are ~370MB of compiled artifacts and ~89% of the tracked tree, and every one of them is reproducible from the kcl-lang/kcl release of the same version. They are now tracked on release/* branches and release tags only; development branches drop them and fetch them on demand, which takes a fresh clone from 394MB to 21MB. Same shape as wasmtime-go: an empty build/ directory on main plus a CI script that fills it in, with the artifacts committed onto the release. - hack/download-libs.sh fetches the platform's runtime from the matching kcl-lang/kcl release, cross-compiling the two iOS static archives from c/ since those have no published asset. Nine CI jobs now call it. - vendor-libs.yaml vendors everything onto a pushed release/* branch. It commits to the branch rather than force-updating a tag, because wasm-test.yaml publishes @kcl-lib/wasm to npm on a tag push and kcl.wasm is in that package's files: a workflow that rewrites the tag afterwards races the publish and silently ships a package with no runtime in it. - go/lib embeds the platform binary with //go:embed, which is a compile time dependency, so the six embed files take a !no_libembed opt-out and a new kcl_lib_noembed.go covers -tags no_libembed. install now rejects an empty CliLib with an actionable error instead of writing a zero-byte library that fails later at dlopen. Breaking for anyone building from a development branch: run hack/download-libs.sh, or build with -tags no_libembed to type-check. Release tags are unaffected. History is left alone on purpose -- filter-repo would strip the binaries from the existing v0.12.x tags. The dart-test windows-11-arm leg is commented out for now: it passed only because go/lib/windows-arm64/kcl.dll was committed here, and no kcl release publishes that asset yet. kcl-lang/kcl#2219 adds the target to that repo's release matrix; re-enable the leg once a release carrying it is out. Signed-off-by: Peefy <xpf6677@163.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1283573 commit f2a00ef

42 files changed

Lines changed: 750 additions & 18 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ast-diff-test.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ jobs:
250250
if: matrix.binding == 'dart'
251251
shell: bash
252252
run: |
253+
# Not tracked on the development branches; see docs/lib-vendoring.md.
254+
"$GITHUB_WORKSPACE/lib/hack/download-libs.sh" linux-amd64
253255
lib="$GITHUB_WORKSPACE/lib/go/lib/linux-amd64/libkcl.so"
254256
test -f "$lib" || (echo "missing prebuilt libkcl at $lib"; exit 1)
255257
echo "KCL_DART_LIB=$lib" >> "$GITHUB_ENV"

‎.github/workflows/dart-test.yaml‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,15 @@ jobs:
5050
- macos-latest # darwin-arm64
5151
- macos-15-intel # darwin-amd64
5252
- windows-latest # windows-amd64
53-
- windows-11-arm # windows-arm64
53+
# windows-11-arm is out until kcl-lang/kcl publishes a
54+
# kcl-lib-<version>-windows-arm64.zip: kcl-lang/kcl#2219 adds the
55+
# target to that repo's release matrix, but no released version has
56+
# the asset yet, so hack/download-libs.sh 404s and the leg fails.
57+
# This leg used to pass only because go/lib/windows-arm64/kcl.dll was
58+
# committed here, which is exactly what #207 stops doing. Re-add the
59+
# line once the first kcl release carrying the asset is out and
60+
# KCL_VERSION in go/install/install.go points at it.
61+
# - windows-11-arm # windows-arm64
5462
- windows-latest # windows-amd64
5563
runs-on: ${{ matrix.os }}
5664
steps:
@@ -121,6 +129,13 @@ jobs:
121129
echo "name=$name" >> "$GITHUB_OUTPUT"
122130
echo "ext=$ext" >> "$GITHUB_OUTPUT"
123131
132+
- name: Download the prebuilt libkcl runtime
133+
shell: bash
134+
run: |
135+
# Not tracked on the development branches; see docs/lib-vendoring.md.
136+
# The platform key mapped above is also the kcl release target name.
137+
../hack/download-libs.sh "${{ steps.arch.outputs.dir }}"
138+
124139
- name: Set KCL_DART_LIB
125140
shell: bash
126141
working-directory: "dart"

‎.github/workflows/go-test.yaml‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,29 @@ jobs:
8888
musl-dev \
8989
gcc \
9090
git \
91-
make
91+
make \
92+
bash \
93+
curl
94+
95+
# The prebuilt libkcl binaries are not tracked on the development
96+
# branches (docs/lib-vendoring.md). The //go:embed in go/lib needs this
97+
# platform's copy to compile at all. The script resolves the repository
98+
# root from its own path, so the `go` working-directory is fine.
99+
#
100+
# The musl leg is the odd one out: `go test` there builds for two
101+
# platforms at once — the linux/amd64 test binaries the runner executes,
102+
# and the musl cross-compile. So it needs BOTH the linux-amd64 shared
103+
# library (selected by the implicit _GOOS_GOARCH constraint on
104+
# kcl_lib_linux_amd64.go) and the linux-musl-amd64 static archive that
105+
# the cgo LDFLAGS in go/lib link against.
106+
- name: Download the prebuilt libkcl runtime
107+
shell: bash
108+
run: |
109+
if [ -n "${{ matrix.container }}" ]; then
110+
../hack/download-libs.sh linux-amd64 linux-musl-amd64
111+
else
112+
../hack/download-libs.sh
113+
fi
92114
93115
- name: Go mod tidy
94116
run: go mod tidy

‎.github/workflows/julia-test.yaml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ jobs:
4040
runs-on: ${{ matrix.os }}
4141
steps:
4242
- uses: actions/checkout@v7
43+
- name: Download the prebuilt libkcl runtime
44+
shell: bash
45+
run: |
46+
# Not tracked on the development branches; see docs/lib-vendoring.md.
47+
../hack/download-libs.sh
4348
- name: Setup Julia
4449
uses: julia-actions/setup-julia@v3
4550
with:

‎.github/workflows/php-test.yaml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ jobs:
4343
runs-on: ${{ matrix.os }}
4444
steps:
4545
- uses: actions/checkout@v7
46+
- name: Download the prebuilt libkcl runtime
47+
shell: bash
48+
run: |
49+
# Not tracked on the development branches; see docs/lib-vendoring.md.
50+
../hack/download-libs.sh
4651
- name: Setup PHP
4752
uses: shivammathur/setup-php@v2
4853
with:

‎.github/workflows/publish-kcltool.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ jobs:
108108
uses: actions/checkout@v7
109109
with:
110110
repository: kcl-lang/lib
111+
# Release tags carry the vendored go/lib binaries; the development
112+
# branches do not. See docs/lib-vendoring.md.
111113
ref: ${{ env.KCL_LIB_REF }}
112114
path: lib-src
113115

‎.github/workflows/vendor-libs.yaml‎

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
name: vendor-libs
2+
3+
# The development branches deliberately do not carry the prebuilt libkcl
4+
# binaries or kcl.wasm — they are ~370MB of compiled artifacts reproducible
5+
# from the kcl-lang/kcl release of the same version. This workflow vendors them
6+
# onto a release branch, and release tags are cut from that branch so consumers
7+
# pinning a tag get a self-contained tree.
8+
#
9+
# Why a branch and not a force-moved tag: wasm-test.yaml publishes
10+
# @kcl-lib/wasm to npm on a tag push, and kcl.wasm is in that package's `files`
11+
# array. Vendoring by force-updating the tag after the fact would let npm
12+
# publish run against the pre-vendoring commit and silently ship a package with
13+
# no runtime in it. See docs/lib-vendoring.md for the full procedure.
14+
on:
15+
push:
16+
branches:
17+
- 'release/v*'
18+
workflow_dispatch:
19+
inputs:
20+
branch:
21+
description: Release branch to vendor onto, e.g. release/v0.13.2
22+
required: true
23+
type: string
24+
kcl_version:
25+
description: >-
26+
kcl-lang/kcl release to fetch from. Defaults to the version in the
27+
branch name. Override only when the lib and kcl versions diverge.
28+
required: false
29+
type: string
30+
31+
concurrency:
32+
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
33+
cancel-in-progress: false
34+
35+
# contents: write so the vendoring commit can be pushed back to the branch.
36+
permissions:
37+
contents: write
38+
39+
jobs:
40+
# The kcl-lang/kcl release has to be published before this branch is pushed;
41+
# see docs/lib-vendoring.md.
42+
prebuilt:
43+
name: Fetch prebuilt runtimes
44+
runs-on: ubuntu-latest
45+
outputs:
46+
branch: ${{ steps.vars.outputs.branch }}
47+
lib_version: ${{ steps.vars.outputs.lib_version }}
48+
kcl_version: ${{ steps.vars.outputs.kcl_version }}
49+
steps:
50+
- uses: actions/checkout@v7
51+
52+
- name: Resolve versions
53+
id: vars
54+
env:
55+
DISPATCH_BRANCH: ${{ inputs.branch }}
56+
DISPATCH_KCL_VERSION: ${{ inputs.kcl_version }}
57+
PUSH_REF: ${{ github.ref }}
58+
run: |
59+
set -euo pipefail
60+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
61+
branch="$DISPATCH_BRANCH"
62+
else
63+
branch="${PUSH_REF#refs/heads/}"
64+
fi
65+
if [[ ! "$branch" =~ ^release/v[0-9] ]]; then
66+
echo "::error::expected a release/v<version> branch, got '$branch'"
67+
exit 1
68+
fi
69+
70+
# The lib version is the branch name; the SDK advertises it on first
71+
# run and InstallKcl keys its cache directory off it, so vendoring a
72+
# libkcl from a different version than the SDK claims would be a
73+
# silent ABI mismatch. Same guard as publish-kcltool.yaml.
74+
lib_version="v${branch#release/}"
75+
sdk_version="$(sed -nE 's/^const KCL_VERSION[[:space:]]*=[[:space:]]*"([^"]+)".*/\1/p' go/install/install.go)"
76+
echo "branch: $branch"
77+
echo "lib version: $lib_version"
78+
echo "SDK KCL_VERSION: $sdk_version"
79+
if [ "$sdk_version" != "$lib_version" ]; then
80+
echo "::error::go/install/install.go KCL_VERSION ($sdk_version) does not match the branch version ($lib_version). Bump one of them before vendoring."
81+
exit 1
82+
fi
83+
84+
kcl_version="$DISPATCH_KCL_VERSION"
85+
if [ -z "$kcl_version" ]; then
86+
kcl_version="$lib_version"
87+
fi
88+
echo "kcl release: $kcl_version"
89+
{
90+
echo "branch=$branch"
91+
echo "lib_version=$lib_version"
92+
echo "kcl_version=$kcl_version"
93+
} >> "$GITHUB_OUTPUT"
94+
95+
- name: Download and stage
96+
run: |
97+
./hack/download-libs.sh --version "${{ steps.vars.outputs.kcl_version }}" \
98+
linux-amd64 linux-arm64 linux-musl-amd64 linux-musl-arm64 \
99+
darwin-amd64 darwin-arm64 windows-amd64 windows-arm64 \
100+
wasm32-wasip1
101+
102+
- name: Inventory
103+
run: |
104+
set -euo pipefail
105+
find go/lib wasm -type f \
106+
\( -name 'libkcl.*' -o -name 'kcl.dll' -o -name 'kcl.wasm' \) \
107+
-exec ls -la {} +
108+
109+
- uses: actions/upload-artifact@v7
110+
with:
111+
name: prebuilt-libs
112+
path: |
113+
go/lib/*/libkcl.so
114+
go/lib/*/libkcl.dylib
115+
go/lib/*/libkcl.a
116+
go/lib/*/kcl.dll
117+
wasm/kcl.wasm
118+
if-no-files-found: error
119+
120+
# iOS has no prebuilt source: go/lib/ios-*/libkcl.a is the kcl-lib-c static
121+
# archive built from this repository's c/ crate, so it is cross-compiled
122+
# here rather than downloaded. Same recipe as build-libkcl-mobile.yaml.
123+
ios:
124+
name: Cross-compile iOS static archives
125+
runs-on: macos-latest
126+
needs: [prebuilt]
127+
steps:
128+
- uses: actions/checkout@v7
129+
130+
- name: Build
131+
run: |
132+
set -euo pipefail
133+
./hack/download-libs.sh \
134+
--version "${{ needs.prebuilt.outputs.kcl_version }}" \
135+
ios-arm64 ios-arm64-sim
136+
137+
- name: Verify architectures
138+
run: |
139+
set -euo pipefail
140+
lipo -info go/lib/ios-arm64/libkcl.a
141+
lipo -info go/lib/ios-arm64-sim/libkcl.a
142+
143+
- uses: actions/upload-artifact@v7
144+
with:
145+
name: ios-libs
146+
path: |
147+
go/lib/ios-arm64/libkcl.a
148+
go/lib/ios-arm64-sim/libkcl.a
149+
if-no-files-found: error
150+
151+
vendor:
152+
name: Commit the binaries onto the release branch
153+
runs-on: ubuntu-latest
154+
needs: [prebuilt, ios]
155+
steps:
156+
- uses: actions/checkout@v7
157+
with:
158+
# Full history so the commit lands on the branch tip.
159+
fetch-depth: 0
160+
ref: ${{ needs.prebuilt.outputs.branch }}
161+
162+
- uses: actions/download-artifact@v8
163+
with:
164+
path: staged
165+
166+
# Both artifacts are rooted at the repository, so they merge into one
167+
# staged/ tree without colliding on a path.
168+
- name: Merge into the working tree
169+
run: |
170+
set -euo pipefail
171+
test -d staged/go/lib || { echo "::error::no artifacts downloaded"; exit 1; }
172+
mkdir -p go/lib wasm
173+
cp -Rv staged/go/lib/. go/lib/
174+
test -f staged/wasm/kcl.wasm
175+
install -m 0755 staged/wasm/kcl.wasm wasm/kcl.wasm
176+
177+
- name: Sanity-check the staged tree
178+
run: |
179+
set -euo pipefail
180+
missing=0
181+
for f in \
182+
go/lib/darwin-amd64/libkcl.dylib go/lib/darwin-arm64/libkcl.dylib \
183+
go/lib/linux-amd64/libkcl.so go/lib/linux-arm64/libkcl.so \
184+
go/lib/linux-musl-amd64/libkcl.a go/lib/linux-musl-arm64/libkcl.a \
185+
go/lib/windows-amd64/kcl.dll go/lib/windows-arm64/kcl.dll \
186+
go/lib/ios-arm64/libkcl.a go/lib/ios-arm64-sim/libkcl.a \
187+
wasm/kcl.wasm ; do
188+
if [ ! -s "$f" ]; then
189+
echo "::error::missing or empty $f"
190+
missing=1
191+
fi
192+
done
193+
[ "$missing" -eq 0 ] || exit 1
194+
du -sh go/lib wasm/kcl.wasm
195+
196+
- name: Commit the binaries onto the branch
197+
env:
198+
BRANCH: ${{ needs.prebuilt.outputs.branch }}
199+
TAG: ${{ needs.prebuilt.outputs.lib_version }}
200+
run: |
201+
set -euo pipefail
202+
git config user.name "github-actions[bot]"
203+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
204+
205+
# go/.gitignore and wasm/.gitignore exclude these on purpose so the
206+
# development branches stay small. Force-add: this is the one place
207+
# the artifacts are meant to be tracked.
208+
git add -f \
209+
go/lib/darwin-amd64/libkcl.dylib go/lib/darwin-arm64/libkcl.dylib \
210+
go/lib/linux-amd64/libkcl.so go/lib/linux-arm64/libkcl.so \
211+
go/lib/linux-musl-amd64/libkcl.a go/lib/linux-musl-arm64/libkcl.a \
212+
go/lib/windows-amd64/kcl.dll go/lib/windows-arm64/kcl.dll \
213+
go/lib/ios-arm64/libkcl.a go/lib/ios-arm64-sim/libkcl.a \
214+
wasm/kcl.wasm
215+
216+
if git diff --cached --quiet; then
217+
echo "Already vendored; nothing to commit."
218+
exit 0
219+
fi
220+
git commit -m "chore(release): vendor prebuilt runtimes for ${TAG}"
221+
git push origin "HEAD:${BRANCH}"
222+
223+
- name: Summary
224+
if: always()
225+
env:
226+
BRANCH: ${{ needs.prebuilt.outputs.branch }}
227+
TAG: ${{ needs.prebuilt.outputs.lib_version }}
228+
run: |
229+
echo "::notice title=Release branch ready::\`${BRANCH}\` now carries the prebuilt runtimes."
230+
echo "Cut the release tag from this branch, not from main:"
231+
echo '```'
232+
echo "git tag ${TAG} ${BRANCH}"
233+
echo "git push origin ${TAG}"
234+
echo '```'

‎.github/workflows/wasm-test.yaml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ jobs:
3636
with:
3737
node-version: 22.x
3838

39+
# kcl.wasm is the runtime this package wraps: it is listed in
40+
# package.json "files", so it is both what the tests execute and what
41+
# `npm publish` ships. It is not tracked on the development branches —
42+
# see docs/lib-vendoring.md.
43+
- name: Download kcl.wasm
44+
run: ../hack/download-libs.sh --wasm
45+
3946
- name: Install dependencies
4047
run: npm install
4148

‎.github/workflows/zig-test.yaml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ jobs:
3636
runs-on: ${{ matrix.os }}
3737
steps:
3838
- uses: actions/checkout@v7
39+
- name: Download the prebuilt libkcl runtime
40+
shell: bash
41+
run: |
42+
# zig/build.zig links ../go/lib/<platform>/; not tracked on the
43+
# development branches. See docs/lib-vendoring.md.
44+
../hack/download-libs.sh
3945
- uses: korandoru/setup-zig@v1
4046
with:
4147
zig-version: 0.16.0

‎README.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
This repo mainly includes the binding of the low-level API and spec of the [KCL language core](https://github.com/kcl-lang/kcl), and the SDKs of various languages are based on this to encapsulate higher-level APIs.
44

5+
> **The prebuilt native runtimes are not on `main`.** `go/lib/<platform>/` and
6+
> `wasm/kcl.wasm` are ~370MB of compiled binaries, reproducible from the
7+
> [kcl-lang/kcl](https://github.com/kcl-lang/kcl) release of the same version.
8+
> Development branches do not carry them; run `hack/download-libs.sh` (add
9+
> `--wasm` for the npm package) before building anything that links against the
10+
> runtime. Release branches and release tags do carry them — see
11+
> [docs/lib-vendoring.md](./docs/lib-vendoring.md).
12+
513
## Bindings
614

715
### Rust

0 commit comments

Comments
 (0)