Skip to content

Commit f701db8

Browse files
committed
Add an option to choose link mode
1 parent fd65f9a commit f701db8

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

README.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@
77
| x86_64 |||
88
| arm 64 |||
99

10-
| Refname | libGRPC version | Zig `0.16.x` | Zig `0.15.x` |
11-
|----------|-----------------|:------------:|:------------:|
12-
| `1.76.0` | `v1.76.0` |||
10+
| Refname | libGRPC version | Zig `0.16.x` | Zig `0.15.x` |
11+
|------------|-----------------|:------------:|:------------:|
12+
| `1.76.0+1` | `v1.76.0` |||
1313

1414
## Use
1515

16-
Add the dependency in your `build.zig.zon` by running the following command:
16+
Add the dependency to your `build.zig.zon` by running the following command:
1717
```zig
1818
zig fetch --save git+https://github.com/allyourcodebase/grpc#master
1919
```
2020

2121
Then, in your `build.zig`:
2222
```zig
23-
const grpc = b.dependency("grpc", { .target = target, .optimize = optimize });
23+
const grpc = b.dependency("grpc", {
24+
.target = target,
25+
.optimize = optimize,
26+
.link_mode = .dynamic,
27+
});
2428
2529
// to use from Zig:
2630
mod.addImport("cgrpc", grpc.module("cgrpc"));
@@ -29,6 +33,15 @@ mod.addImport("cgrpc", grpc.module("cgrpc"));
2933
exe.linkLibrary(grpc.artifact("grpc"));
3034
```
3135

36+
## Options
37+
38+
```
39+
-Dlink_mode=[enum] Compile static or dynamic libraries. Defaults to dynamic
40+
Supported Values:
41+
static
42+
dynamic
43+
```
44+
3245
## Bump dependencies
3346

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

build.zig

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ const ExecutableList = std.ArrayList(struct { name: []const u8, mod: *Build.Modu
77
pub fn build(b: *Build) !void {
88
const target = b.standardTargetOptions(.{});
99
const optimize = b.standardOptimizeOption(.{});
10+
const linkmode = b.option(
11+
std.builtin.LinkMode,
12+
"link_mode",
13+
"Compile static or dynamic libraries. Defaults to dynamic",
14+
) orelse .dynamic;
1015

1116
// Dependencies
1217
const upstream = b.dependency("upstream", .{});
@@ -185,7 +190,11 @@ pub fn build(b: *Build) !void {
185190
.optimize = optimize,
186191
.link_libcpp = true,
187192
});
188-
const libgrpc = b.addLibrary(.{ .name = "grpc", .root_module = grpc });
193+
const libgrpc = b.addLibrary(.{
194+
.name = "grpc",
195+
.root_module = grpc,
196+
.linkage = linkmode,
197+
});
189198

190199
grpc.addCSourceFiles(.{
191200
.root = upstream.path("src/core"),
@@ -322,6 +331,7 @@ pub fn build(b: *Build) !void {
322331
ite.mod.linkLibrary(libgrpc);
323332
ite.mod.linkLibrary(libgtest);
324333
ite.mod.linkLibrary(libabseil);
334+
ite.mod.linkFramework("CoreFoundation", .{});
325335
example_step.dependOn(&install_exe.step);
326336
test_step.dependOn(&run_exe.step);
327337
}

0 commit comments

Comments
 (0)