Skip to content

Commit e1b2d80

Browse files
authored
Merge pull request #16 from inge4pres/upgrade-0.15.2
chore: upgrade Zig to 0.15.2
2 parents 1214534 + de19864 commit e1b2d80

25 files changed

+1504
-320
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
name: CI/CD with Benchmarks
22

3+
env:
4+
ZIG_VERSION: 0.15.2
5+
36
on:
47
push:
58
branches: [ main, develop ]
@@ -14,20 +17,10 @@ jobs:
1417
- uses: actions/checkout@v4
1518

1619
- name: Setup Zig
17-
uses: goto-bus-stop/setup-zig@v2
18-
with:
19-
version: 0.11.0
20-
21-
- name: Restore Zig cache
22-
uses: actions/cache@v3
20+
uses: mlugg/setup-zig@v2
2321
with:
24-
path: |
25-
~/.cache/zig
26-
zig-cache
27-
key: ${{ runner.os }}-zig-${{ hashFiles('**/*.zig', '**/build.zig.zon') }}
28-
restore-keys: |
29-
${{ runner.os }}-zig-
30-
22+
version: ${{env.ZIG_VERSION}}
23+
3124
- name: Build project
3225
run: zig build
3326

@@ -46,19 +39,9 @@ jobs:
4639
- uses: actions/checkout@v4
4740

4841
- name: Setup Zig
49-
uses: goto-bus-stop/setup-zig@v2
50-
with:
51-
version: 0.11.0
52-
53-
- name: Restore Zig cache
54-
uses: actions/cache@v3
42+
uses: mlugg/setup-zig@v2
5543
with:
56-
path: |
57-
~/.cache/zig
58-
zig-cache
59-
key: ${{ runner.os }}-zig-${{ hashFiles('**/*.zig', '**/build.zig.zon') }}
60-
restore-keys: |
61-
${{ runner.os }}-zig-
44+
version: ${{env.ZIG_VERSION}}
6245

6346
- name: Build benchmark tool
6447
run: zig build
@@ -254,4 +237,4 @@ jobs:
254237
}
255238
} catch (error) {
256239
console.log('Performance regression check failed:', error);
257-
}
240+
}

README.md

Lines changed: 144 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,60 +20,136 @@ A blazingly fast gRPC client & server implementation in Zig, designed for maximu
2020
## 🚀 Quick Start
2121

2222
```zig
23-
// Server
24-
const server = try GrpcServer.init(allocator, 50051, "secret-key");
25-
try server.handlers.append(.{
26-
.name = "SayHello",
27-
.handler_fn = sayHello,
28-
});
29-
try server.start();
23+
const std = @import("std");
24+
const GrpcServer = @import("grpc-server").GrpcServer;
25+
26+
pub fn main() !void {
27+
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
28+
defer _ = gpa.deinit();
29+
const allocator = gpa.allocator();
30+
31+
// Create and configure server
32+
var server = try GrpcServer.init(allocator, 50051, "secret-key");
33+
defer server.deinit();
3034
31-
// Client
32-
var client = try GrpcClient.init(allocator, "localhost", 50051);
33-
const response = try client.call("SayHello", "World", .none);
35+
// Register handlers
36+
try server.handlers.append(allocator, .{
37+
.name = "SayHello",
38+
.handler_fn = sayHello,
39+
});
40+
41+
// Start server
42+
try server.start();
43+
}
44+
45+
fn sayHello(request: []const u8, allocator: std.mem.Allocator) ![]u8 {
46+
_ = request;
47+
return allocator.dupe(u8, "Hello from gRPC-zig!");
48+
}
3449
```
3550

3651
## 📚 Examples
3752

3853
### Basic Server
3954

55+
See [examples/basic_server.zig](examples/basic_server.zig) for a complete example.
56+
4057
```zig
4158
const std = @import("std");
42-
const GrpcServer = @import("server.zig").GrpcServer;
59+
const GrpcServer = @import("grpc-server").GrpcServer;
4360
4461
pub fn main() !void {
4562
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
4663
defer _ = gpa.deinit();
64+
const allocator = gpa.allocator();
4765
48-
var server = try GrpcServer.init(gpa.allocator(), 50051, "secret-key");
66+
var server = try GrpcServer.init(allocator, 50051, "secret-key");
4967
defer server.deinit();
5068
5169
try server.start();
5270
}
5371
```
5472

55-
### Streaming
73+
### Basic Client
74+
75+
See [examples/basic_client.zig](examples/basic_client.zig) for a complete example.
5676

