From cb4d121517e4e742aa230db340c1ac6d4faede30 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Fri, 20 Oct 2023 12:25:18 +0200 Subject: [PATCH] Try to support both zig 0.11 and zig-master --- build.zig | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/build.zig b/build.zig index 78b87fce..b538da74 100644 --- a/build.zig +++ b/build.zig @@ -247,16 +247,18 @@ pub fn build(b: *std.build.Builder) !void { const name = entry.basename; if (mem.endsWith(u8, name, ".c")) { const full_path = try fmt.allocPrint(allocator, "{s}/{s}", .{ src_path, entry.path }); - lib.addCSourceFiles(.{ - .files = &.{full_path}, - .flags = &.{ - "-fvisibility=hidden", - "-fno-strict-aliasing", - "-fno-strict-overflow", - "-fwrapv", - "-flax-vector-conversions", - }, - }); + const flags = &.{ + "-fvisibility=hidden", + "-fno-strict-aliasing", + "-fno-strict-overflow", + "-fwrapv", + "-flax-vector-conversions", + }; + if (@hasDecl(std.Build.Step.Compile, "AddCSourceFilesOptions")) { + lib.addCSourceFiles(.{ .files = &.{full_path}, .flags = flags }); + } else { + lib.addCSourceFiles(&.{full_path}, flags); + } } else if (mem.endsWith(u8, name, ".S")) { const full_path = try fmt.allocPrint(allocator, "{s}/{s}", .{ src_path, entry.path }); lib.addAssemblyFile(.{ .path = full_path }); @@ -294,8 +296,11 @@ pub fn build(b: *std.build.Builder) !void { exe.addIncludePath(.{ .path = "src/libsodium/include" }); exe.addIncludePath(.{ .path = "test/quirks" }); const full_path = try fmt.allocPrint(allocator, "{s}/{s}", .{ test_path, entry.path }); - exe.addCSourceFiles(.{ .files = &.{full_path} }); - + if (@hasDecl(std.Build.Step.Compile, "AddCSourceFilesOptions")) { + exe.addCSourceFiles(.{ .files = &.{full_path} }); + } else { + exe.addCSourceFiles(&.{full_path}, &.{}); + } if (enable_benchmarks) { exe.defineCMacro("BENCHMARKS", "1"); var buf: [16]u8 = undefined;