forked from duckdb/duckdb
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build_basic.zig
219 lines (208 loc) · 8.05 KB
/
build_basic.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
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("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 duckdb_sources = try iterateFiles(b, "src");
const static = b.addStaticLibrary(.{
.name = "duckdb_sources",
.target = target,
.optimize = optimize,
});
static.addCSourceFiles(duckdb_sources.items, &.{});
static.addIncludePath("third_party/httplib");
static.addIncludePath("third_party/libpg_query/include");
static.defineCMacro("DUCKDB_MAIN_LIBRARY",null);
static.defineCMacro("DUCKDB",null);
static.defineCMacro("SQLITE_OMIT_LOAD_EXTENSION","1");
_ = try basicSetup(b,static);
const sqlite_api = b.addStaticLibrary(.{
.name = "sqlite_api",
.target = target,
.optimize = optimize,
});
sqlite_api.addCSourceFiles(
(try iterateFiles(b, "tools/sqlite3_api_wrapper")).items, &.{});
if (target.isWindows()){
sqlite_api.addCSourceFile(
"tools/sqlite3_api_wrapper/sqlite3/os_win.c",
&.{});}
sqlite_api.addIncludePath("extension");
sqlite_api.addIncludePath("third_party/catch");
sqlite_api.addIncludePath("third_party/libpg_query/include");
sqlite_api.addIncludePath("tools/sqlite3_api_wrapper/include");
sqlite_api.addIncludePath("tools/sqlite3_api_wrapper/sqlite3_udf_api/include");
sqlite_api.addIncludePath("tools/sqlite3_api_wrapper/test/include");
sqlite_api.defineCMacro("SQLITE_SHELL_IS_UTF8", null);
sqlite_api.defineCMacro("USE_DUCKDB_SHELL_WRAPPER", null);
sqlite_api.linkLibrary(static);
sqlite_api.linkLibrary(utf8proc);
_ = try basicSetup(b,sqlite_api);
sqlite_api.linkLibC();
// shell aka DuckDBClient
const shell = b.addExecutable(.{
.name = "duckdb",
.target = target,
.optimize = optimize,
});
shell.addCSourceFile("tools/shell/shell.c", &.{});
shell.addIncludePath("third_party/libpg_query/include");
shell.addIncludePath("tools/shell/include");
shell.addIncludePath("tools/sqlite3_api_wrapper/include");
shell.defineCMacro("DUCKDB_BUILD_LIBRARY",null);
shell.defineCMacro("SQLITE_OMIT_LOAD_EXTENSION", "1");
if (target.isLinux() or builtin.os.tag == .linux){
shell.addCSourceFile(
"tools/shell/linenoise.cpp",&.{});
shell.defineCMacro("HAVE_LINENOISE", "1");
}
if (target.isDarwin() or builtin.os.tag == .macos){
shell.addCSourceFile(
"tools/shell/linenoise.cpp",&.{});
shell.defineCMacro("HAVE_LINENOISE", "1");
}
shell.linkLibrary(fastpforlib);
shell.linkLibrary(fmt);
shell.linkLibrary(fsst);
shell.linkLibrary(hyperloglog);
shell.linkLibrary(mbedtls);
shell.linkLibrary(miniz);
shell.linkLibrary(pg_query);
shell.linkLibrary(re2);
shell.linkLibrary(sqlite_api);
shell.linkLibrary(static);
shell.linkLibrary(utf8proc);
_ = try basicSetup(b,shell);
shell.linkLibC();
shell.want_lto = false;
}
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(include_dir);
}
in.defineCMacro("DUCKDB_BUILD_LIBRARY",null);
in.linkLibCpp();
in.force_pic = true;
in.strip = true;
b.installArtifact(in);
}