#Issues with calling into RocksDB

1 messages · Page 1 of 1 (latest)

fresh cairn
#

Hello, I am starting a project using Zig to interact with RocksDB, which has been mostly great, but stuck on a couple of things. First, I am successfully calling Rocks from my executable, but when I run the test step I get errors that it is not linked. I tried adding the same directives in build.zig to the test executable:

    tests.linkLibC();
    tests.linkSystemLibraryName("rocksdb");
    tests.addIncludePath(.{ .path = "/usr/include" });

But the test step still says it can't find rocksdb/c.h and that libc is not linked. I am working around by building the test executable instead:

b.installArtifact(tests);

Which works, but only for tests I define in main.zig. Tests in other files do not get run, even though they are imported and used in main.zig.
The second issue is with C strings. Everything I read says that Zig "strings" are null-terminated and will work with C calls. This has been the case for me when using comptime strings. but I am trying to use a randomly-generated folder name for testing which I create using std.fmt.printAlloc, and RocksDB is giving an error saying the file path is too long. When Rocks prints the path, it appears to not be terminated and contain an entire memory page:

ERRR IO error: While mkdir if missing: /tmp/rockstest-hgkfemsmj7�����������...etc

Any pointers (pun) would be appreciated!

fervent musk
#

If you mean std.fmt.allocPrint then you need std.fmt.allocPrintZ

fresh cairn
#

Ah, so that's what those Z functions are for... thank you! Now seeing this: gpa] (err): Allocation size 26 bytes does not match free size 25 which makes sense due to the extra null byte. I tried returning a [0:*]const u8 instead of []const u8 but the free function won't accept that. How should I be freeing the result of allocPrintZ?

#

Never mind, looks like [:0]u8 is what I needed

fervent musk
fresh cairn
fervent musk
#

zig build ?

#

you want to run test during zig build ?

fresh cairn
#

No, I want to run zig test src/main.zig like a normal pure zig project, but that fails. I can work around by installing the test executable as part of zig build and then running it, but it doesn't run all of the tests. I posted comments on the gist with the commands I am running and full output

fervent musk
#

for the first one you need to link with libc

#

zig test src/main.zig -lc

#

also to run tests directly through zig build

#

zig build test

#

can i see src/main.zig ?

fresh cairn
#

This worked: zig test src/main.zig -lc -lrocksdb

fervent musk
#

Oh forgot about the library oops

fresh cairn
#

Thank you! It's working and running the tests in all of the files. Appreciate your time

fervent musk
#

Happy to help!