5777
```zig
58-
var stream = streaming.MessageStream.init(allocator, 5);
59-
try stream.push("First message", false);
60-
try stream.push("Final message", true);
78+
const std = @import("std");
79+
const GrpcClient = @import("grpc-client").GrpcClient;
80+
81+
pub fn main() !void {
82+
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
83+
defer _ = gpa.deinit();
84+
const allocator = gpa.allocator();
85+
86+
var client = try GrpcClient.init(allocator, "localhost", 50051);
87+
defer client.deinit();
88+
89+
const response = try client.call("SayHello", "World", .none);
90+
defer allocator.free(response);
91+
92+
std.debug.print("Response: {s}\n", .{response});
93+
}
6194
```
6295

96+
### Features
97+
98+
All features are demonstrated in the [examples/](examples/) directory:
99+
100+
- **[Authentication](examples/auth.zig)**: JWT token generation and verification
101+
- **[Compression](examples/compression.zig)**: gzip/deflate support
102+
- **[Streaming](examples/streaming.zig)**: Bi-directional message streaming
103+
- **[Health Checks](examples/health.zig)**: Service health monitoring
104+
63105
## 🔧 Installation
64106

65-
1. Fetch the dependency:
107+
### Option 1: Using zig fetch (Recommended)
108+
109+
1. Add the dependency to your project:
66110

67111
```sh
68-
zig fetch --save "git+https://ziglana/grpc-zig/gRPC-zig#main"
112+
zig fetch --save git+https://github.com/ziglana/gRPC-zig#main
69113
```
70114

71115
2. Add to your `build.zig`:
72116

73117
```zig
74-
const grpc_zig = b.dependency("grpc_zig", .{});
118+
const grpc_zig_dep = b.dependency("grpc_zig", .{
119+
.target = target,
120+
.optimize = optimize,
121+
});
122+
123+
// For server development
124+
exe.root_module.addImport("grpc-server", grpc_zig_dep.module("grpc-server"));
125+
126+
// For client development
127+
exe.root_module.addImport("grpc-client", grpc_zig_dep.module("grpc-client"));
128+
```
129+
130+
3. Import in your code:
131+
132+
```zig
133+
const GrpcServer = @import("grpc-server").GrpcServer;
134+
const GrpcClient = @import("grpc-client").GrpcClient;
135+
```
136+
137+
### Option 2: Manual setup
75138

76-
exe.addModule("grpc", grpc_zig.module("grpc"));
139+
Clone the repository and add it to your `build.zig.zon`:
140+
141+
```zig
142+
.{
143+
.name = "my-project",
144+
.version = "0.1.0",
145+
.dependencies = .{
146+
.grpc_zig = .{
147+
.url = "https://github.com/ziglana/gRPC-zig/archive/refs/heads/main.tar.gz",
148+
// Replace with actual hash after first fetch
149+
.hash = "...",
150+
},
151+
},
152+
}
77153
```
78154

79155
## 🏃 Performance
@@ -123,6 +199,54 @@ The benchmarks automatically run in CI/CD on every pull request and provide perf
123199

124200
📖 **[Detailed Benchmarking Guide](docs/benchmarking.md)**
125201

202+
## 🧪 Testing
203+
204+
### Unit Tests
205+
206+
Run the unit test suite:
207+
208+
```bash
209+
zig build test
210+
```
211+
212+
The test suite covers:
213+
- Compression algorithms (gzip, deflate, none)
214+
- Benchmark handler functionality
215+
- Core protocol functionality
216+
217+
### Integration Tests
218+
219+
Run integration tests with a Python client validating the Zig server:
220+
221+
```bash
222+
cd integration_test
223+
./run_tests.sh
224+
```
225+
226+
Or manually:
227+
228+
```bash
229+
# Build and start the test server
230+
zig build integration_test
231+
./zig-out/bin/grpc-test-server
232+
233+
# In another terminal, run Python tests
234+
cd integration_test
235+
python3 -m venv venv
236+
source venv/bin/activate
237+
pip install -r requirements.txt
238+
python3 test_client.py
239+
```
240+
241+
The integration tests validate:
242+
- HTTP/2 protocol compliance
243+
- gRPC request/response flow
244+
- Compression functionality
245+
- Health checking
246+
- Authentication integration
247+
248+
📖 **[Integration Test Documentation](integration_test/README.md)**
249+
126250
## 🤝 Contributing
127251

128252
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

0 commit comments

Comments
 (0)