diff --git a/build.zig b/build.zig index b5c6cc3..9b05074 100644 --- a/build.zig +++ b/build.zig @@ -24,22 +24,25 @@ pub fn build(b: *Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const lib = b.addStaticLibrary(.{ - .name = "odbc", + const lib = b.addSharedLibrary(.{ + .name = "zigodbc", + .root_source_file = .{ .path = "src/lib.zig" }, + .version = .{ .major = 0, .minor = 0, .patch = 0 }, .target = target, .optimize = optimize, }); setupOdbcDependencies(lib); + b.installArtifact(lib); _ = b.addModule("zig-odbc", .{ .root_source_file = .{ .path = "src/lib.zig" }, }); - const test_cmd = b.step("test", "Run library tests"); + const test_step = b.step("test", "Run library tests"); - var tests: [test_files.len]*std.Build.Step.Compile = undefined; + var tests: [test_files.len]*std.Build.Step.Run = undefined; inline for (test_files, 0..) |item, index| { const current_tests = b.addTest(.{ .name = item.name, @@ -50,10 +53,12 @@ pub fn build(b: *Build) void { setupOdbcDependencies(current_tests); - tests[index] = current_tests; + const run_current_unit_tests = b.addRunArtifact(current_tests); + + tests[index] = run_current_unit_tests; } for (tests) |t| { - test_cmd.dependOn(&t.step); + test_step.dependOn(&t.step); } } @@ -65,6 +70,5 @@ pub fn setupOdbcDependencies(step: *std.Build.Step.Compile) void { step.addIncludeDir("/usr/local/include"); step.addIncludeDir("/usr/local/lib"); } - step.linkSystemLibrary(odbc_library_name); } diff --git a/src/statement.zig b/src/statement.zig index bd17820..47693f6 100644 --- a/src/statement.zig +++ b/src/statement.zig @@ -315,7 +315,7 @@ pub const Statement = struct { var name_length: c_short = 0; _ = c.SQLGetCursorName(self.handle, null, 0, &name_length); - var name_buffer = try allocator.allocSentinel(u8, name_length, 0); + const name_buffer = try allocator.allocSentinel(u8, name_length, 0); errdefer allocator.free(name_buffer); const result = c.SQLGetCursorName(self.handle, name_buffer.ptr, @as(c_short, @intCast(name_buffer.len)), &name_length); @@ -346,7 +346,7 @@ pub const Statement = struct { if (result_type == .success_with_info) { // SuccessWithInfo might indicate that only part of the column was retrieved, and in that case we need to // continue fetching the rest of it. If we're getting long data, SQLGetData will return NoData - var error_buffer: [@sizeOf(odbc_error.SqlState) * 3]u8 = undefined; + const error_buffer: [@sizeOf(odbc_error.SqlState) * 3]u8 = undefined; var fba = std.heap.FixedBufferAllocator.init(error_buffer); const errors = try self.getErrors(&fba.allocator); for (errors) |err| if (err == .StringRightTrunc) { diff --git a/src/util.zig b/src/util.zig index cceecb4..53f9d28 100644 --- a/src/util.zig +++ b/src/util.zig @@ -88,12 +88,9 @@ test "bitmask" { test "enum error" { const Base = enum { A, B, C }; - const BaseError = EnumErrorSet(Base); - try std.testing.expectEqualStrings("A", @typeInfo(BaseError).ErrorSet.?[0].name); - try std.testing.expectEqualStrings("B", @typeInfo(BaseError).ErrorSet.?[1].name); - try std.testing.expectEqualStrings("C", @typeInfo(BaseError).ErrorSet.?[2].name); + try std.testing.expectEqual(BaseError, error{ A, B, C }); // Just making sure everything compiles, that BaseError is accepted in the error // spot of the return type.