From 5391211b5d1f356211eec32e8a93c8760401996a 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 | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/build.zig b/build.zig index 3e8fc2b7..b538da74 100644 --- a/build.zig +++ b/build.zig @@ -247,13 +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(&.{full_path}, &.{ + 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 }); @@ -291,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(&.{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;