From 42743db558fb6e5bc849e2e9604893328fe20ef3 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 27 Nov 2022 22:42:04 +0100 Subject: [PATCH] build.zig: require at least SSE4.1 when targeting x86_64 --- build.zig | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/build.zig b/build.zig index 8f797398..639121ee 100644 --- a/build.zig +++ b/build.zig @@ -5,6 +5,7 @@ const fs = std.fs; const heap = std.heap; const mem = std.mem; const LibExeObjStep = std.build.LibExeObjStep; +const Target = std.Target; pub fn build(b: *std.build.Builder) !void { const src_path = "src/libsodium"; @@ -132,12 +133,13 @@ pub fn build(b: *std.build.Builder) !void { lib.defineCMacro("HAVE_EMMINTRIN_H", "1"); lib.defineCMacro("HAVE_PMMINTRIN_H", "1"); lib.defineCMacro("HAVE_SMMINTRIN_H", "1"); + lib.defineCMacro("HAVE_TMMINTRIN_H", "1"); lib.defineCMacro("HAVE_WMMINTRIN_H", "1"); }, .aarch64, .aarch64_be => { const cpu_features = target.getCpuFeatures(); - const has_neon = cpu_features.isEnabled(@enumToInt(std.Target.aarch64.Feature.neon)); - const has_crypto = cpu_features.isEnabled(@enumToInt(std.Target.aarch64.Feature.crypto)); + const has_neon = cpu_features.isEnabled(@enumToInt(Target.aarch64.Feature.neon)); + const has_crypto = cpu_features.isEnabled(@enumToInt(Target.aarch64.Feature.crypto)); if (has_neon and has_crypto) { lib.defineCMacro("HAVE_ARMCRYPTO", "1"); } @@ -155,6 +157,15 @@ pub fn build(b: *std.build.Builder) !void { else => {}, } + switch (target.getCpuArch()) { + .x86_64 => { + lib.target.cpu_features_add.addFeature(@enumToInt(Target.x86.Feature.sse4_1)); + lib.target.cpu_features_add.addFeature(@enumToInt(Target.x86.Feature.aes)); + lib.target.cpu_features_add.addFeature(@enumToInt(Target.x86.Feature.pclmul)); + }, + else => {}, + } + var allocator = heap.page_allocator; var walker = try src_dir.walk(allocator); while (try walker.next()) |entry| {