From c61f3fb2a36105159f4c6e4a1cdffba7c0611ed1 Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Sun, 5 Feb 2023 13:06:56 +0100 Subject: fix build.zig file --- build.zig | 98 ++++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 65 insertions(+), 33 deletions(-) (limited to 'build.zig') diff --git a/build.zig b/build.zig index a217191..fe9a77e 100644 --- a/build.zig +++ b/build.zig @@ -182,16 +182,19 @@ pub fn build(b: *std.build.Builder) !void { const use_bundled = b.option(bool, "use_bundled", "Use the bundled sqlite3 source instead of linking the system library (default false)"); const target = b.standardTargetOptions(.{}); - const mode = b.standardReleaseOptions(); + const optimize = b.standardOptimizeOption(.{}); // Tool to preprocess the sqlite header files. // // Due to limitations of translate-c the standard header files can't be used for building loadable extensions // so we have this tool which creates usable header files. - const preprocess_files_tool = b.addExecutable("preprocess-files", "tools/preprocess_files.zig"); - preprocess_files_tool.setBuildMode(mode); - preprocess_files_tool.setTarget(getTarget(target, true)); + const preprocess_files_tool = b.addExecutable(.{ + .name = "preprocess-files", + .root_source_file = .{ .path = "tools/preprocess_files.zig" }, + .target = getTarget(target, true), + .optimize = optimize, + }); // Add a top-level step to run the preprocess-files tool 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 { const bundled = use_bundled orelse test_target.bundled; const cross_target = getTarget(test_target.target, bundled); - const tests = b.addTest("sqlite.zig"); + const tests = b.addTest(.{ + .target = cross_target, + .root_source_file = .{ .path = "sqlite.zig" }, + }); if (bundled) { - const lib = b.addStaticLibrary("sqlite", null); + const lib = b.addStaticLibrary(.{ + .name = "sqlite", + .target = cross_target, + .optimize = optimize, + }); lib.addCSourceFile("c/sqlite3.c", &[_][]const u8{"-std=c99"}); lib.linkLibC(); - lib.setTarget(cross_target); - lib.setBuildMode(mode); sqlite3 = lib; } - const lib = b.addStaticLibrary("zig-sqlite", "sqlite.zig"); + const lib = b.addStaticLibrary(.{ + .name = "zig-sqlite", + .root_source_file = .{ .path = "sqlite.zig" }, + .target = cross_target, + .optimize = optimize, + }); if (bundled) lib.addIncludePath("c"); linkSqlite(lib); - lib.setTarget(cross_target); - lib.setBuildMode(mode); const single_threaded_txt = if (test_target.single_threaded) "single" else "multi"; tests.setNamePrefix(b.fmt("{s}-{s}-{s} ", .{ try cross_target.zigTriple(b.allocator), - @tagName(mode), + @tagName(optimize), single_threaded_txt, })); tests.single_threaded = test_target.single_threaded; - tests.setBuildMode(mode); - tests.setTarget(cross_target); if (bundled) tests.addIncludePath("c"); linkSqlite(tests); @@ -260,22 +269,29 @@ pub fn build(b: *std.build.Builder) !void { // Fuzzing - const lib = b.addStaticLibrary("sqlite", null); + const lib = b.addStaticLibrary(.{ + .name = "sqlite", + .target = getTarget(target, true), + .optimize = optimize, + }); lib.addCSourceFile("c/sqlite3.c", &[_][]const u8{"-std=c99"}); lib.addIncludePath("c"); lib.linkLibC(); - lib.setBuildMode(mode); - lib.setTarget(getTarget(target, true)); // The library - const fuzz_lib = b.addStaticLibrary("fuzz-lib", "fuzz/main.zig"); + const fuzz_lib = b.addStaticLibrary(.{ + .name = "fuzz-lib", + .root_source_file = .{ .path = "fuzz/main.zig" }, + .target = getTarget(target, true), + .optimize = optimize, + }); fuzz_lib.addIncludePath("c"); - fuzz_lib.setBuildMode(mode); - fuzz_lib.setTarget(getTarget(target, true)); fuzz_lib.linkLibrary(lib); fuzz_lib.want_lto = true; fuzz_lib.bundle_compiler_rt = true; - fuzz_lib.addPackagePath("sqlite", "sqlite.zig"); + fuzz_lib.addAnonymousModule("sqlite", .{ + .source_file = .{ .path = "sqlite.zig" }, + }); // Setup the output name const fuzz_executable_name = "fuzz"; @@ -296,12 +312,17 @@ pub fn build(b: *std.build.Builder) !void { fuzz_compile_run.dependOn(&fuzz_install.step); // Compile a companion exe for debugging crashes - const fuzz_debug_exe = b.addExecutable("fuzz-debug", "fuzz/main.zig"); + const fuzz_debug_exe = b.addExecutable(.{ + .name = "fuzz-debug", + .root_source_file = .{ .path = "fuzz/main.zig" }, + .target = getTarget(target, true), + .optimize = optimize, + }); fuzz_debug_exe.addIncludePath("c"); - fuzz_debug_exe.setBuildMode(mode); - fuzz_debug_exe.setTarget(getTarget(target, true)); fuzz_debug_exe.linkLibrary(lib); - fuzz_debug_exe.addPackagePath("sqlite", "sqlite.zig"); + fuzz_debug_exe.addAnonymousModule("sqlite", .{ + .source_file = .{ .path = "sqlite.zig" }, + }); // Only install fuzz-debug when the fuzz step is run const install_fuzz_debug_exe = b.addInstallArtifact(fuzz_debug_exe); @@ -315,21 +336,32 @@ pub fn build(b: *std.build.Builder) !void { // // This builds an example shared library with the extension and a binary that tests it. - const zigcrypto_loadable_ext = b.addSharedLibrary("zigcrypto", "examples/zigcrypto.zig", .unversioned); + const zigcrypto_loadable_ext = b.addSharedLibrary(.{ + .name = "zigcrypto", + .root_source_file = .{ .path = "examples/zigcrypto.zig" }, + .version = null, + .target = getTarget(target, true), + .optimize = optimize, + }); zigcrypto_loadable_ext.force_pic = true; zigcrypto_loadable_ext.addIncludePath("c"); - zigcrypto_loadable_ext.setBuildMode(mode); - zigcrypto_loadable_ext.setTarget(getTarget(target, true)); - zigcrypto_loadable_ext.addPackagePath("sqlite", "sqlite.zig"); + zigcrypto_loadable_ext.addAnonymousModule("sqlite", .{ + .source_file = .{ .path = "sqlite.zig" }, + }); zigcrypto_loadable_ext.linkLibrary(lib); const install_zigcrypto_loadable_ext = b.addInstallArtifact(zigcrypto_loadable_ext); - const zigcrypto_test = b.addExecutable("zigcrypto-test", "examples/zigcrypto_test.zig"); + const zigcrypto_test = b.addExecutable(.{ + .name = "zigcrypto-test", + .root_source_file = .{ .path = "examples/zigcrypto_test.zig" }, + .target = getTarget(target, true), + .optimize = optimize, + }); zigcrypto_test.addIncludePath("c"); - zigcrypto_test.setBuildMode(mode); - zigcrypto_test.setTarget(getTarget(target, true)); - zigcrypto_test.addPackagePath("sqlite", "sqlite.zig"); + zigcrypto_test.addAnonymousModule("sqlite", .{ + .source_file = .{ .path = "sqlite.zig" }, + }); zigcrypto_test.linkLibrary(lib); const install_zigcrypto_test = b.addInstallArtifact(zigcrypto_test); -- cgit v1.2.3 From d16e5ca7fc308510444105915dcdc602beb80838 Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Thu, 16 Feb 2023 08:41:45 +0100 Subject: fix build --- build.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'build.zig') diff --git a/build.zig b/build.zig index fe9a77e..592055b 100644 --- a/build.zig +++ b/build.zig @@ -295,7 +295,7 @@ pub fn build(b: *std.build.Builder) !void { // Setup the output name const fuzz_executable_name = "fuzz"; - const fuzz_exe_path = try std.fs.path.join(b.allocator, &.{ b.cache_root, fuzz_executable_name }); + const fuzz_exe_path = try b.cache_root.join(b.allocator, &.{fuzz_executable_name}); // We want `afl-clang-lto -o path/to/output path/to/library` const fuzz_compile = b.addSystemCommand(&.{ "afl-clang-lto", "-o", fuzz_exe_path }); -- cgit v1.2.3