Skip to content

Commit edba5ba

Browse files
committed
Link libgrpc from the bindings
1 parent 82a243e commit edba5ba

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

README.md

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

33
Status: Work in progress
44

5+
| Refname | libGRPC version | Zig `0.16.x` | Zig `0.15.x` |
6+
|----------|-----------------|--------------|--------------|
7+
| `1.76.0` | `v1.76.0` |||
8+
9+
## Use
10+
11+
Add the dependency in your `build.zig.zon` by running the following command:
12+
```zig
13+
zig fetch --save git+https://github.com/allyourcodebase/grpc#master
14+
```
15+
16+
Then, in your `build.zig`:
17+
```zig
18+
const grpc = b.dependency("grpc", { .target = target, .optimize = optimize });
19+
20+
// to use from Zig:
21+
mod.addImport("cgrpc", grpc.module("cgrpc"));
22+
23+
// to use from C:
24+
exe.linkLibrary(grpc.artifact("grpc"));
25+
```
26+
527
## Bump dependencies
628

729
When bumping upstream version, also bump dependencies. Example:

build.zig

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,15 @@ pub fn build(b: *Build) !void {
263263
\\#include <grpc/credentials.h>
264264
\\#include <grpc/byte_buffer_reader.h>
265265
);
266-
const binding = b.addTranslateC(.{
266+
const grpc_capi = b.addTranslateC(.{
267267
.root_source_file = try include_all.getDirectory().join(b.allocator, "grpc_api.h"),
268268
.target = target,
269269
.optimize = optimize,
270270
});
271-
binding.addIncludePath(upstream.path("include"));
272-
_ = binding.addModule("cgrpc");
271+
grpc_capi.addIncludePath(upstream.path("include"));
272+
273+
const bindings = grpc_capi.addModule("cgrpc");
274+
bindings.linkLibrary(libgrpc);
273275
}
274276
}
275277

0 commit comments

Comments
 (0)