-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathbuild.zig
More file actions
168 lines (144 loc) · 5.23 KB
/
build.zig
File metadata and controls
168 lines (144 loc) · 5.23 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
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
const std = @import("std");
pub fn build(b: *std.Build) void {
const cflags = [_][]const u8{ "-Wall", "-Wextra", "-Werror=return-type", "-std=gnu11", "-O2", "-fPIC" };
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const build_core = b.option(bool, "core", "Build the Olaf core and not the CLI interface (default: false)") orelse false;
if (target.result.cpu.arch == .wasm32) {
const lib = b.addExecutable(.{
.name = "olaf_core",
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
});
addCoreSources(lib, b, &cflags, false, false, false); // false = no LMDB sources
lib.linkLibC();
b.installArtifact(lib);
} else {
// if only build core c library olaf_core for linking from other languages
if (build_core) {
const exe = b.addExecutable(.{
.name = "olaf_core",
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
});
addCoreSources(exe, b, &cflags, true, true, false);
exe.linkLibC();
b.installArtifact(exe);
// run step
const run_step = b.addRunArtifact(exe);
run_step.setCwd(b.path(".")); // Set working directory to project root
b.step("run", "Run Olaf core").dependOn(&run_step.step);
if (b.args) |args| {
run_step.addArgs(args);
}
} else {
const exe = b.addExecutable(.{
.name = "olaf",
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.root_source_file = b.path("./cli/olaf_cli.zig"),
}),
});
exe.addIncludePath(b.path("cli"));
exe.addIncludePath(b.path("src"));
addCoreSources(exe, b, &cflags, true, false, true); // true = include LMDB sources
exe.linkLibC();
b.installArtifact(exe);
// run step
const run_step = b.addRunArtifact(exe);
run_step.setCwd(b.path(".")); // Set working directory to project root
b.step("run", "Run Olaf CLI").dependOn(&run_step.step);
if (b.args) |args| {
run_step.addArgs(args);
}
}
}
// Test step
const test_step = b.step("test", "Run Olaf tests");
if (!build_core) {
const test_files = [_][]const u8{
"tests/olaf_unit_tests.zig",
"tests/olaf_functional_tests.zig",
};
for (test_files) |test_file| {
const tests = b.addTest(.{
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.root_source_file = b.path(test_file),
}),
});
tests.addIncludePath(b.path("cli"));
tests.addIncludePath(b.path("src"));
addCoreSources(tests, b, &cflags, true, false, false);
tests.linkLibC();
const run_tests = b.addRunArtifact(tests);
run_tests.setCwd(b.path("."));
test_step.dependOn(&run_tests.step);
}
}
}
/// Add core Olaf C source files to an executable
fn addCoreSources(
exe: *std.Build.Step.Compile,
b: *std.Build,
cflags: []const []const u8,
include_lmdb: bool,
include_olaf_main: bool,
include_cli: bool,
) void {
// Common sources used by all builds
const common_sources = [_][]const u8{
"src/hash-table.c",
"src/pffft.c",
"src/queue.c",
"src/olaf_deque.c",
"src/olaf_max_filter_perceptual_van_herk.c",
"src/olaf_config.c",
"src/olaf_ep_extractor.c",
"src/olaf_fp_db_writer.c",
"src/olaf_fp_db_writer_cache.c",
"src/olaf_fp_file_writer.c",
"src/olaf_fp_extractor.c",
"src/olaf_fp_matcher.c",
"src/olaf_reader_stream.c",
"src/olaf_runner.c",
"src/olaf_stream_processor.c",
};
// LMDB sources (only for native builds)
const lmdb_sources = [_][]const u8{
"src/mdb.c",
"src/midl.c",
};
// Database implementation sources
const db_sources = [_][]const u8{
if (include_lmdb) "src/olaf_db.c" else "src/olaf_db_mem.c",
};
// Add all common sources
for (common_sources) |src| {
exe.addCSourceFile(.{ .file = b.path(src), .flags = cflags });
}
// Add LMDB sources if needed
if (include_lmdb) {
for (lmdb_sources) |src| {
exe.addCSourceFile(.{ .file = b.path(src), .flags = cflags });
}
}
// Add database sources
for (db_sources) |src| {
exe.addCSourceFile(.{ .file = b.path(src), .flags = cflags });
}
// Optionally add main executable source
if (include_olaf_main) {
exe.addCSourceFile(.{ .file = b.path("./src/olaf.c"), .flags = cflags });
}
// Optionally add wrapper bridge
if (include_cli) {
exe.addCSourceFile(.{ .file = b.path("./cli/olaf_cli_bridge.c"), .flags = cflags });
}
}