Skip to content

Instantly share code, notes, and snippets.

@shreyassanthu77
Created June 29, 2024 12:18
Show Gist options
  • Save shreyassanthu77/f824528a4a9a94db1148462436884261 to your computer and use it in GitHub Desktop.
Save shreyassanthu77/f824528a4a9a94db1148462436884261 to your computer and use it in GitHub Desktop.
zig libsql
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "ziglibsql",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
exe.addIncludePath(b.path("include/"));
exe.addLibraryPath(b.path("lib/"));
exe.linkSystemLibrary2("sql_experimental", .{
.preferred_link_mode = .static,
});
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const exe_unit_tests = b.addTest(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_exe_unit_tests.step);
}
const std = @import("std");
const libsql = @cImport({
@cInclude("libsql.h");
});
pub fn main() !void {
var conn: libsql.libsql_database_t = undefined;
var err_ptr: [*c]const u8 = undefined;
const ret = libsql.libsql_open_ext(":memory:", &conn, &err_ptr);
std.debug.print("{d}\n", .{ret});
}
test "simple test" {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment