-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.zig
97 lines (73 loc) · 2.92 KB
/
build.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const std = @import("std");
const Build = std.Build;
const version = std.SemanticVersion{ .major = 0, .minor = 0, .patch = 1 };
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// Setup library
_ = setupLibrary(b, target, optimize);
// Setup exe
setupExe(b, target, optimize);
// Setup testing
setupTesting(b, target, optimize);
}
fn setupLibrary(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Step.Compile {
const boringssl_include_path = b.path("boringssl/include/openssl");
const boringssl_lib_path = b.path("boringssl/build");
const lib = b.addStaticLibrary(.{
.name = "http2",
.root_source_file = b.path("http2/connection.zig"),
.target = target,
.optimize = optimize,
.version = version,
});
lib.linkLibC();
// Link OpenSSL libraries
lib.linkSystemLibrary("ssl");
lib.linkSystemLibrary("crypto");
lib.addIncludePath(boringssl_include_path);
lib.addLibraryPath(boringssl_lib_path);
lib.addIncludePath(b.path("boringssl/include/openssl"));
b.installArtifact(lib);
return lib;
}
fn setupExe(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) void {
const exe_step = b.step("http2", "Build exe for http2 lib");
const exe = b.addExecutable(.{
.name = "http2",
.root_source_file = b.path("http2.zig"),
.target = target,
.optimize = optimize,
});
exe.linkLibC();
// Link OpenSSL libraries
exe.linkSystemLibrary("ssl");
exe.linkSystemLibrary("crypto");
const boringssl_include_path = b.path("boringssl/include/openssl");
const boringssl_lib_path = b.path("boringssl/build");
exe.addIncludePath(boringssl_include_path);
exe.addLibraryPath(boringssl_lib_path);
exe.addIncludePath(b.path("boringssl/include/openssl"));
b.installArtifact(exe);
exe_step.dependOn(&exe.step);
}
fn setupTesting(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) void {
const test_files = [_]struct { name: []const u8, path: []const u8 }{
.{ .name = "hpack", .path = "http2/hpack.zig" },
.{ .name = "huffman", .path = "http2/huffman.zig" },
.{ .name = "frame", .path = "http2/frame.zig" },
.{ .name = "stream", .path = "http2/stream.zig" },
.{ .name = "connection", .path = "http2/connection.zig" },
};
const test_step = b.step("test", "Run library tests");
for (test_files) |test_file| {
const _test = b.addTest(.{
.name = test_file.name,
.root_source_file = .{ .src_path = .{ .owner = b, .sub_path = test_file.path } },
.target = target,
.optimize = optimize,
});
const run_test = b.addRunArtifact(_test);
test_step.dependOn(&run_test.step);
}
}