From b5880e3ce2235c7aade1a160d958d17d3784e686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Thu, 12 Feb 2026 00:20:12 +0200 Subject: [PATCH] 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 --- build.zig | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/build.zig b/build.zig index f808353966..a557dd3c26 100644 --- a/build.zig +++ b/build.zig @@ -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);