Skip to content

Commit d0ad091

Browse files
committed
Build zlib
1 parent 17018b5 commit d0ad091

File tree

5 files changed

+36
-14
lines changed

5 files changed

+36
-14
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ zig fetch --save=re2 git+https://github.com/google/re2#2022-04-01
1313
zig fetch --save=boringssl git+https://github.com/google/boringssl#c63fadbde60a2224c22189d14c4001bbd2a3a629
1414
zig fetch --save=cares git+https://github.com/c-ares/c-ares#v1.34.5
1515
zig fetch --save=gtest git+https://github.com/google/googletest#v1.17.0
16+
zig fetch --save=zlib git+https://github.com/madler/zlib#v1.3.1
1617
```

build.zig

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub fn build(b: *Build) !void {
1515
const boringssl = b.dependency("boringssl", .{});
1616
const cares = b.dependency("cares", .{});
1717
const gtest = b.dependency("gtest", .{});
18+
const zlib = b.dependency("zlib", .{});
1819

1920
const libs_step = b.step("dependencies", "Install libraries libgrpc depends on");
2021

@@ -111,12 +112,26 @@ pub fn build(b: *Build) !void {
111112
sslmod.addCSourceFiles(.{
112113
.root = boringssl.path("src"),
113114
.files = &file_lists.libboringssl_src,
114-
.flags = &cxx_flags,
115+
.flags = &(cxx_flags ++ .{"-fno-exceptions"}),
115116
});
117+
sslmod.addCMacro("OPENSSL_NO_ASM", "1");
118+
sslmod.addCMacro("_GNU_SOURCE", "1");
119+
sslmod.addCMacro("_HAS_EXCEPTIONS", "0");
120+
sslmod.addCMacro("NOMINMAX", "1");
116121
sslmod.addIncludePath(boringssl.path("src/include"));
117122
libssl.installHeadersDirectory(boringssl.path("src/include/openssl"), "openssl", .{});
118123
libs_step.dependOn(&b.addInstallArtifact(libssl, .{}).step);
119124

125+
// zlib
126+
const zmod = b.createModule(.{ .target = target, .optimize = optimize });
127+
const libz = b.addLibrary(.{ .name = "z", .root_module = zmod });
128+
zmod.addCSourceFiles(.{
129+
.root = zlib.path(""),
130+
.files = &file_lists.libz_src,
131+
.flags = &c_flags,
132+
});
133+
libs_step.dependOn(&b.addInstallArtifact(libz, .{}).step);
134+
120135
// Core library
121136
const grpc = b.createModule(.{
122137
.target = target,
@@ -142,6 +157,7 @@ pub fn build(b: *Build) !void {
142157
grpc.linkLibrary(libabseil);
143158
grpc.linkLibrary(libupb);
144159
grpc.linkLibrary(libssl);
160+
grpc.linkLibrary(libz);
145161
if (target.result.os.tag.isDarwin()) {
146162
grpc.linkFramework("CoreFoundation", .{});
147163
grpc.addCMacro("OSATOMIC_USE_INLINED", "1");

build.zig.zon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,9 @@
3434
.url = "git+https://github.com/google/googletest?ref=v1.17.0#52eb8108c5bdec04579160ae17225d66034bd723",
3535
.hash = "N-V-__8AAEV8PgDOBc81AuVJQ9XhGo46f-4dlQ7sXar_M0_i",
3636
},
37+
.zlib = .{
38+
.url = "git+https://github.com/madler/zlib?ref=v1.3.1#51b7f2abdade71cd9bb0e7a373ef2610ec6f9daf",
39+
.hash = "N-V-__8AAB0eQwD-0MdOEBmz7intriBReIsIDNlukNVoNu6o",
40+
},
3741
},
3842
}

generate.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def splitByLanguage(prefix, current):
5656
filelists |= libgrpc
5757
filelists['libcares_src'] = [f.split('/', 3)[-1] for f in filelists.pop('LIBCARES_SRC')]
5858
filelists['libboringssl_src'] = [f.split('/', 3)[-1] for f in filelists.pop('LIBBORINGSSL_SRC')]
59+
filelists['libz_src'] = [f.split('/', 2)[-1] for f in filelists.pop('LIBZ_SRC')]
5960

6061
for name, files in filelists.items():
6162
print(name.lower(), file=sys.stderr)

generated.zig

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,6 @@ pub const public_headers_c = .{
4444
"include/grpc/status.h",
4545
"include/grpc/support/workaround_list.h",
4646
};
47-
pub const libz_src = .{
48-
"third_party/zlib/adler32.c",
49-
"third_party/zlib/compress.c",
50-
"third_party/zlib/crc32.c",
51-
"third_party/zlib/deflate.c",
52-
"third_party/zlib/infback.c",
53-
"third_party/zlib/inffast.c",
54-
"third_party/zlib/inflate.c",
55-
"third_party/zlib/inftrees.c",
56-
"third_party/zlib/trees.c",
57-
"third_party/zlib/uncompr.c",
58-
"third_party/zlib/zutil.c",
59-
};
6047
pub const libgrpc_third_party_abseil_cpp = .{
6148
"absl/base/internal/cycleclock.cc",
6249
"absl/base/internal/low_level_alloc.cc",
@@ -1585,3 +1572,16 @@ pub const libboringssl_src = .{
15851572
"ssl/tls_method.cc",
15861573
"ssl/tls_record.cc",
15871574
};
1575+
pub const libz_src = .{
1576+
"adler32.c",
1577+
"compress.c",
1578+
"crc32.c",
1579+
"deflate.c",
1580+
"infback.c",
1581+
"inffast.c",
1582+
"inflate.c",
1583+
"inftrees.c",
1584+
"trees.c",
1585+
"uncompr.c",
1586+
"zutil.c",
1587+
};

0 commit comments

Comments
 (0)