]> gitweb.ps.run Git - ziglmdb/blobdiff - build.zig
refactor
[ziglmdb] / build.zig
index 65bca19553ab80e57ca345b5f093e1a221ef9a0f..6f0bd08df5b7ff71616a9e63b9b893ebc17fb9a2 100644 (file)
--- a/build.zig
+++ b/build.zig
@@ -19,12 +19,12 @@ pub fn build(b: *std.Build) void {
         .name = "lmdb",
         // In this case the main source file is merely a path, however, in more
         // complicated build scripts, this could be a generated file.
-        .root_source_file = .{ .path = "src/main.zig" },
+        .root_source_file = .{ .cwd_relative = "src/main.zig" },
         .target = target,
         .optimize = optimize,
     });
 
-    exe.addIncludePath(.{ .path = "./lmdb/libraries/liblmdb" });
+    exe.addIncludePath(.{ .cwd_relative = "./lmdb/libraries/liblmdb" });
 
     exe.addCSourceFiles(.{ .files = &.{
         "./lmdb/libraries/liblmdb/midl.c",
@@ -64,11 +64,22 @@ pub fn build(b: *std.Build) void {
     // Creates a step for unit testing. This only builds the test executable
     // but does not run it.
     const unit_tests = b.addTest(.{
-        .root_source_file = .{ .path = "src/main.zig" },
+        .root_source_file = .{ .cwd_relative = "src/main.zig" },
         .target = target,
         .optimize = optimize,
     });
 
+    unit_tests.addIncludePath(.{ .cwd_relative = "./lmdb/libraries/liblmdb" });
+
+    unit_tests.addCSourceFiles(.{ .files = &.{
+        "./lmdb/libraries/liblmdb/midl.c",
+        "./lmdb/libraries/liblmdb/mdb.c",
+    } });
+
+    unit_tests.linkLibC();
+
+    const test_bin = b.addInstallBinFile(unit_tests.getEmittedBin(), "./lmdb_test");
+
     const run_unit_tests = b.addRunArtifact(unit_tests);
 
     // Similar to creating the run step earlier, this exposes a `test` step to
@@ -76,4 +87,6 @@ pub fn build(b: *std.Build) void {
     // running the unit tests.
     const test_step = b.step("test", "Run unit tests");
     test_step.dependOn(&run_unit_tests.step);
+    test_step.dependOn(&unit_tests.step);
+    test_step.dependOn(&test_bin.step);
 }