-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbuild.zig
More file actions
87 lines (76 loc) · 3.08 KB
/
build.zig
File metadata and controls
87 lines (76 loc) · 3.08 KB
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
const std = @import("std");
const LazyPath = std.Build.LazyPath;
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const system_libduckdb = b.option(bool, "system_libduckdb", "link with system libduckdb") orelse true;
const debug_duckdb = b.option(bool, "debug_duckdb", "compile duckdb with DUCKDB_DEBUG_STACKTRACE") orelse false;
const zuckdb = b.addModule("zuckdb", .{
.root_source_file = b.path("src/zuckdb.zig"),
.target = target,
.optimize = optimize,
});
const c_header: LazyPath, const lib = blk: {
if (system_libduckdb) {
const lib_path = b.path("lib");
zuckdb.addIncludePath(lib_path);
zuckdb.linkSystemLibrary("duckdb", .{});
break :blk .{ b.path("lib/duckdb.h"), null };
} else {
const c_dep = b.lazyDependency("duckdb", .{}) orelse return;
const root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libcpp = true,
});
const c_lib = b.addLibrary(.{
.name = "duckdb",
.root_module = root_module,
});
root_module.addIncludePath(c_dep.path(""));
root_module.addCSourceFiles(.{
.files = &.{"duckdb.cpp"},
.root = c_dep.path(""),
.flags = &.{"-Wno-date-time"},
});
if (debug_duckdb) {
root_module.addCMacro("DUCKDB_DEBUG_STACKTRACE", "");
}
root_module.addCMacro("DUCKDB_STATIC_BUILD", "");
// json tests fail because extension loading does not work
// on the self built version. TODO: statically link core extensions:
// c_lib.root_module.addCMacro("DUCKDB_EXTENSION_JSON_LINKED", "true");
b.installArtifact(c_lib);
b.default_step.dependOn(&b.addInstallHeaderFile(
c_dep.path("duckdb.h"),
"duckdb.h",
).step);
zuckdb.linkLibrary(c_lib);
break :blk .{ c_dep.path("duckdb.h"), c_lib };
}
};
zuckdb.addImport("duckdb_clib", b.addTranslateC(.{
.root_source_file = c_header,
.target = target,
.optimize = optimize,
}).createModule());
{
// Setup Tests
const lib_test = b.addTest(.{
.root_module = zuckdb,
.test_runner = .{ .path = b.path("test_runner.zig"), .mode = .simple },
});
lib_test.root_module.addIncludePath(b.path("lib"));
lib_test.root_module.addLibraryPath(b.path("lib"));
_ = lib;
// if (system_libduckdb) {
// lib_test.root_module.linkSystemLibrary("duckdb", .{});
// } else {
// lib_test.root_module.linkLibrary(lib.?);
// }
const run_test = b.addRunArtifact(lib_test);
run_test.has_side_effects = true;
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_test.step);
}
}