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:
12
build.zig
12
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user