Skip to content

Commit ef6cb99

Browse files
improved and add new features (#1)
* improved and add new features * Add comprehensive JSON serialization/deserialization support for all types * update ci * zig fmt . * update readme.md * Fix memory leaks in examples by disabling auto update check
1 parent 1c663df commit ef6cb99

30 files changed

Lines changed: 2950 additions & 534 deletions

.github/workflows/ci.yml

Lines changed: 113 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,127 @@ on:
55
branches: [main]
66
pull_request:
77
branches: [main]
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: ci-${{ github.ref }}
12+
cancel-in-progress: true
813

914
jobs:
10-
test:
11-
name: Test on ${{ matrix.os }}
15+
build:
16+
name: Build & Test
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v5
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Setup Zig
25+
uses: mlugg/setup-zig@v2
26+
with:
27+
version: 0.15.2
28+
29+
- name: Run Zig tests
30+
run: zig build test --summary all
31+
32+
- name: Build library (Debug)
33+
run: zig build -Doptimize=Debug
34+
35+
- name: Build library (ReleaseFast)
36+
run: zig build -Doptimize=ReleaseFast
37+
38+
- name: Run benchmarks
39+
run: zig build bench
40+
41+
- name: Zig format check
42+
run: zig fmt --check src/ examples/ bench/
43+
44+
examples-run:
45+
name: Run Examples (${{ matrix.target }})
46+
needs: build
1247
runs-on: ${{ matrix.os }}
1348
strategy:
49+
fail-fast: false
1450
matrix:
15-
os: [ubuntu-latest, windows-latest, macos-latest]
51+
include:
52+
- os: ubuntu-latest
53+
target: x86_64-linux
54+
- os: ubuntu-latest
55+
target: x86-linux
56+
- os: ubuntu-latest
57+
target: aarch64-linux
58+
- os: macos-latest
59+
target: x86_64-macos
60+
- os: macos-latest
61+
target: aarch64-macos
62+
- os: windows-latest
63+
target: x86_64-windows
64+
- os: windows-latest
65+
target: x86-windows
1666
steps:
17-
- uses: actions/checkout@v5
18-
- uses: mlugg/setup-zig@v2
67+
- name: Checkout
68+
uses: actions/checkout@v4
1969
with:
20-
version: 0.15.0
21-
- name: Run Tests
22-
run: zig build test
70+
fetch-depth: 0
2371

24-
build:
25-
name: Build
72+
- name: Setup Zig
73+
uses: mlugg/setup-zig@v2
74+
with:
75+
version: 0.15.2
76+
77+
- name: Install QEMU and Multilib (Linux)
78+
if: runner.os == 'Linux' && (matrix.target == 'aarch64-linux' || matrix.target == 'x86-linux')
79+
run: |
80+
sudo apt-get update
81+
sudo apt-get install -y qemu-user-static gcc-multilib
82+
if [ "${{ matrix.target }}" = "aarch64-linux" ]; then
83+
sudo apt-get install -y gcc-aarch64-linux-gnu
84+
fi
85+
86+
- name: Run Zig tests on ${{ matrix.target }}
87+
run: zig build test -Dtarget=${{ matrix.target }} --summary all
88+
89+
- name: Run all examples on ${{ matrix.target }}
90+
run: |
91+
echo "Running examples for ${{ matrix.target }}"
92+
zig build run-all-examples -Dtarget=${{ matrix.target }}
93+
94+
examples-build-only:
95+
name: Build (${{ matrix.target }})
96+
needs: build
2697
runs-on: ubuntu-latest
98+
strategy:
99+
fail-fast: false
100+
matrix:
101+
target:
102+
- x86_64-linux
103+
- x86-linux
104+
- aarch64-linux
105+
- x86_64-macos
106+
- aarch64-macos
107+
- x86_64-windows
108+
- x86-windows
109+
- x86_64-freestanding
110+
- aarch64-freestanding
111+
- riscv64-freestanding
112+
- riscv64-linux
113+
- riscv32-linux
114+
- powerpc64le-linux
115+
- mips64-linux
116+
- s390x-linux
117+
- arm-freestanding
118+
- arm-linux-gnueabihf
27119
steps:
28-
- uses: actions/checkout@v5
29-
- uses: mlugg/setup-zig@v2
120+
- name: Checkout
121+
uses: actions/checkout@v4
30122
with:
31-
version: 0.15.0
32-
- name: Build Library
33-
run: zig build
123+
fetch-depth: 0
124+
125+
- name: Setup Zig
126+
uses: mlugg/setup-zig@v2
127+
with:
128+
version: 0.15.2
129+
130+
- name: Build for ${{ matrix.target }} (build-only)
131+
run: zig build -Dtarget=${{ matrix.target }} -Doptimize=Debug

.github/workflows/release.yml

Lines changed: 116 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,39 @@ jobs:
1414
matrix:
1515
os: [ubuntu-latest, windows-latest, macos-latest]
1616
steps:
17-
- uses: actions/checkout@v5
17+
- uses: actions/checkout@v4
1818
- uses: mlugg/setup-zig@v2
1919
with:
20-
version: 0.15.0
20+
version: 0.15.2
2121
- name: Run Tests
2222
run: zig build test
2323

24+
bench:
25+
name: Run Benchmarks
26+
needs: test
27+
runs-on: ubuntu-latest
28+
outputs:
29+
bench_output: ${{ steps.run_bench.outputs.bench_output }}
30+
steps:
31+
- uses: actions/checkout@v4
32+
- uses: mlugg/setup-zig@v2
33+
with:
34+
version: 0.15.2
35+
- name: Run Benchmarks
36+
id: run_bench
37+
run: |
38+
# Run benchmarks (generates benchmark-results.md)
39+
zig build bench || true
40+
41+
# Prepare output for release body from the generated markdown file
42+
echo "bench_output<<EOF" >> $GITHUB_OUTPUT
43+
if [ -f benchmark-results.md ]; then
44+
cat benchmark-results.md >> $GITHUB_OUTPUT
45+
else
46+
echo "No benchmark results found." >> $GITHUB_OUTPUT
47+
fi
48+
echo "EOF" >> $GITHUB_OUTPUT
49+
2450
build-library:
2551
name: Build Library (${{ matrix.target }})
2652
needs: test
@@ -35,42 +61,48 @@ jobs:
3561
- aarch64-linux
3662
- x86_64-macos
3763
- aarch64-macos
64+
- x86_64-freestanding
65+
- aarch64-freestanding
66+
- riscv64-freestanding
67+
- arm-freestanding
3868
steps:
39-
- uses: actions/checkout@v5
69+
- uses: actions/checkout@v4
4070
- uses: mlugg/setup-zig@v2
4171
with:
42-
version: 0.15.0
72+
version: 0.15.2
4373

4474
- name: Build Library
4575
run: zig build -Doptimize=ReleaseSafe -Dtarget=${{ matrix.target }}
4676

47-
- name: Rename Artifact (Windows)
48-
if: contains(matrix.target, 'windows')
49-
run: mv zig-out/lib/zigantic.lib zigantic-${{ matrix.target }}.lib
50-
51-
- name: Rename Artifact (Unix)
52-
if: ${{ !contains(matrix.target, 'windows') }}
53-
run: mv zig-out/lib/libzigantic.a libzigantic-${{ matrix.target }}.a
54-
55-
- name: Upload Artifact
56-
run: gh release upload ${{ github.event.release.tag_name }} ${{ contains(matrix.target, 'windows') && format('zigantic-{0}.lib', matrix.target) || format('libzigantic-{0}.a', matrix.target) }}
77+
- name: Prepare Release Artifacts
78+
run: |
79+
mkdir -p release
80+
if [[ "${{ matrix.target }}" == *"windows"* ]]; then
81+
cp zig-out/lib/zigantic.lib release/zigantic-${{ matrix.target }}.lib || true
82+
else
83+
cp zig-out/lib/libzigantic.a release/libzigantic-${{ matrix.target }}.a || true
84+
fi
85+
86+
- name: Upload Release Artifacts
87+
run: |
88+
gh release upload "${{ github.event.release.tag_name }}" release/* --clobber || true
5789
env:
5890
GH_TOKEN: ${{ secrets.GH_TOKEN }}
5991

6092
update-release:
6193
name: Update Release Description
62-
needs: test
94+
needs: [test, bench]
6395
runs-on: ubuntu-latest
6496
steps:
65-
- uses: actions/checkout@v5
97+
- uses: actions/checkout@v4
6698

6799
- name: Get Release URL
68100
id: get_url
69101
run: echo "url=https://github.com/${{ github.repository }}/archive/refs/tags/${{ github.event.release.tag_name }}.tar.gz" >> $GITHUB_OUTPUT
70102

71103
- uses: mlugg/setup-zig@v2
72104
with:
73-
version: 0.15.0
105+
version: 0.15.2
74106

75107
- name: Calculate Hash
76108
id: calc_hash
@@ -85,27 +117,79 @@ jobs:
85117
body: |
86118
${{ github.event.release.body }}
87119
88-
## Installation
120+
## 📃 Documentation
121+
122+
Full documentation can be found at https://muhammad-fiaz.github.io/zigantic/
123+
124+
## 📦 Installation
125+
126+
### Option A — Automatic (Recommended)
127+
128+
Run this to install the dependency and automatically save the hash:
89129
90130
```bash
91131
zig fetch --save https://github.com/${{ github.repository }}/archive/refs/tags/${{ github.event.release.tag_name }}.tar.gz
92132
```
93133
94-
Then in `build.zig`:
134+
> [!NOTE]
135+
> After running, Zig updates your `build.zig.zon` with the correct hash automatically.
136+
137+
The entry will look like:
95138
96139
```zig
97-
const zigantic = b.dependency("zigantic", .{ .target = target, .optimize = optimize });
98-
exe.root_module.addImport("zigantic", zigantic.module("zigantic"));
140+
.dependencies = .{
141+
.zigantic = .{
142+
.url = "https://github.com/${{ github.repository }}/archive/refs/tags/${{ github.event.release.tag_name }}.tar.gz",
143+
.hash = "${{ steps.calc_hash.outputs.hash }}",
144+
},
145+
},
99146
```
100147
101-
## Prebuilt Libraries
102-
103-
| Platform | File |
104-
|----------|------|
105-
| Windows x86_64 | [zigantic-x86_64-windows.lib](https://github.com/${{ github.repository }}/releases/download/${{ github.event.release.tag_name }}/zigantic-x86_64-windows.lib) |
106-
| Windows x86 | [zigantic-x86-windows.lib](https://github.com/${{ github.repository }}/releases/download/${{ github.event.release.tag_name }}/zigantic-x86-windows.lib) |
107-
| Linux x86_64 | [libzigantic-x86_64-linux.a](https://github.com/${{ github.repository }}/releases/download/${{ github.event.release.tag_name }}/libzigantic-x86_64-linux.a) |
108-
| Linux x86 | [libzigantic-x86-linux.a](https://github.com/${{ github.repository }}/releases/download/${{ github.event.release.tag_name }}/libzigantic-x86-linux.a) |
109-
| Linux aarch64 | [libzigantic-aarch64-linux.a](https://github.com/${{ github.repository }}/releases/download/${{ github.event.release.tag_name }}/libzigantic-aarch64-linux.a) |
110-
| macOS x86_64 | [libzigantic-x86_64-macos.a](https://github.com/${{ github.repository }}/releases/download/${{ github.event.release.tag_name }}/libzigantic-x86_64-macos.a) |
111-
| macOS aarch64 | [libzigantic-aarch64-macos.a](https://github.com/${{ github.repository }}/releases/download/${{ github.event.release.tag_name }}/libzigantic-aarch64-macos.a) |
148+
### Option B — Manual
149+
150+
```bash
151+
zig fetch --hash https://github.com/${{ github.repository }}/archive/refs/tags/${{ github.event.release.tag_name }}.tar.gz
152+
```
153+
154+
Copy that hash into your `build.zig.zon`:
155+
156+
```zig
157+
.hash = "${{ steps.calc_hash.outputs.hash }}"
158+
```
159+
160+
## 📊 Benchmarks
161+
162+
The following benchmark results were captured during the release workflow:
163+
164+
> [!NOTE]
165+
> Benchmarks are automatically generated by GitHub Actions using [bench/benchmark.zig](https://github.com/muhammad-fiaz/zigantic/blob/main/bench/benchmark.zig). Results may vary based on the CI runner environment.
166+
167+
${{ needs.bench.outputs.bench_output }}
168+
169+
## ⬇️ Downloads (Prebuilt Library)
170+
171+
| Platform | Architecture | File |
172+
|----------|--------------|------|
173+
| Windows | x86_64 | [zigantic-x86_64-windows.lib](https://github.com/muhammad-fiaz/zigantic/releases/download/${{ github.event.release.tag_name }}/zigantic-x86_64-windows.lib) |
174+
| Windows | x86 | [zigantic-x86-windows.lib](https://github.com/muhammad-fiaz/zigantic/releases/download/${{ github.event.release.tag_name }}/zigantic-x86-windows.lib) |
175+
| Linux | x86_64 | [libzigantic-x86_64-linux.a](https://github.com/muhammad-fiaz/zigantic/releases/download/${{ github.event.release.tag_name }}/libzigantic-x86_64-linux.a) |
176+
| Linux | x86 | [libzigantic-x86-linux.a](https://github.com/muhammad-fiaz/zigantic/releases/download/${{ github.event.release.tag_name }}/libzigantic-x86-linux.a) |
177+
| Linux | aarch64 (ARM64) | [libzigantic-aarch64-linux.a](https://github.com/muhammad-fiaz/zigantic/releases/download/${{ github.event.release.tag_name }}/libzigantic-aarch64-linux.a) |
178+
| macOS | x86_64 (Intel) | [libzigantic-x86_64-macos.a](https://github.com/muhammad-fiaz/zigantic/releases/download/${{ github.event.release.tag_name }}/libzigantic-x86_64-macos.a) |
179+
| macOS | aarch64 (Apple Silicon) | [libzigantic-aarch64-macos.a](https://github.com/muhammad-fiaz/zigantic/releases/download/${{ github.event.release.tag_name }}/libzigantic-aarch64-macos.a) |
180+
| Bare Metal | x86_64 | [libzigantic-x86_64-freestanding.a](https://github.com/muhammad-fiaz/zigantic/releases/download/${{ github.event.release.tag_name }}/libzigantic-x86_64-freestanding.a) |
181+
| Bare Metal | aarch64 | [libzigantic-aarch64-freestanding.a](https://github.com/muhammad-fiaz/zigantic/releases/download/${{ github.event.release.tag_name }}/libzigantic-aarch64-freestanding.a) |
182+
| Bare Metal | RISC-V 64 | [libzigantic-riscv64-freestanding.a](https://github.com/muhammad-fiaz/zigantic/releases/download/${{ github.event.release.tag_name }}/libzigantic-riscv64-freestanding.a) |
183+
| Bare Metal | ARM | [libzigantic-arm-freestanding.a](https://github.com/muhammad-fiaz/zigantic/releases/download/${{ github.event.release.tag_name }}/libzigantic-arm-freestanding.a) |
184+
185+
### 🛠️ Using Prebuilt Libraries
186+
187+
1. Download the library for your platform.
188+
2. Place it in your project (e.g., in a `libs/` folder).
189+
3. Update your `build.zig`:
190+
191+
```zig
192+
// Assuming you placed the library in `libs/`
193+
exe.addLibraryPath(b.path("libs"));
194+
exe.linkSystemLibrary("zigantic");
195+
```

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ Desktop.ini
3333

3434
# Logs
3535
*.log
36+
benchmark-results.md

0 commit comments

Comments
 (0)