Skip to content

Commit

Permalink
update build.zig for 0.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rupurt committed Feb 8, 2024
1 parent cac212f commit 702d172
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
38 changes: 16 additions & 22 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Build = std.Build;

const TestItem = struct {
name: []const u8,
source_file: std.build.FileSource,
source_file: std.Build.LazyPath,
};

const test_files = [_]TestItem{
Expand Down Expand Up @@ -34,18 +34,30 @@ pub fn build(b: *Build) void {
b.installArtifact(lib);

_ = b.addModule("zig-odbc", .{
.source_file = .{ .path = "src/lib.zig" },
.root_source_file = .{ .path = "src/lib.zig" },
});

const test_cmd = b.step("test", "Run library tests");

const tests = testStep(b, optimize, target);
var tests: [test_files.len]*std.Build.Step.Compile = undefined;
inline for (test_files, 0..) |item, index| {
const current_tests = b.addTest(.{
.name = item.name,
.root_source_file = item.source_file,
.optimize = optimize,
.target = target,
});

setupOdbcDependencies(current_tests);

tests[index] = current_tests;
}
for (tests) |t| {
test_cmd.dependOn(&t.step);
}
}

pub fn setupOdbcDependencies(step: *std.build.Step.Compile) void {
pub fn setupOdbcDependencies(step: *std.Build.Step.Compile) void {
step.linkLibC();

const odbc_library_name = if (builtin.os.tag == .windows) "odbc32" else "odbc";
Expand All @@ -56,21 +68,3 @@ pub fn setupOdbcDependencies(step: *std.build.Step.Compile) void {

step.linkSystemLibrary(odbc_library_name);
}

pub fn testStep(b: *Build, optimize: std.builtin.OptimizeMode, target: std.zig.CrossTarget) [test_files.len]*std.build.Step.Compile {
var tests: [test_files.len]*std.build.Step.Compile = undefined;
inline for (test_files, 0..) |item, index| {
const current_tests = b.addTest(.{
.name = item.name,
.root_source_file = item.source_file,
.optimize = optimize,
.target = target,
});

setupOdbcDependencies(current_tests);

tests[index] = current_tests;
}

return tests;
}
2 changes: 1 addition & 1 deletion src/types.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,7 @@ pub const StatementAttributeValue = union(StatementAttribute) {
.RowStatusPointer => |v| std.mem.sliceAsBytes(v)[0..],
};

var result_buffer = try allocator.alloc(u8, bytes.len);
const result_buffer = try allocator.alloc(u8, bytes.len);
std.mem.copy(u8, result_buffer, bytes);

return result_buffer;
Expand Down

0 comments on commit 702d172

Please sign in to comment.