vrischmann / zig-sqlite

zig-sqlite is a small wrapper around sqlite's C API, making it easier to use with Zig.
MIT License
367 stars 49 forks source link

Build failure using example usage #110

Closed jhuntwork closed 2 years ago

jhuntwork commented 2 years ago

When following the instructions on the main README.md, I am getting the following compile time error:

./.zigmod/deps/v/git/github.com/vrischmann/zig-sqlite/branch-stage2/sqlite.zig:335:50: error: expected type '[*c]const u8', found '[:0]const u8'
                const result = c.sqlite3_open_v2(path, &db, flags, null);
                                                 ^~~~

My main.zig file is the following:

const sqlite = @import("sqlite");

pub fn main() !void {
    var db = try sqlite.Db.init(.{ .mode = sqlite.Db.Mode{ .File = "/tmp/test.db" } });
    const query =
        \\SELECT id, name, age, salary FROM employees WHERE age > ? AND age < ?
    ;

    var stmt = try db.prepare(query);
    defer stmt.deinit();
}

I've tried with both master and the stage2 branch, both using zigmod, and receive the same error. My zig version is 0.10.0-dev.3874+9ce841a0f.

Thanks in advance for any help/feedback.

vrischmann commented 2 years ago

Hi,

I'm unable to make zigmod work at the moment (building master fails, the latest release crashes at runtime) so I can't test this.

Can you check if the same error occurs when you use a submodule ? (It should have no effect but just to be sure).

vrischmann commented 2 years ago

Well I'm able to reproduce it myself using a simple git clone so it's definitely not related to zigmod. I'll investigate

vrischmann commented 2 years ago

I think I understand now, this happens when using stage2 without setting use_stage1 = true in the build steps in the build.zig file (to be fair the README doesn't mention this).

Can you post your build.zig file ?

jhuntwork commented 2 years ago

Ah, thanks, that did it. I added exe.use_stage1 = true; to my build.zig file and it compiles now. I've been trying to read up on the differences, but I'd be curious to know what specifically about this code base requires the stage1 compiler.

vrischmann commented 2 years ago

Great that it works.

There are compiler bugs with stage2 which crash the compiler when building an application using zig-sqlite so until they are fixed it's recommeded to stay on stage1. I definitely intend to make zig-sqlite compatible with stage2 when possible.

If you're curious you can simply run zig build test in the stage2 branch and as of zig 0.10.0-dev.3952+9e070b653 the compiler segfaults.