1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-19 10:05:05 -07:00

build.zig: require at least SSE4.1 when targeting x86_64

This commit is contained in:
Frank Denis 2022-11-27 22:42:04 +01:00
parent d0fa8b4178
commit e484cf4959

View File

@ -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| {