forked from boazsegev/facil.io
-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.zig
112 lines (100 loc) · 4.31 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const std = @import("std");
// Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external
// runner.
pub fn build(b: *std.Build) !void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});
// Standard optimization options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});
const lib = b.addStaticLibrary(.{
.name = "facil.io",
// .root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
// Generate flags
var flags = std.ArrayList([]const u8).init(std.heap.page_allocator);
if (lib.optimize != .Debug) try flags.append("-Os");
try flags.append("-Wno-return-type-c-linkage");
try flags.append("-fno-sanitize=undefined");
//
// let's not override malloc from within the lib
// when used as lib, not sure if it would work as expected anyway
// try flags.append("-DFIO_OVERRIDE_MALLOC");
//
try flags.append("-DFIO_HTTP_EXACT_LOGGING");
if (target.getAbi() == .musl)
try flags.append("-D_LARGEFILE64_SOURCE");
////// TODO DELETEME exe.addIncludePath(.{ .path = tracy_path });
////// TODO DELETEME exe.addCSourceFile(.{ .file = .{ .path = client_cpp }, .flags = tracy_c_flags });
// Include paths
lib.addIncludePath(.{ .path = "." });
lib.addIncludePath(.{ .path = "lib/facil" });
lib.addIncludePath(.{ .path = "lib/facil/fiobj" });
lib.addIncludePath(.{ .path = "lib/facil/cli" });
lib.addIncludePath(.{ .path = "lib/facil/http" });
lib.addIncludePath(.{ .path = "lib/facil/http/parsers" });
// C source files
lib.addCSourceFiles(&.{
"lib/facil/fio.c",
"lib/facil/fio_zig.c",
"lib/facil/http/http.c",
"lib/facil/http/http1.c",
"lib/facil/http/websockets.c",
"lib/facil/http/http_internal.c",
"lib/facil/fiobj/fiobj_numbers.c",
"lib/facil/fiobj/fio_siphash.c",
"lib/facil/fiobj/fiobj_str.c",
"lib/facil/fiobj/fiobj_ary.c",
"lib/facil/fiobj/fiobj_data.c",
"lib/facil/fiobj/fiobj_hash.c",
"lib/facil/fiobj/fiobj_json.c",
"lib/facil/fiobj/fiobject.c",
"lib/facil/fiobj/fiobj_mustache.c",
"lib/facil/cli/fio_cli.c",
}, flags.items);
// link against libc
lib.linkLibC();
// install ("export") headers that might be needed
const headers = [_][]const u8{
// "lib/facil/legacy/fio_mem.h",
// "lib/facil/redis/resp_parser.h",
// "lib/facil/redis/redis_engine.h",
"lib/facil/fiobj/fiobj_data.h",
"lib/facil/fiobj/fiobj_json.h",
"lib/facil/fiobj/fiobj_hash.h",
"lib/facil/fiobj/fiobj_ary.h",
"lib/facil/fiobj/fiobj_numbers.h",
"lib/facil/fiobj/fio_tmpfile.h",
"lib/facil/fiobj/mustache_parser.h",
"lib/facil/fiobj/fiobj_mustache.h",
"lib/facil/fiobj/fiobj4fio.h",
"lib/facil/fiobj/fio_json_parser.h",
"lib/facil/fiobj/fiobject.h",
"lib/facil/fiobj/fiobj_str.h",
"lib/facil/fiobj/fiobj.h",
"lib/facil/fiobj/fio_siphash.h",
// "lib/facil/tls/fio_tls.h",
"lib/facil/cli/fio_cli.h",
"lib/facil/http/parsers/hpack.h",
"lib/facil/http/parsers/websocket_parser.h",
"lib/facil/http/parsers/http1_parser.h",
"lib/facil/http/parsers/http_mime_parser.h",
"lib/facil/http/http_internal.h",
"lib/facil/http/http.h",
"lib/facil/http/http1.h",
"lib/facil/http/websockets.h",
"lib/facil/fio.h",
};
for (headers) |h| lib.installHeader(h, std.fs.path.basename(h));
// This declares intent for the library to be installed into the standard
// location when the user invokes the "install" step (the default step when
// running `zig build`).
b.installArtifact(lib);
}