Skip to content

Commit 28391f1

Browse files
authored
feat: add official bun binding (#42)
1 parent 578cba2 commit 28391f1

Some content is hidden

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

42 files changed

+626
-299
lines changed

.github/workflows/CI.yml

Lines changed: 289 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,289 @@
1+
name: Build and Test Zig and Bun
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
zig-build-upload:
13+
strategy:
14+
matrix:
15+
settings:
16+
- os: ubuntu-latest
17+
bun-target: linux-x64-gnu
18+
- os: ubuntu-24.04-arm
19+
bun-target: linux-arm64-gnu
20+
- os: ubuntu-latest
21+
bun-target: linux-x64-musl
22+
- os: ubuntu-24.04-arm
23+
bun-target: linux-arm64-musl
24+
- os: macos-13
25+
bun-target: darwin-x64
26+
- os: macos-latest
27+
bun-target: darwin-arm64
28+
# - os: windows-latest # TODO: https://github.com/ChainSafe/state-transition-z/issues/10
29+
# bun-target: win32-x64-msvc
30+
31+
runs-on: ${{ matrix.settings.os }}
32+
33+
steps:
34+
- name: Checkout Repository
35+
uses: actions/checkout@v4
36+
with:
37+
submodules: recursive # Ensures submodules are cloned
38+
fetch-depth: 0 # Fetches the entire history for all branches
39+
40+
- name: Print OS ${{ matrix.settings.os }}
41+
run: uname -a
42+
- name: Print Architecture ${{ matrix.settings.arch }}
43+
run: uname -m
44+
45+
- name: Verify Submodules
46+
run: |
47+
git submodule update --init --recursive
48+
ls -la blst
49+
50+
- name: Install Zig
51+
uses: mlugg/setup-zig@v1
52+
with:
53+
version: "0.14.0" # Set the required Zig version
54+
55+
- name: Build and Test without portable
56+
run: |
57+
zig build test
58+
59+
- name: Build and Test with portable
60+
run: |
61+
zig build -Dportable=true test
62+
63+
- name: Install Bun
64+
uses: oven-sh/setup-bun@v2
65+
with:
66+
version: 1.2.13
67+
- name: Bun - Install Dependencies
68+
run: bun install
69+
working-directory: ./bun
70+
- name: Build binary using bun-ffi-z
71+
run: bun ./node_modules/.bin/bun-ffi-z build --target ${{ matrix.settings.bun-target }} --optimize ReleaseSafe
72+
working-directory: ./bun
73+
- name: Upload Zig Artifacts
74+
uses: actions/upload-artifact@v4
75+
with:
76+
name: ${{ matrix.settings.bun-target }}
77+
path: 'zig-out/lib/*blst_min_pk.*'
78+
if-no-files-found: error
79+
80+
bun-benchmark:
81+
name: run benchmark on ubuntu-latest x86_64
82+
needs: zig-build-upload
83+
runs-on: ubuntu-latest
84+
steps:
85+
- name: Checkout Repository
86+
uses: actions/checkout@v4
87+
- name: Download artifacts
88+
uses: actions/download-artifact@v4 # no need zig installation, download artifacts from previous job instead
89+
with:
90+
name: linux-x64-gnu
91+
path: zig-out/lib
92+
- name: Install Bun
93+
uses: oven-sh/setup-bun@v2
94+
with:
95+
version: 1.2.13
96+
- name: Bun - Install Dependencies
97+
run: bun install
98+
working-directory: ./bun
99+
- name: Bun - Lint Code
100+
run: bun lint
101+
working-directory: ./bun
102+
- name: Bun - Unit Tests
103+
run: bun test:unit
104+
working-directory: ./bun
105+
- name: Benchmark
106+
run: bun benchmark
107+
working-directory: ./bun
108+
env:
109+
# To write to PRs and commits
110+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
111+
112+
bun-linux-x64-gnu:
113+
name: Test bindings on linux-x64-gnu
114+
needs: zig-build-upload
115+
runs-on: ubuntu-latest
116+
steps:
117+
- name: Checkout Repository
118+
uses: actions/checkout@v4
119+
- name: Download artifacts
120+
uses: actions/download-artifact@v4 # no need zig installation, download artifacts from previous job instead
121+
with:
122+
name: linux-x64-gnu
123+
path: zig-out/lib
124+
- name: Install Bun
125+
uses: oven-sh/setup-bun@v2
126+
with:
127+
version: 1.2.13
128+
- name: Bun - Install Dependencies
129+
run: bun install
130+
working-directory: ./bun
131+
- name: Bun - Unit Tests
132+
run: bun test:unit
133+
working-directory: ./bun
134+
135+
bun-linux-arm64-gnu:
136+
name: Test bindings on linux-arm64-gnu
137+
needs: zig-build-upload
138+
runs-on: ubuntu-latest
139+
steps:
140+
- name: Checkout Repository
141+
uses: actions/checkout@v4
142+
- name: Download artifacts
143+
uses: actions/download-artifact@v4 # no need zig installation, download artifacts from previous job instead
144+
with:
145+
name: linux-arm64-gnu
146+
path: zig-out/lib # download to the same folder of "zig build -Doptimize=ReleaseSafe"
147+
- name: Set up QEMU
148+
uses: docker/setup-qemu-action@v3
149+
with:
150+
platforms: arm64
151+
- run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
152+
- name: Setup and run tests using Bun
153+
uses: addnab/docker-run-action@v3
154+
with:
155+
image: oven/bun:1.2.13
156+
options: '--platform linux/arm64 -v ${{ github.workspace }}:/project -w /project/bun'
157+
run: |
158+
bun install
159+
bun test:unit
160+
161+
bun-linux-x64-musl:
162+
name: Test bindings on linux-x64-musl
163+
needs: zig-build-upload
164+
runs-on: ubuntu-latest
165+
steps:
166+
- name: Checkout Repository
167+
uses: actions/checkout@v4
168+
- name: Download artifacts
169+
uses: actions/download-artifact@v4 # no need zig installation, download artifacts from previous job instead
170+
with:
171+
name: linux-x64-musl
172+
path: zig-out/lib # download to the same folder of "zig build -Doptimize=ReleaseSafe"
173+
- name: Setup and run tests using Bun
174+
uses: addnab/docker-run-action@v3
175+
with:
176+
image: oven/bun:1.2.13-alpine
177+
options: '-v ${{ github.workspace }}:/project -w /project/bun'
178+
run: | # cannot run committeeIndices.test.ts and shuffle.test.ts due to musl is not available: @chainsafe/pubkey-index-map-linux-x64-musl
179+
bun install
180+
bun test test/unit/pubkeyIndexMap.test.ts
181+
182+
bun-linux-arm64-musl:
183+
name: Test bindings on linux-arm64-musl
184+
needs: zig-build-upload
185+
runs-on: ubuntu-latest
186+
steps:
187+
- name: Checkout Repository
188+
uses: actions/checkout@v4
189+
- name: Download artifacts
190+
uses: actions/download-artifact@v4 # no need zig installation, download artifacts from previous job instead
191+
with:
192+
name: linux-arm64-musl
193+
path: zig-out/lib # download to the same folder of "zig build -Doptimize=ReleaseSafe"
194+
- name: Set up QEMU
195+
uses: docker/setup-qemu-action@v3
196+
with:
197+
platforms: arm64
198+
- run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
199+
- name: Setup and run tests using Bun
200+
uses: addnab/docker-run-action@v3
201+
with:
202+
image: oven/bun:1.2.13-alpine
203+
options: '--platform linux/arm64 -v ${{ github.workspace }}:/project -w /project/bun'
204+
run: | # cannot run committeeIndices.test.ts and shuffle.test.ts due to musl is not available: @chainsafe/pubkey-index-map-linux-x64-musl
205+
bun install
206+
bun test test/unit/pubkeyIndexMap.test.ts
207+
208+
bun-darwin:
209+
name: Test bindings on macos
210+
needs: zig-build-upload
211+
strategy:
212+
matrix:
213+
settings:
214+
- os: macos-13
215+
bun-target: darwin-x64
216+
- os: macos-latest
217+
bun-target: darwin-arm64
218+
# - os: windows-latest # TODO: https://github.com/ChainSafe/state-transition-z/issues/10
219+
# bun-target: win32-x64-msvc
220+
runs-on: ${{ matrix.settings.os }}
221+
steps:
222+
- name: Checkout Repository
223+
uses: actions/checkout@v4
224+
- name: Download artifacts
225+
uses: actions/download-artifact@v4 # no need zig installation, download artifacts from previous job instead
226+
with:
227+
name: ${{ matrix.settings.bun-target }}
228+
path: zig-out/lib # download to the same folder of "zig build -Doptimize=ReleaseSafe"
229+
- name: Install Bun
230+
uses: oven-sh/setup-bun@v2
231+
with:
232+
version: 1.2.13
233+
- name: Bun - Install Dependencies
234+
run: bun install
235+
working-directory: ./bun
236+
- name: Bun - Unit Tests
237+
run: bun test:unit
238+
working-directory: ./bun
239+
240+
publish:
241+
name: Publish
242+
runs-on: ubuntu-latest
243+
needs:
244+
- bun-linux-x64-gnu
245+
- bun-linux-arm64-gnu
246+
- bun-linux-x64-musl
247+
- bun-linux-arm64-musl
248+
- bun-darwin
249+
steps:
250+
- name: Opening Release PR
251+
if: github.ref == 'refs/heads/main'
252+
uses: googleapis/release-please-action@v4
253+
id: release
254+
with:
255+
config-file: release-please-config.json
256+
manifest-file: .release-please-manifest.json
257+
- name: Checkout Repository
258+
uses: actions/checkout@v4
259+
- name: Install Bun
260+
uses: oven-sh/setup-bun@v2
261+
with:
262+
version: 1.2.13
263+
- name: Bun - Install Dependencies
264+
if: ${{ steps.release.outputs.release_created }}
265+
run: bun install
266+
working-directory: ./bun
267+
- name: Download all artifacts
268+
if: ${{ steps.release.outputs.release_created }}
269+
uses: actions/download-artifact@v4
270+
with:
271+
path: bun/artifacts
272+
- name: List artifacts
273+
if: ${{ steps.release.outputs.release_created }}
274+
run: ls -R ./bun/artifacts
275+
shell: bash
276+
- name: Create targetPackages
277+
if: ${{ steps.release.outputs.release_created }}
278+
run: bun run prepublishOnly
279+
working-directory: ./bun
280+
- name: List targetPackages
281+
if: ${{ steps.release.outputs.release_created }}
282+
run: ls -R ./bun/targetPackages
283+
shell: bash
284+
- name: Publish
285+
if: ${{ steps.release.outputs.release_created }}
286+
run: bun run publish
287+
working-directory: ./bun
288+
env:
289+
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)