1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-24 20:45:17 -07:00

Update for Zig 0.11

This commit is contained in:
Frank Denis 2023-02-16 21:59:29 +01:00
parent 5755a5c009
commit bb2ee2359f

View File

@ -11,17 +11,21 @@ pub fn build(b: *std.build.Builder) !void {
const src_dir = try fs.Dir.openIterableDir(fs.cwd(), src_path, .{ .no_follow = true }); const src_dir = try fs.Dir.openIterableDir(fs.cwd(), src_path, .{ .no_follow = true });
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions(); const optimize = b.standardOptimizeOption(.{});
const enable_benchmarks = b.option(bool, "enable_benchmarks", "Whether tests should be benchmarks.") orelse false; const enable_benchmarks = b.option(bool, "enable_benchmarks", "Whether tests should be benchmarks.") orelse false;
const benchmarks_iterations = b.option(u32, "iterations", "Number of iterations for benchmarks.") orelse 200; const benchmarks_iterations = b.option(u32, "iterations", "Number of iterations for benchmarks.") orelse 200;
const shared = b.addSharedLibrary( const shared = b.addSharedLibrary(.{
if (target.isWindows()) "sodium_shared" else "sodium", .name = if (target.isWindows()) "sodium_shared" else "sodium",
null, .target = target,
.unversioned, .optimize = optimize,
); });
const static = b.addStaticLibrary("sodium", null); const static = b.addStaticLibrary(.{
.name = "sodium",
.target = target,
.optimize = optimize,
});
shared.strip = true; shared.strip = true;
static.strip = true; static.strip = true;
@ -36,10 +40,8 @@ pub fn build(b: *std.build.Builder) !void {
} }
for (libs) |lib| { for (libs) |lib| {
lib.setTarget(target);
lib.setBuildMode(mode);
lib.install(); lib.install();
if (mode != .Debug) { if (optimize != .Debug) {
lib.strip = true; lib.strip = true;
} }
lib.linkLibC(); lib.linkLibC();
@ -214,18 +216,18 @@ pub fn build(b: *std.build.Builder) !void {
continue; continue;
} }
const exe_name = name[0 .. name.len - 2]; const exe_name = name[0 .. name.len - 2];
var exe = b.addExecutable(exe_name, null); var exe = b.addExecutable(.{
exe.setTarget(target); .name = exe_name,
exe.setBuildMode(mode); .target = target,
.optimize = optimize,
});
exe.linkLibC(); exe.linkLibC();
exe.want_lto = false;
exe.strip = true; exe.strip = true;
exe.linkLibrary(static); exe.linkLibrary(static);
exe.addIncludePath("src/libsodium/include"); exe.addIncludePath("src/libsodium/include");
exe.addIncludePath("test/quirks"); exe.addIncludePath("test/quirks");
const full_path = try fmt.allocPrint(allocator, "{s}/{s}", .{ test_path, entry.path }); const full_path = try fmt.allocPrint(allocator, "{s}/{s}", .{ test_path, entry.path });
exe.addCSourceFiles(&.{full_path}, &.{}); exe.addCSourceFiles(&.{full_path}, &.{});
exe.strip = true;
if (enable_benchmarks) { if (enable_benchmarks) {
exe.defineCMacro("BENCHMARKS", "1"); exe.defineCMacro("BENCHMARKS", "1");