forked from duckdb/duckdb
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.zig
270 lines (250 loc) · 11.8 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
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
263
264
265
266
267
268
269
270
const std = @import("std");
const builtin = @import("builtin");
pub fn build(b: *std.build.Builder) !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 release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const optimize = b.standardOptimizeOption(.{});
var child = std.ChildProcess.init(&[_][]const u8{ "python3", "scripts/generate_version_hpp.py" }, std.heap.page_allocator);
try child.spawn();
_ = try child.wait();
const fastpforlib = b.addStaticLibrary(.{
.name = "fastpforlib",
.target = target,
.optimize = optimize,
});
fastpforlib.addCSourceFiles((try iterateFiles(b, "third_party/fastpforlib")).items, &.{});
_ = try basicSetup(b, fastpforlib);
const fmt = b.addStaticLibrary(.{
.name = "fmt",
.target = target,
.optimize = optimize,
});
fmt.addCSourceFiles((try iterateFiles(b, "third_party/fmt")).items, &.{});
_ = try basicSetup(b, fmt);
const fsst = b.addStaticLibrary(.{
.name = "fsst",
.target = target,
.optimize = optimize,
});
fsst.addCSourceFiles((try iterateFiles(b, "third_party/fsst")).items, &.{});
_ = try basicSetup(b, fsst);
const hyperloglog = b.addStaticLibrary(.{
.name = "hyperloglog",
.target = target,
.optimize = optimize,
});
hyperloglog.addCSourceFiles((try iterateFiles(b, "third_party/hyperloglog")).items, &.{});
_ = try basicSetup(b, hyperloglog);
const mbedtls = b.addStaticLibrary(.{
.name = "mbedtls",
.target = target,
.optimize = optimize,
});
mbedtls.addCSourceFiles((try iterateFiles(b, "third_party/mbedtls")).items, &.{});
_ = try basicSetup(b, mbedtls);
const miniz = b.addStaticLibrary(.{
.name = "miniz",
.target = target,
.optimize = optimize,
});
miniz.addCSourceFiles((try iterateFiles(b, "third_party/miniz")).items, &.{});
_ = try basicSetup(b, miniz);
const pg_query = b.addStaticLibrary(.{
.name = "pg_query",
.target = target,
.optimize = optimize,
});
pg_query.addCSourceFiles((try iterateFiles(b, "third_party/libpg_query")).items, &.{});
pg_query.addIncludePath(std.build.LazyPath.relative("third_party/libpg_query/include"));
_ = try basicSetup(b, pg_query);
const re2 = b.addStaticLibrary(.{
.name = "re2",
.target = target,
.optimize = optimize,
});
re2.addCSourceFiles((try iterateFiles(b, "third_party/re2")).items, &.{});
_ = try basicSetup(b, re2);
const utf8proc = b.addStaticLibrary(.{
.name = "utf8proc",
.target = target,
.optimize = optimize,
});
utf8proc.addCSourceFiles((try iterateFiles(b, "third_party/utf8proc")).items, &.{});
_ = try basicSetup(b, utf8proc);
const httpfs_extension = b.addStaticLibrary(.{
.name = "httpfs_extension",
.target = target,
.optimize = optimize,
});
httpfs_extension.addCSourceFiles((try iterateFiles(b, "extension/httpfs")).items, &.{});
httpfs_extension.addIncludePath(std.build.LazyPath.relative("extension/httpfs/include"));
httpfs_extension.addIncludePath(std.build.LazyPath.relative("third_party/httplib"));
httpfs_extension.addIncludePath(std.build.LazyPath.relative("third_party/openssl/include"));
httpfs_extension.addIncludePath(std.build.LazyPath.relative("third_party/picohash"));
_ = try basicSetup(b, httpfs_extension);
const icu_extension = b.addStaticLibrary(.{
.name = "icu_extension",
.target = target,
.optimize = optimize,
});
icu_extension.addCSourceFiles((try iterateFiles(b, "extension/icu")).items, &.{});
icu_extension.addIncludePath(std.build.LazyPath.relative("extension/icu/include"));
icu_extension.addIncludePath(std.build.LazyPath.relative("extension/icu/third_party/icu/common"));
icu_extension.addIncludePath(std.build.LazyPath.relative("extension/icu/third_party/icu/i18n"));
_ = try basicSetup(b, icu_extension);
const jemalloc_extension = b.addStaticLibrary(.{
.name = "jemalloc_extension",
.target = target,
.optimize = optimize,
});
jemalloc_extension.addCSourceFiles((try iterateFiles(b, "extension/jemalloc")).items, &.{});
jemalloc_extension.addIncludePath(std.build.LazyPath.relative("extension/jemalloc/include"));
jemalloc_extension.addIncludePath(std.build.LazyPath.relative("extension/jemalloc/jemalloc/include"));
if ((target.isLinux() or builtin.os.tag == .linux)) {
_ = try basicSetup(b, jemalloc_extension);
}
const parquet_extension = b.addStaticLibrary(.{
.name = "parquet_extension",
.target = target,
.optimize = optimize,
});
parquet_extension.addCSourceFiles((try iterateFiles(b, "extension/parquet")).items, &.{});
parquet_extension.addCSourceFiles((try iterateFiles(b, "third_party/parquet")).items, &.{});
parquet_extension.addCSourceFiles((try iterateFiles(b, "third_party/snappy")).items, &.{});
parquet_extension.addCSourceFiles((try iterateFiles(b, "third_party/thrift")).items, &.{});
parquet_extension.addCSourceFiles((try iterateFiles(b, "third_party/zstd")).items, &.{});
parquet_extension.addIncludePath(std.build.LazyPath.relative("extension/parquet/include"));
parquet_extension.addIncludePath(std.build.LazyPath.relative("third_party/parquet"));
parquet_extension.addIncludePath(std.build.LazyPath.relative("third_party/snappy"));
parquet_extension.addIncludePath(std.build.LazyPath.relative("third_party/thrift"));
parquet_extension.addIncludePath(std.build.LazyPath.relative("third_party/zstd/include"));
_ = try basicSetup(b, parquet_extension);
const duckdb_sources = try iterateFiles(b, "src");
const libduckdb = b.addSharedLibrary(.{
.name = "duckdb",
.target = target,
.optimize = optimize,
});
libduckdb.addCSourceFiles(duckdb_sources.items, &.{});
libduckdb.addIncludePath(std.build.LazyPath.relative("/opt/homebrew/opt/openssl@3/"));
libduckdb.addIncludePath(std.build.LazyPath.relative("extension/httpfs/include"));
libduckdb.addIncludePath(std.build.LazyPath.relative("extension/icu/include"));
libduckdb.addIncludePath(std.build.LazyPath.relative("extension/icu/third_party/icu/common"));
libduckdb.addIncludePath(std.build.LazyPath.relative("extension/icu/third_party/icu/i18n"));
libduckdb.addIncludePath(std.build.LazyPath.relative("extension/jemalloc/include"));
libduckdb.addIncludePath(std.build.LazyPath.relative("extension/jemalloc/jemalloc/include"));
libduckdb.addIncludePath(std.build.LazyPath.relative("extension/parquet/include"));
libduckdb.addIncludePath(std.build.LazyPath.relative("third_party/httplib"));
libduckdb.addIncludePath(std.build.LazyPath.relative("third_party/libpg_query/include"));
libduckdb.addIncludePath(std.build.LazyPath.relative("third_party/openssl/include"));
libduckdb.defineCMacro("BUILD_HTTPFS_EXTENSION", "TRUE");
libduckdb.defineCMacro("BUILD_ICU_EXTENSION", "TRUE");
libduckdb.defineCMacro("BUILD_JEMALLOC_EXTENSION", "TRUE");
libduckdb.defineCMacro("BUILD_PARQUET_EXTENSION", "TRUE");
libduckdb.defineCMacro("DUCKDB_MAIN_LIBRARY", null);
libduckdb.defineCMacro("DUCKDB", null);
if (target.isWindows() or builtin.os.tag == .windows) {
libduckdb.addIncludePath(std.build.LazyPath.relative("third_party/openssl/include"));
libduckdb.addObjectFile(std.build.LazyPath.relative("third_party/openssl/lib/libcrypto.lib"));
libduckdb.addObjectFile(std.build.LazyPath.relative("third_party/openssl/lib/libssl.lib"));
libduckdb.addObjectFile(std.build.LazyPath.relative("third_party/win64/ws2_32.lib"));
libduckdb.addObjectFile(std.build.LazyPath.relative("third_party/win64/crypt32.lib"));
libduckdb.addObjectFile(std.build.LazyPath.relative("third_party/win64/cryptui.lib"));
libduckdb.step.dependOn(&b.addInstallFileWithDir(
.{ .path = "third_party/openssl/lib/libssl-3-x64.dll" },
.bin,
"libssl-3-x64.dll",
).step);
libduckdb.step.dependOn(&b.addInstallFileWithDir(
.{ .path = "third_party/openssl/lib/libcrypto-3-x64.dll" },
.bin,
"libcrypto-3-x64.dll",
).step);
}
if (target.isLinux()) {
libduckdb.addIncludePath(std.build.LazyPath.relative("third_party/openssl/include"));
libduckdb.linkSystemLibrary("ssl");
libduckdb.linkSystemLibrary("crypto");
}
if (target.isDarwin()) {
libduckdb.addIncludePath(std.build.LazyPath.relative("/opt/homebrew/opt/openssl@3/"));
libduckdb.addLibraryPath(std.build.LazyPath.relative("/opt/homebrew/opt/openssl@3/lib"));
libduckdb.linkSystemLibrary("ssl");
libduckdb.linkSystemLibrary("crypto");
}
libduckdb.linkLibrary(fastpforlib);
libduckdb.linkLibrary(fmt);
libduckdb.linkLibrary(fsst);
libduckdb.linkLibrary(hyperloglog);
libduckdb.linkLibrary(mbedtls);
libduckdb.linkLibrary(miniz);
libduckdb.linkLibrary(pg_query);
libduckdb.linkLibrary(re2);
libduckdb.linkLibrary(utf8proc);
libduckdb.linkLibrary(parquet_extension);
libduckdb.linkLibrary(httpfs_extension);
libduckdb.linkLibrary(icu_extension);
libduckdb.linkLibrary(jemalloc_extension);
_ = try basicSetup(b, libduckdb);
libduckdb.linkLibC();
}
fn iterateFiles(b: *std.build.Builder, path: []const u8) !std.ArrayList([]const u8) {
var files = std.ArrayList([]const u8).init(b.allocator);
var dir = try std.fs.cwd().openIterableDir(path, .{});
var walker = try dir.walk(b.allocator);
defer walker.deinit();
var out: [256]u8 = undefined;
const exclude_files: []const []const u8 = &.{ "grammar.cpp", "symbols.cpp", "os_win.c", "linenoise.cpp", "parquetcli.cpp", "utf8proc_data.cpp", "test_sqlite3_api_wrapper.cpp" };
const allowed_exts: []const []const u8 = &.{ ".c", ".cpp", ".cxx", ".c++", ".cc" };
while (try walker.next()) |entry| {
const ext = std.fs.path.extension(entry.basename);
const include_file = for (allowed_exts) |e| {
if (std.mem.eql(u8, ext, e))
break true;
} else false;
if (include_file) {
const exclude_file = for (exclude_files) |e| {
if (std.mem.eql(u8, entry.basename, e))
break true;
} else false;
if (!exclude_file) {
const file = try std.fmt.bufPrint(&out, ("{s}/{s}"), .{ path, entry.path });
try files.append(b.dupe(file));
}
}
}
return files;
}
fn basicSetup(b: *std.build.Builder, in: *std.build.LibExeObjStep) !void {
const include_dirs = [_][]const u8{
"src/include",
"third_party/concurrentqueue",
"third_party/fast_float",
"third_party/fastpforlib",
"third_party/fmt/include",
"third_party/fsst",
"third_party/hyperloglog",
"third_party/mbedtls/include",
"third_party/miniparquet",
"third_party/miniz",
"third_party/pcg",
"third_party/re2",
"third_party/tdigest",
"third_party/utf8proc/include",
"third_party/mbedtls/include",
"third_party/jaro_winkler",
};
for (include_dirs) |include_dir| {
in.addIncludePath(std.build.LazyPath.relative(include_dir));
}
in.defineCMacro("DUCKDB_BUILD_LIBRARY", null);
in.linkLibCpp();
in.force_pic = true;
in.strip = true;
b.installArtifact(in);
}