Created
October 19, 2023 16:58
-
-
Save tmlbl/d6b78581ab9bec29edf86663780f89e3 to your computer and use it in GitHub Desktop.
Zig RocksDB test issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
pub fn build(b: *std.Build) void { | |
const target = b.standardTargetOptions(.{}); | |
const optimize = b.standardOptimizeOption(.{}); | |
const exe = b.addExecutable(.{ | |
.name = "csvd", | |
.root_source_file = .{ .path = "src/main.zig" }, | |
.target = target, | |
.optimize = optimize, | |
}); | |
exe.linkLibC(); | |
exe.linkSystemLibraryName("rocksdb"); | |
exe.addIncludePath(.{ .path = "/usr/include" }); | |
exe.addModule("zinatra", b.createModule(.{ | |
.source_file = .{ .path = "./zinatra/src/App.zig" }, | |
})); | |
b.installArtifact(exe); | |
const tests = b.addTest(.{ | |
.root_source_file = .{ .path = "src/main.zig" }, | |
.target = target, | |
.optimize = .Debug, | |
}); | |
tests.linkLibC(); | |
tests.linkSystemLibraryName("rocksdb"); | |
tests.addIncludePath(.{ .path = "/usr/include" }); | |
tests.addModule("zinatra", b.createModule(.{ | |
.source_file = .{ .path = "./zinatra/src/App.zig" }, | |
})); | |
b.installArtifact(tests); | |
const run_tests = b.addRunArtifact(tests); | |
const test_step = b.step("test", "Run the tests"); | |
test_step.dependOn(&run_tests.step); | |
} |
Author
tmlbl
commented
Oct 19, 2023
> zig build
> ./zig-out/bin/test
Test [1/1] test.data types...
opening /tmp/rockstest-eraz5vck0e...
All 1 tests passed.
For anyone finding this, I had to pass linker flags to zig test
. The needed command was:
zig test src/main.zig -lc -lrocksdb
The extra setup code for the test executable is not needed when running this way, so build.zig now looks like this:
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "csvd",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
exe.linkLibC();
exe.linkSystemLibraryName("rocksdb");
exe.addIncludePath(.{ .path = "/usr/include" });
exe.addModule("zinatra", b.createModule(.{
.source_file = .{ .path = "./zinatra/src/App.zig" },
}));
b.installArtifact(exe);
const tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = .Debug,
});
const run_tests = b.addRunArtifact(tests);
const test_step = b.step("test", "Run the tests");
test_step.dependOn(&run_tests.step);
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment