I’m trying to write a Nix expression to build a program with optimizations for different x86_64 CPUs. A complicating thing is that one of CPUs is Zen4 which isn’t supported as -march
target in GCC, so it needs a custom flag set to build with AVX512. Also I’d like to keep it pure as much as possible (i.e. no impureUseNativeOptimizations
). I’ve come up with the following:
- Detect the local microarch via
system-features
innix.conf
; - Wrap
stdenv
for the program and its performance-critical dependencies usingwrapCFlags
with the appropriate flag list.
This way it bypasses the need to needlessly recompile stdenv.cc.cc
and allows to add custom logic for (yet) unsupported microarches. Also it seems to me that one shouldn’t use cross-compilation infra in such case. However, I’ve stumbled at the step 1, as I couldn’t figure out how functions like stdenv.hostPlatform.avx2Support
parse enabled feature info from nix.conf
.
How could this be achieved? Or should I always look at cross-compiling when dealing with such problem?