summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig100
1 files changed, 66 insertions, 34 deletions
diff --git a/build.zig b/build.zig
index a217191..592055b 100644
--- a/build.zig
+++ b/build.zig
@@ -182,16 +182,19 @@ pub fn build(b: *std.build.Builder) !void {
182 const use_bundled = b.option(bool, "use_bundled", "Use the bundled sqlite3 source instead of linking the system library (default false)"); 182 const use_bundled = b.option(bool, "use_bundled", "Use the bundled sqlite3 source instead of linking the system library (default false)");
183 183
184 const target = b.standardTargetOptions(.{}); 184 const target = b.standardTargetOptions(.{});
185 const mode = b.standardReleaseOptions(); 185 const optimize = b.standardOptimizeOption(.{});
186 186
187 // Tool to preprocess the sqlite header files. 187 // Tool to preprocess the sqlite header files.
188 // 188 //
189 // Due to limitations of translate-c the standard header files can't be used for building loadable extensions 189 // Due to limitations of translate-c the standard header files can't be used for building loadable extensions
190 // so we have this tool which creates usable header files. 190 // so we have this tool which creates usable header files.
191 191
192 const preprocess_files_tool = b.addExecutable("preprocess-files", "tools/preprocess_files.zig"); 192 const preprocess_files_tool = b.addExecutable(.{
193 preprocess_files_tool.setBuildMode(mode); 193 .name = "preprocess-files",
194 preprocess_files_tool.setTarget(getTarget(target, true)); 194 .root_source_file = .{ .path = "tools/preprocess_files.zig" },
195 .target = getTarget(target, true),
196 .optimize = optimize,
197 });
195 198
196 // Add a top-level step to run the preprocess-files tool 199 // Add a top-level step to run the preprocess-files tool
197 const preprocess_files_run = b.step("preprocess-files", "Run the preprocess-files tool"); 200 const preprocess_files_run = b.step("preprocess-files", "Run the preprocess-files tool");
@@ -220,32 +223,38 @@ pub fn build(b: *std.build.Builder) !void {
220 const bundled = use_bundled orelse test_target.bundled; 223 const bundled = use_bundled orelse test_target.bundled;
221 const cross_target = getTarget(test_target.target, bundled); 224 const cross_target = getTarget(test_target.target, bundled);
222 225
223 const tests = b.addTest("sqlite.zig"); 226 const tests = b.addTest(.{
227 .target = cross_target,
228 .root_source_file = .{ .path = "sqlite.zig" },
229 });
224 230
225 if (bundled) { 231 if (bundled) {
226 const lib = b.addStaticLibrary("sqlite", null); 232 const lib = b.addStaticLibrary(.{
233 .name = "sqlite",
234 .target = cross_target,
235 .optimize = optimize,
236 });
227 lib.addCSourceFile("c/sqlite3.c", &[_][]const u8{"-std=c99"}); 237 lib.addCSourceFile("c/sqlite3.c", &[_][]const u8{"-std=c99"});
228 lib.linkLibC(); 238 lib.linkLibC();
229 lib.setTarget(cross_target);
230 lib.setBuildMode(mode);
231 sqlite3 = lib; 239 sqlite3 = lib;
232 } 240 }
233 241
234 const lib = b.addStaticLibrary("zig-sqlite", "sqlite.zig"); 242 const lib = b.addStaticLibrary(.{
243 .name = "zig-sqlite",
244 .root_source_file = .{ .path = "sqlite.zig" },
245 .target = cross_target,
246 .optimize = optimize,
247 });
235 if (bundled) lib.addIncludePath("c"); 248 if (bundled) lib.addIncludePath("c");
236 linkSqlite(lib); 249 linkSqlite(lib);
237 lib.setTarget(cross_target);
238 lib.setBuildMode(mode);
239 250
240 const single_threaded_txt = if (test_target.single_threaded) "single" else "multi"; 251 const single_threaded_txt = if (test_target.single_threaded) "single" else "multi";
241 tests.setNamePrefix(b.fmt("{s}-{s}-{s} ", .{ 252 tests.setNamePrefix(b.fmt("{s}-{s}-{s} ", .{
242 try cross_target.zigTriple(b.allocator), 253 try cross_target.zigTriple(b.allocator),
243 @tagName(mode), 254 @tagName(optimize),
244 single_threaded_txt, 255 single_threaded_txt,
245 })); 256 }));
246 tests.single_threaded = test_target.single_threaded; 257 tests.single_threaded = test_target.single_threaded;
247 tests.setBuildMode(mode);
248 tests.setTarget(cross_target);
249 if (bundled) tests.addIncludePath("c"); 258 if (bundled) tests.addIncludePath("c");
250 linkSqlite(tests); 259 linkSqlite(tests);
251 260
@@ -260,26 +269,33 @@ pub fn build(b: *std.build.Builder) !void {
260 269
261 // Fuzzing 270 // Fuzzing
262 271
263 const lib = b.addStaticLibrary("sqlite", null); 272 const lib = b.addStaticLibrary(.{
273 .name = "sqlite",
274 .target = getTarget(target, true),
275 .optimize = optimize,
276 });
264 lib.addCSourceFile("c/sqlite3.c", &[_][]const u8{"-std=c99"}); 277 lib.addCSourceFile("c/sqlite3.c", &[_][]const u8{"-std=c99"});
265 lib.addIncludePath("c"); 278 lib.addIncludePath("c");
266 lib.linkLibC(); 279 lib.linkLibC();
267 lib.setBuildMode(mode);
268 lib.setTarget(getTarget(target, true));
269 280
270 // The library 281 // The library
271 const fuzz_lib = b.addStaticLibrary("fuzz-lib", "fuzz/main.zig"); 282 const fuzz_lib = b.addStaticLibrary(.{
283 .name = "fuzz-lib",
284 .root_source_file = .{ .path = "fuzz/main.zig" },
285 .target = getTarget(target, true),
286 .optimize = optimize,
287 });
272 fuzz_lib.addIncludePath("c"); 288 fuzz_lib.addIncludePath("c");
273 fuzz_lib.setBuildMode(mode);
274 fuzz_lib.setTarget(getTarget(target, true));
275 fuzz_lib.linkLibrary(lib); 289 fuzz_lib.linkLibrary(lib);
276 fuzz_lib.want_lto = true; 290 fuzz_lib.want_lto = true;
277 fuzz_lib.bundle_compiler_rt = true; 291 fuzz_lib.bundle_compiler_rt = true;
278 fuzz_lib.addPackagePath("sqlite", "sqlite.zig"); 292 fuzz_lib.addAnonymousModule("sqlite", .{
293 .source_file = .{ .path = "sqlite.zig" },
294 });
279 295
280 // Setup the output name 296 // Setup the output name
281 const fuzz_executable_name = "fuzz"; 297 const fuzz_executable_name = "fuzz";
282 const fuzz_exe_path = try std.fs.path.join(b.allocator, &.{ b.cache_root, fuzz_executable_name }); 298 const fuzz_exe_path = try b.cache_root.join(b.allocator, &.{fuzz_executable_name});
283 299
284 // We want `afl-clang-lto -o path/to/output path/to/library` 300 // We want `afl-clang-lto -o path/to/output path/to/library`
285 const fuzz_compile = b.addSystemCommand(&.{ "afl-clang-lto", "-o", fuzz_exe_path }); 301 const fuzz_compile = b.addSystemCommand(&.{ "afl-clang-lto", "-o", fuzz_exe_path });
@@ -296,12 +312,17 @@ pub fn build(b: *std.build.Builder) !void {
296 fuzz_compile_run.dependOn(&fuzz_install.step); 312 fuzz_compile_run.dependOn(&fuzz_install.step);
297 313
298 // Compile a companion exe for debugging crashes 314 // Compile a companion exe for debugging crashes
299 const fuzz_debug_exe = b.addExecutable("fuzz-debug", "fuzz/main.zig"); 315 const fuzz_debug_exe = b.addExecutable(.{
316 .name = "fuzz-debug",
317 .root_source_file = .{ .path = "fuzz/main.zig" },
318 .target = getTarget(target, true),
319 .optimize = optimize,
320 });
300 fuzz_debug_exe.addIncludePath("c"); 321 fuzz_debug_exe.addIncludePath("c");
301 fuzz_debug_exe.setBuildMode(mode);
302 fuzz_debug_exe.setTarget(getTarget(target, true));
303 fuzz_debug_exe.linkLibrary(lib); 322 fuzz_debug_exe.linkLibrary(lib);
304 fuzz_debug_exe.addPackagePath("sqlite", "sqlite.zig"); 323 fuzz_debug_exe.addAnonymousModule("sqlite", .{
324 .source_file = .{ .path = "sqlite.zig" },
325 });
305 326
306 // Only install fuzz-debug when the fuzz step is run 327 // Only install fuzz-debug when the fuzz step is run
307 const install_fuzz_debug_exe = b.addInstallArtifact(fuzz_debug_exe); 328 const install_fuzz_debug_exe = b.addInstallArtifact(fuzz_debug_exe);
@@ -315,21 +336,32 @@ pub fn build(b: *std.build.Builder) !void {
315 // 336 //
316 // This builds an example shared library with the extension and a binary that tests it. 337 // This builds an example shared library with the extension and a binary that tests it.
317 338
318 const zigcrypto_loadable_ext = b.addSharedLibrary("zigcrypto", "examples/zigcrypto.zig", .unversioned); 339 const zigcrypto_loadable_ext = b.addSharedLibrary(.{
340 .name = "zigcrypto",
341 .root_source_file = .{ .path = "examples/zigcrypto.zig" },
342 .version = null,
343 .target = getTarget(target, true),
344 .optimize = optimize,
345 });
319 zigcrypto_loadable_ext.force_pic = true; 346 zigcrypto_loadable_ext.force_pic = true;
320 zigcrypto_loadable_ext.addIncludePath("c"); 347 zigcrypto_loadable_ext.addIncludePath("c");
321 zigcrypto_loadable_ext.setBuildMode(mode); 348 zigcrypto_loadable_ext.addAnonymousModule("sqlite", .{
322 zigcrypto_loadable_ext.setTarget(getTarget(target, true)); 349 .source_file = .{ .path = "sqlite.zig" },
323 zigcrypto_loadable_ext.addPackagePath("sqlite", "sqlite.zig"); 350 });
324 zigcrypto_loadable_ext.linkLibrary(lib); 351 zigcrypto_loadable_ext.linkLibrary(lib);
325 352
326 const install_zigcrypto_loadable_ext = b.addInstallArtifact(zigcrypto_loadable_ext); 353 const install_zigcrypto_loadable_ext = b.addInstallArtifact(zigcrypto_loadable_ext);
327 354
328 const zigcrypto_test = b.addExecutable("zigcrypto-test", "examples/zigcrypto_test.zig"); 355 const zigcrypto_test = b.addExecutable(.{
356 .name = "zigcrypto-test",
357 .root_source_file = .{ .path = "examples/zigcrypto_test.zig" },
358 .target = getTarget(target, true),
359 .optimize = optimize,
360 });
329 zigcrypto_test.addIncludePath("c"); 361 zigcrypto_test.addIncludePath("c");
330 zigcrypto_test.setBuildMode(mode); 362 zigcrypto_test.addAnonymousModule("sqlite", .{
331 zigcrypto_test.setTarget(getTarget(target, true)); 363 .source_file = .{ .path = "sqlite.zig" },
332 zigcrypto_test.addPackagePath("sqlite", "sqlite.zig"); 364 });
333 zigcrypto_test.linkLibrary(lib); 365 zigcrypto_test.linkLibrary(lib);
334 366
335 const install_zigcrypto_test = b.addInstallArtifact(zigcrypto_test); 367 const install_zigcrypto_test = b.addInstallArtifact(zigcrypto_test);