From 5fb1a9fb3e086f5dcb8ee59e297d57037bc2c52d Mon Sep 17 00:00:00 2001 From: Cayman Date: Tue, 29 Sep 2026 14:58:08 -0400 Subject: [PATCH] fix: dispatch hashtree at runtime on every x86_64 target Select hashtree on x86_64 by target OS instead of compile-time CPU features, since `hashtree_hash` already picks its backend at runtime. - `isSupported()` returns true on x86_64 except macOS and Windows MSVC, the targets where `build.zig` does not assemble the x86 backends - baseline builds (for example published packages built with only `-Dtarget`) now use SHA-NI, AVX-512, AVX2, AVX or SSE instead of std SHA-256 - macOS keeps the std fallback whatever `-Dcpu` is, which fixes the undefined `_hashtree_sha256_*` link errors with `-Dcpu=haswell` --- src/root.zig | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/root.zig b/src/root.zig index 98936e3..9db162a 100644 --- a/src/root.zig +++ b/src/root.zig @@ -21,9 +21,11 @@ fn isSupported() bool { return true; } - if (builtin.cpu.arch == .x86_64 and (std.Target.x86.featureSetHasAll(builtin.cpu.features, .{ .avx512f, .avx512vl }) or - std.Target.x86.featureSetHasAll(builtin.cpu.features, .{ .avx2, .bmi2 }) or - std.Target.x86.featureSetHasAll(builtin.cpu.features, .{ .sha, .avx }))) + // hashtree_hash selects SHA-NI, AVX-512, AVX2, AVX, SSE or generic C at runtime, so this must not depend on the + // compile-time CPU. The x86 backends are assembled on the same targets as in build.zig. + if (builtin.cpu.arch == .x86_64 and + builtin.os.tag != .macos and + !(builtin.os.tag == .windows and builtin.abi == .msvc)) { return true; }