Open mitchellh opened 3 weeks ago
I realized my repro has some Nix paths hardcoded. Here is a build.zig
that also reproduces it, just put simdutf.cpp
inside the vendor
folder.
Command: zig build -Dtarget=x86_64-linux
const std = @import("std");
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const lib = b.addStaticLibrary(.{
.name = "simdutf",
.target = target,
.optimize = optimize,
});
lib.linkLibCpp();
lib.addIncludePath(.{ .path = "vendor" });
var flags = std.ArrayList([]const u8).init(b.allocator);
defer flags.deinit();
try flags.appendSlice(&.{});
lib.addCSourceFiles(.{
.flags = flags.items,
.files = &.{
"vendor/simdutf.cpp",
},
});
lib.installHeadersDirectory(
.{ .path = "vendor" },
"",
.{ .include_extensions = &.{".h"} },
);
b.installArtifact(lib);
}
Testing on a couple of X86 systems:
Xeon W-2133 (has AVX512) zig build
had no errors but zig build -Dtarget=x86_64-linux
had same errors.
AMD Ryzen 7 5800X (no AVX512) had errors with both commands.
This also affects Highway builds: https://github.com/google/highway which do similar conditional target compilation logic, but getting a clean repro of that for you is much more difficult so I think the simdutf approach is better. I'm just noting this since its not specific to one project.
Some digging around and experimenting with the -target-feature
that Zig passes to zig clang
and those passed by clang
to itself it looks like passing -Xclang -target-feature -Xclang -evex512
triggers the issue, since passing it to clang
makes it also fail to compile
The issue is that Zig is including the avx512vbmi2intrin.h
file even when the target cpu doesn't support avx512. simdutf does feature detect by detecting if that file is included, and if so, it tries to use avx512 intrinsics.
Zig Version
0.13.0
Steps to Reproduce and Observed Behavior
With
zig 0.13
and the latest simdutf (5.7.8) at the time of writing amalgamation of simdutf8, targetingx86_64
(macOS or Linux works).If it makes a difference, I am cross compiling from an aarch64 machine, but I don't believe that makes a difference since another tester I'm pretty sure reproduced this while building from an x86_64 machine.
Result:
Expected Behavior
Builds.
Additional info: https://github.com/llvm/llvm-project/issues/71325