summaryrefslogtreecommitdiff
path: root/vere/ext/unwind/build.zig
blob: 95b1939df83d2f7ce66161911de364154751caf9 (plain)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
const std = @import("std");

pub fn build(b: *std.Build) !void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});
    const t = target.result;

    const dep_c = b.dependency("unwind", .{
        .target = target,
        .optimize = optimize,
    });

    const lib = b.addStaticLibrary(.{
        .name = "unwind",
        .target = target,
        .optimize = optimize,
    });

    lib.linkLibC();

    lib.root_module.addCMacro("HAVE_CONFIG_H", "");
    lib.root_module.addCMacro("_GNU_SOURCE", "");
    lib.root_module.addCMacro("NDEBUG", "");
    lib.root_module.addCMacro("__EXTENSIONS__", "");

    const config_h = b.addConfigHeader(.{
        .style = .blank,
        .include_path = "config.h",
    }, .{
        .CONFIG_BLOCK_SIGNALS = "",
        .CONFIG_DEBUG_FRAME = "",
        .CONFIG_MSABI_SUPPORT = null,
        .CONFIG_WEAK_BACKTRACE = 1,
        .CONSERVATIVE_CHECKS = 1,
        .HAVE_ASM_PTRACE_H = 1,
        .HAVE_ASM_PTRACE_OFFSETS_H = null,
        .HAVE_ASM_VSYSCALL_H = null,
        .HAVE_BYTESWAP_H = 1,
        .HAVE_DECL_PTRACE_CONT = 1,
        .HAVE_DECL_PTRACE_POKEDATA = 1,
        .HAVE_DECL_PTRACE_POKEUSER = 1,
        .HAVE_DECL_PTRACE_SETREGSET = 1,
        .HAVE_DECL_PTRACE_SINGLESTEP = 1,
        .HAVE_DECL_PTRACE_SYSCALL = 1,
        .HAVE_DECL_PTRACE_TRACEME = 1,
        .HAVE_DECL_PT_CONTINUE = 1,
        .HAVE_DECL_PT_GETFPREGS = 0,
        .HAVE_DECL_PT_GETREGS = 0,
        .HAVE_DECL_PT_IO = 0,
        .HAVE_DECL_PT_STEP = 1,
        .HAVE_DECL_PT_SYSCALL = 1,
        .HAVE_DECL_PT_TRACE_ME = 1,
        .HAVE_DLFCN_H = 1,
        .HAVE_DLMODINFO = null,
        .HAVE_DL_ITERATE_PHDR = 1,
        .HAVE_DL_PHDR_REMOVALS_COUNTER = null,
        .HAVE_ELF_FPREGSET_T = 1,
        .HAVE_ELF_H = 1,
        .HAVE_ENDIAN_H = 1,
        .HAVE_EXECINFO_H = 1,
        .HAVE_EXECVPE = 1,
        .HAVE_GETUNWIND = null,
        .HAVE_IA64INTRIN_H = null,
        .HAVE_INTTYPES_H = 1,
        .HAVE_LINK_H = 1,
        .HAVE_LZMA = null,
        .HAVE_MEMORY_H = 1,
        .HAVE_MINCORE = 1,
        .HAVE_PIPE2 = 1,
        .HAVE_PROCFS_STATUS = null,
        .HAVE_SIGALTSTACK = 1,
        .HAVE_SIGNAL_H = 1,
        .HAVE_STDINT_H = 1,
        .HAVE_STDLIB_H = 1,
        .HAVE_STRINGS_H = 1,
        .HAVE_STRING_H = 1,
        .HAVE_STRUCT_DL_PHDR_INFO_DLPI_SUBS = 1,
        .HAVE_STRUCT_ELF_PRSTATUS = 1,
        .HAVE_STRUCT_PRSTATUS = null,
        .HAVE_SYS_ELF_H = 1,
        .HAVE_SYS_ENDIAN_H = null,
        .HAVE_SYS_LINK_H = null,
        .HAVE_SYS_PARAM_H = 1,
        .HAVE_SYS_PROCFS_H = 1,
        .HAVE_SYS_PTRACE_H = 1,
        .HAVE_SYS_STAT_H = 1,
        .HAVE_SYS_SYSCALL_H = 1,
        .HAVE_SYS_TYPES_H = 1,
        .HAVE_SYS_UC_ACCESS_H = null,
        .HAVE_TTRACE = null,
        .HAVE_UNISTD_H = 1,
        .HAVE_ZLIB = null,
        .HAVE__BUILTIN_UNREACHABLE = 1,
        .HAVE__BUILTIN___CLEAR_CACHE = 1,
        .HAVE___CACHE_PER_THREAD = null,
        .LT_OBJDIR = ".libs/",
        .PACKAGE = "libunwind",
        .PACKAGE_BUGREPORT = "https://github.com/libunwind/libunwind",
        .PACKAGE_NAME = "libunwind",
        .PACKAGE_STRING = "libunwind 1.8.1",
        .PACKAGE_TARNAME = "libunwind",
        .PACKAGE_URL = "",
        .PACKAGE_VERSION = "1.8.1",
        .SIZEOF_OFF_T = 8,
        .STDC_HEADERS = 1,
        .VERSION = "1.8.1",
        .@"const" = null,
        .@"inline" = null,
        .size_t = null,
    });

    const libunwind_h = b.addConfigHeader(.{
        .style = .{
            .cmake = dep_c.path("include/libunwind.h.in"),
        },
        .include_path = "libunwind.h",
    }, .{ .arch = @tagName(t.cpu.arch) });

    const libunwind_i_h = b.addConfigHeader(.{
        .style = .{
            .cmake = dep_c.path("include/tdep/libunwind_i.h.in"),
        },
        .include_path = "tdep/libunwind_i.h",
    }, .{ .arch = @tagName(t.cpu.arch) });

    const libunwind_common_h = b.addConfigHeader(.{
        .style = .{
            .cmake = dep_c.path("include/libunwind-common.h.in"),
        },
        .include_path = "libunwind-common.h",
    }, .{ .PKG_MAJOR = 1, .PKG_MINOR = 8, .PKG_EXTRA = 1 });

    lib.addConfigHeader(config_h);
    lib.addConfigHeader(libunwind_h);
    lib.addConfigHeader(libunwind_i_h);
    lib.addConfigHeader(libunwind_common_h);
    lib.addIncludePath(dep_c.path("src"));
    lib.addIncludePath(dep_c.path("include"));
    if (t.cpu.arch.isAARCH64())
        lib.addIncludePath(dep_c.path("include/tdep-aarch64"));
    if (t.cpu.arch == .x86_64)
        lib.addIncludePath(dep_c.path("include/tdep-x86_64"));

    var srcs = std.ArrayList([]const u8).init(b.allocator);
    defer srcs.deinit();

    try srcs.appendSlice(&.{
        // libunwind.la
        "os-linux.c",
        "dl-iterate-phdr.c",
        "mi/init.c",
        "mi/flush_cache.c",
        "mi/mempool.c",
        "mi/strerror.c",
        "mi/backtrace.c",
        "mi/dyn-cancel.c",
        "mi/dyn-info-list.c",
        "mi/dyn-register.c",
        "mi/Laddress_validator.c",
        "mi/Ldestroy_addr_space.c",
        "mi/Ldyn-extract.c",
        "mi/Lfind_dynamic_proc_info.c",
        "mi/Lget_accessors.c",
        "mi/Lget_fpreg.c",
        "mi/Lset_fpreg.c",
        "mi/Lget_proc_info_by_ip.c",
        "mi/Lget_proc_name.c",
        "mi/Lget_reg.c",
        "mi/Lput_dynamic_unwind_info.c",
        "mi/Lset_cache_size.c",
        "mi/Lset_caching_policy.c",
        "mi/Lset_iterate_phdr_function.c",
        "mi/Lset_reg.c",
        "mi/Lget_elf_filename.c",
        // libunwind-dwarf-local.la
        "dwarf/Lexpr.c",
        "dwarf/Lfde.c",
        "dwarf/Lfind_proc_info-lsb.c",
        "dwarf/Lfind_unwind_table.c",
        "dwarf/Lget_proc_info_in_range.c",
        "dwarf/Lparser.c",
        "dwarf/Lpe.c",
        // libunwind-dwarf-common.la
        "dwarf/global.c",
        // libunwind-elf64.la
        "elf64.c",
    });

    if (t.cpu.arch.isAARCH64())
        try srcs.appendSlice(&.{
            "aarch64/is_fpreg.c",
            "aarch64/regname.c",
            "aarch64/Los-linux.c",
            "aarch64/getcontext.S",
            "aarch64/Lapply_reg_state.c",
            "aarch64/Lcreate_addr_space.c",
            "aarch64/Lget_proc_info.c",
            "aarch64/Lget_save_loc.c",
            "aarch64/Lglobal.c",
            "aarch64/Linit.c",
            "aarch64/Linit_local.c",
            "aarch64/Linit_remote.c",
            "aarch64/Lis_signal_frame.c",
            "aarch64/Lregs.c",
            "aarch64/Lreg_states_iterate.c",
            "aarch64/Lresume.c",
            "aarch64/Lstash_frame.c",
            "aarch64/Lstep.c",
            "aarch64/Ltrace.c",
            // "aarch64/longjmp.S",
            // "aarch64/setcontext.S",
            // "aarch64/siglongjmp.S",
        });

    if (t.cpu.arch == .x86_64)
        try srcs.appendSlice(&.{
            "x86_64/is_fpreg.c",
            "x86_64/regname.c",
            "x86_64/Los-linux.c",
            "x86_64/getcontext.S",
            "x86_64/Lapply_reg_state.c",
            "x86_64/Lcreate_addr_space.c",
            "x86_64/Lget_proc_info.c",
            "x86_64/Lget_save_loc.c",
            "x86_64/Lglobal.c",
            "x86_64/Linit.c",
            "x86_64/Linit_local.c",
            "x86_64/Linit_remote.c",
            "x86_64/Lregs.c",
            "x86_64/Lreg_states_iterate.c",
            "x86_64/Lresume.c",
            "x86_64/Lstash_frame.c",
            "x86_64/Lstep.c",
            "x86_64/Ltrace.c",
            // "x86_64/longjmp.S",
            "x86_64/setcontext.S",
            // "x86_64/siglongjmp.S",
        });

    lib.addCSourceFiles(.{
        .root = dep_c.path("src"),
        .files = srcs.items,
        .flags = &.{
            "-fno-sanitize=all",
            "-fexceptions",
            "-Wall",
            "-Wsign-compare",
        },
    });

    lib.installConfigHeader(libunwind_h);
    lib.installConfigHeader(libunwind_common_h);
    lib.installHeadersDirectory(dep_c.path("include"), "", .{
        .include_extensions = &.{
            "libunwind-x86_64.h",
            "libunwind-aarch64.h",
            "libunwind-dynamic.h",
        },
    });

    b.installArtifact(lib);
}