summaryrefslogtreecommitdiff
path: root/vere/ext/backtrace/build.zig
blob: 86cbdcd7ab779cc0bce9faf0c79f8e287afc027e (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
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("backtrace", .{
        .target = target,
        .optimize = optimize,
    });

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

    lib.linkLibC();

    var config_h: *std.Build.Step.ConfigHeader = undefined;

    if (t.os.tag != .windows) {
        config_h = b.addConfigHeader(.{
            .style = .{
                .autoconf = dep_c.path("config.h.in"),
            },
            .include_path = "config.h",
        }, .{
            .BACKTRACE_ELF_SIZE = 64,
            .BACKTRACE_XCOFF_SIZE = 64,
            .HAVE_ATOMIC_FUNCTIONS = 1,
            .HAVE_CLOCK_GETTIME = 1,
            .HAVE_DECL_GETPAGESIZE = 1,
            .HAVE_DECL_STRNLEN = 1,
            .HAVE_DECL__PGMPTR = 0,
            .HAVE_DLFCN_H = 1,
            .HAVE_DL_ITERATE_PHDR = null,
            .HAVE_FCNTL = 0,
            .HAVE_GETEXECNAME = null,
            .HAVE_GETIPINFO = 1,
            .HAVE_INTTYPES_H = 1,
            .HAVE_KERN_PROC = null,
            .HAVE_KERN_PROC_ARGS = null,
            .HAVE_LIBLZMA = 1,
            .HAVE_LINK_H = null,
            .HAVE_LOADQUERY = null,
            .HAVE_LSTAT = 1,
            .HAVE_MACH_O_DYLD_H = null,
            .HAVE_MEMORY_H = 1,
            .HAVE_READLINK = 1,
            .HAVE_STDINT_H = 1,
            .HAVE_STDLIB_H = 1,
            .HAVE_STRINGS_H = 1,
            .HAVE_STRING_H = 1,
            .HAVE_SYNC_FUNCTIONS = 1,
            .HAVE_SYS_LDR_H = null,
            .HAVE_SYS_LINK_H = null,
            .HAVE_SYS_MMAN_H = 1,
            .HAVE_SYS_STAT_H = 1,
            .HAVE_SYS_TYPES_H = 1,
            .HAVE_TLHELP32_H = null,
            .HAVE_UNISTD_H = 1,
            .HAVE_WINDOWS_H = null,
            .HAVE_ZLIB = 1,
            .HAVE_ZSTD = null,
            .LT_OBJDIR = "",
            .PACKAGE_BUGREPORT = "",
            .PACKAGE_NAME = "",
            .PACKAGE_STRING = "",
            .PACKAGE_TARNAME = "",
            .PACKAGE_URL = "",
            .PACKAGE_VERSION = "",
            .STDC_HEADERS = 1,
            ._ALL_SOURCE = 1,
            ._GNU_SOURCE = 1,
            ._POSIX_PTHREAD_SEMANTICS = 1,
            ._TANDEM_SOURCE = 1,
            .__EXTENSIONS__ = 1,
            ._FILE_OFFSET_BITS = null,
            ._LARGE_FILES = null,
            ._MINIX = null,
            ._POSIX_1_SOURCE = null,
            ._POSIX_SOURCE = null,
        });

        if (t.os.tag.isDarwin()) {
            config_h.addValues(.{
                .HAVE_MACH_O_DYLD_H = 1,
            });
        }
    } else {
        config_h = b.addConfigHeader(.{
            .style = .{
                .autoconf = dep_c.path("config.h.in"),
            },
            .include_path = "config.h",
        }, .{
            .BACKTRACE_ELF_SIZE = 64,
            .BACKTRACE_XCOFF_SIZE = 64,
            .HAVE_ATOMIC_FUNCTIONS = 1,
            .HAVE_CLOCK_GETTIME = 1,
            .HAVE_DECL_GETPAGESIZE = 1,
            .HAVE_DECL_STRNLEN = 1,
            .HAVE_DECL__PGMPTR = 0,
            .HAVE_DLFCN_H = 1,
            .HAVE_DL_ITERATE_PHDR = null,
            .HAVE_FCNTL = null,
            .HAVE_GETEXECNAME = null,
            .HAVE_GETIPINFO = 1,
            .HAVE_INTTYPES_H = 1,
            .HAVE_KERN_PROC = null,
            .HAVE_KERN_PROC_ARGS = null,
            .HAVE_LIBLZMA = 1,
            .HAVE_LINK_H = null,
            .HAVE_LOADQUERY = null,
            .HAVE_LSTAT = null,
            .HAVE_MACH_O_DYLD_H = null,
            .HAVE_MEMORY_H = 1,
            .HAVE_READLINK = null,
            .HAVE_STDINT_H = 1,
            .HAVE_STDLIB_H = 1,
            .HAVE_STRINGS_H = 1,
            .HAVE_STRING_H = 1,
            .HAVE_SYNC_FUNCTIONS = 1,
            .HAVE_SYS_LDR_H = null,
            .HAVE_SYS_LINK_H = null,
            .HAVE_SYS_MMAN_H = null,
            .HAVE_SYS_STAT_H = 1,
            .HAVE_SYS_TYPES_H = 1,
            .HAVE_TLHELP32_H = null,
            .HAVE_UNISTD_H = 1,
            .HAVE_WINDOWS_H = 1,
            .HAVE_ZLIB = 1,
            .HAVE_ZSTD = null,
            .LT_OBJDIR = "",
            .PACKAGE_BUGREPORT = "",
            .PACKAGE_NAME = "",
            .PACKAGE_STRING = "",
            .PACKAGE_TARNAME = "",
            .PACKAGE_URL = "",
            .PACKAGE_VERSION = "",
            .STDC_HEADERS = 1,
            ._ALL_SOURCE = 1,
            ._GNU_SOURCE = 1,
            ._POSIX_PTHREAD_SEMANTICS = 1,
            ._TANDEM_SOURCE = 1,
            .__EXTENSIONS__ = 1,
            ._FILE_OFFSET_BITS = null,
            ._LARGE_FILES = null,
            ._MINIX = null,
            ._POSIX_1_SOURCE = null,
            ._POSIX_SOURCE = null,
        });
    }

    const backtrace_supported_h = b.addConfigHeader(.{
        .style = .{
            .cmake = dep_c.path("backtrace-supported.h.in"),
        },
        .include_path = "backtrace-supported.h",
    }, .{
        .BACKTRACE_SUPPORTED = 1,
        .BACKTRACE_USES_MALLOC = 0,
        .BACKTRACE_SUPPORTS_THREADS = 1,
        .BACKTRACE_SUPPORTS_DATA = 1,
    });

    lib.addConfigHeader(config_h);
    lib.addConfigHeader(backtrace_supported_h);
    lib.addIncludePath(dep_c.path(""));

    lib.addCSourceFiles(.{
        .root = dep_c.path(""),
        .files = &.{
            // libbacktrace_la_SOURCES
            "atomic.c",
            "dwarf.c",
            "fileline.c",
            "posix.c",
            "print.c",
            "sort.c",
            "state.c",
            // BACKTRACE_FILES
            "backtrace.c",
            "simple.c",
            "nounwind.c",
            // FORMAT_FILES
            "elf.c",
            "macho.c",
            "pecoff.c",
            "unknown.c",
            "xcoff.c",
            // VIEW_FILES
            if (t.os.tag == .windows) "read.c" else "mmapio.c",
            // ALLOC_FILES
            if (t.os.tag == .windows) "alloc.c" else "mmap.c",
        },
        .flags = &.{
            "-fno-sanitize=all",
        },
    });

    lib.installHeader(dep_c.path("backtrace.h"), "backtrace.h");

    b.installArtifact(lib);
}