forked from libbpf/libbpf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.zig
123 lines (119 loc) · 2.83 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
113
114
115
116
117
118
119
120
121
122
123
//! Requires zig version: 0.12.0 or higher (w/ pkg-manager)
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{
.whitelist = permissive_targets,
});
const optimize = b.standardOptimizeOption(.{});
const lib = b.addStaticLibrary(.{
.name = "bpf",
.target = target,
.optimize = optimize,
});
if (optimize == .Debug or optimize == .ReleaseSafe)
lib.bundle_compiler_rt = true
else
lib.root_module.strip = true;
lib.addIncludePath(.{ .path = "src" });
lib.addIncludePath(.{ .path = "include" });
lib.addIncludePath(.{ .path = "include/uapi" });
lib.addCSourceFiles(.{ .files = src, .flags = &.{
"-Wall",
"-Wextra",
"-Wpedantic",
} });
lib.defineCMacro("_LARGEFILE64_SOURCE", null);
lib.defineCMacro("_FILE_OFFSET_BITS", "64");
lib.linkSystemLibrary("elf");
lib.linkSystemLibrary("z");
lib.linkLibC();
// copy all headers to zig-out/include
lib.installHeadersDirectory("include", "");
lib.installHeadersDirectoryOptions(.{
.source_dir = .{ .path = "src" },
.install_dir = .header,
.install_subdir = "",
.exclude_extensions = &.{
"c",
"Makefile",
"map",
"template",
},
});
b.installArtifact(lib);
}
const src = &.{
"src/btf.c",
"src/btf_dump.c",
"src/usdt.c",
"src/libbpf_errno.c",
"src/linker.c",
"src/relo_core.c",
"src/str_error.c",
"src/libbpf.c",
"src/bpf_prog_linfo.c",
"src/hashmap.c",
"src/libbpf_probes.c",
"src/bpf.c",
"src/zip.c",
"src/netlink.c",
"src/gen_loader.c",
"src/ringbuf.c",
"src/strset.c",
"src/nlattr.c",
};
const permissive_targets: []const std.Target.Query = &.{
.{
.cpu_arch = .x86_64,
.os_tag = .linux,
.abi = .gnu,
},
.{
.cpu_arch = .x86,
.os_tag = .linux,
.abi = .gnu,
},
.{
.cpu_arch = .x86_64,
.os_tag = .linux,
.abi = .musl,
},
.{
.cpu_arch = .x86,
.os_tag = .linux,
.abi = .musl,
},
.{
.cpu_arch = .aarch64,
.os_tag = .linux,
.abi = .gnu,
},
.{
.cpu_arch = .aarch64,
.os_tag = .linux,
.abi = .musl,
},
.{
.cpu_arch = .riscv64,
.os_tag = .linux,
.abi = .gnu,
// issue: https://github.com/ziglang/zig/issues/3340
},
.{
.cpu_arch = .riscv64,
.os_tag = .linux,
.abi = .musl,
},
.{
.cpu_arch = .powerpc64,
.os_tag = .linux,
.abi = .gnu,
},
.{
.cpu_arch = .powerpc64,
.os_tag = .linux,
.abi = .musl,
},
};
// see all targets list:
// run: zig targets | jq .libc (json format)