zig0

my attempts at zig bootstrapping in C
Log | Files | Refs | README | LICENSE

commit 981d95b4e2d39a7cd126f17b4d7f70846b1e15dd (tree)
parent 0b115912b93873fa83c23d3c053d80cd51f35ded
Author: Motiejus Jakštys <motiejus@jakstys.lt>
Date:   Thu, 12 Feb 2026 00:20:12 +0200

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>

Diffstat:
Mbuild.zig | 12+++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git 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);