build: subtract avx512f when running under valgrind

Valgrind 3.26.0 cannot decode AVX-512 instructions. On AVX-512 capable
CPUs (e.g. Zen 4), Zig's standard library emits these instructions when
targeting native, causing immediate crashes. Subtract avx512f from the
CPU features when -Dvalgrind is set.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-12 00:20:12 +02:00
parent bf200f7ef9
commit b5880e3ce2

View File

@@ -43,13 +43,23 @@ const cflags = &[_][]const u8{
const compilers = &[_][]const u8{ "zig", "clang", "gcc", "tcc" };
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const cc = b.option([]const u8, "cc", "C compiler") orelse "zig";
const no_exec = b.option(bool, "no-exec", "Compile test binary without running it") orelse false;
const valgrind = b.option(bool, "valgrind", "Run tests under valgrind") orelse false;
const target = blk: {
var query = b.standardTargetOptionsQueryOnly(.{});
if (valgrind) {
const arch = query.cpu_arch orelse builtin.cpu.arch;
if (arch == .x86_64) {
query.cpu_features_sub.addFeature(@intFromEnum(std.Target.x86.Feature.avx512f));
}
}
break :blk b.resolveTargetQuery(query);
};
const test_step = b.step("test", "Run unit tests");
addTestStep(b, test_step, target, optimize, cc, no_exec, valgrind);