1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-20 02:25:14 -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 1904d6ad21
commit 42743db558

View File

@ -5,6 +5,7 @@ const fs = std.fs;
const heap = std.heap; const heap = std.heap;
const mem = std.mem; const mem = std.mem;
const LibExeObjStep = std.build.LibExeObjStep; const LibExeObjStep = std.build.LibExeObjStep;
const Target = std.Target;
pub fn build(b: *std.build.Builder) !void { pub fn build(b: *std.build.Builder) !void {
const src_path = "src/libsodium"; 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_EMMINTRIN_H", "1");
lib.defineCMacro("HAVE_PMMINTRIN_H", "1"); lib.defineCMacro("HAVE_PMMINTRIN_H", "1");
lib.defineCMacro("HAVE_SMMINTRIN_H", "1"); lib.defineCMacro("HAVE_SMMINTRIN_H", "1");
lib.defineCMacro("HAVE_TMMINTRIN_H", "1");
lib.defineCMacro("HAVE_WMMINTRIN_H", "1"); lib.defineCMacro("HAVE_WMMINTRIN_H", "1");
}, },
.aarch64, .aarch64_be => { .aarch64, .aarch64_be => {
const cpu_features = target.getCpuFeatures(); const cpu_features = target.getCpuFeatures();
const has_neon = cpu_features.isEnabled(@enumToInt(std.Target.aarch64.Feature.neon)); const has_neon = cpu_features.isEnabled(@enumToInt(Target.aarch64.Feature.neon));
const has_crypto = cpu_features.isEnabled(@enumToInt(std.Target.aarch64.Feature.crypto)); const has_crypto = cpu_features.isEnabled(@enumToInt(Target.aarch64.Feature.crypto));
if (has_neon and has_crypto) { if (has_neon and has_crypto) {
lib.defineCMacro("HAVE_ARMCRYPTO", "1"); lib.defineCMacro("HAVE_ARMCRYPTO", "1");
} }
@ -155,6 +157,15 @@ pub fn build(b: *std.build.Builder) !void {
else => {}, 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 allocator = heap.page_allocator;
var walker = try src_dir.walk(allocator); var walker = try src_dir.walk(allocator);
while (try walker.next()) |entry| { while (try walker.next()) |entry| {