From 702d172444d68c376f9603240d13ff4db66f5652 Mon Sep 17 00:00:00 2001 From: Alex Kwiatkowski Date: Thu, 8 Feb 2024 14:12:07 -0800 Subject: [PATCH] update build.zig for 0.12.0 --- build.zig | 38 ++++++++++++++++---------------------- src/types.zig | 2 +- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/build.zig b/build.zig index 987fa92..b5c6cc3 100644 --- a/build.zig +++ b/build.zig @@ -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{ @@ -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"; @@ -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; -} diff --git a/src/types.zig b/src/types.zig index f1e61da..dd3346b 100644 --- a/src/types.zig +++ b/src/types.zig @@ -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;