From f93bdf7aec2fa12705c5bfc301bfe017f45ff5d6 Mon Sep 17 00:00:00 2001 From: eljamm Date: Wed, 19 Aug 2026 12:29:35 +0200 Subject: [PATCH] vacask: set OpenVAF target CPU VACASK's device models are compiled by OpenVAF, a Verilog-A compiler. By default, OpenVAF's `--target_cpu native` tells it to use every CPU instruction available on the machine doing the build (e.g. AVX-512, if the builder happens to have it). If the resulting binary is then run on a different, older CPU that doesn't support those instructions, it crashes with "illegal instruction" (SIGILL). To avoid this, we detect which instruction set the CPU we're building for actually supports and tell OpenVAF to target that instead, which keeps the compiled models runnable on other x86_64 machines as well. See: - https://codeberg.org/arpadbuermen/VACASK/src/commit/bf59752fbfdfed18dc7fe2e3e11a9c02f8de28a0/README.md#installation-from-pre-built-packages - https://github.com/NixOS/nixpkgs/blob/dc36b3c506df17272cdca29e85d0d0190b068981/lib/systems/architectures.nix Assisted-by: DeepSeek V4 Flash Free --- pkgs/by-name/va/vacask/package.nix | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/pkgs/by-name/va/vacask/package.nix b/pkgs/by-name/va/vacask/package.nix index df72bc92f73c..8091b2746311 100644 --- a/pkgs/by-name/va/vacask/package.nix +++ b/pkgs/by-name/va/vacask/package.nix @@ -16,6 +16,35 @@ boost188, suitesparse, tomlplusplus, + + # VACASK's device models are compiled by OpenVAF, a Verilog-A compiler. + # + # By default, OpenVAF's `--target_cpu native` tells it to use every CPU + # instruction available on the machine doing the build (e.g. AVX-512, if the + # builder happens to have it). If the resulting binary is then run on a + # different, older CPU that doesn't support those instructions, it crashes + # with "illegal instruction" (SIGILL). + # + # To avoid this, we detect which instruction set the CPU we're building for + # actually supports and tell OpenVAF to target that instead, which keeps the + # compiled models runnable on other x86_64 machines as well. + # + # See: + # - https://codeberg.org/arpadbuermen/VACASK/src/commit/bf59752fbfdfed18dc7fe2e3e11a9c02f8de28a0/README.md#installation-from-pre-built-packages + # - https://github.com/NixOS/nixpkgs/blob/dc36b3c506df17272cdca29e85d0d0190b068981/lib/systems/architectures.nix + openvafTargetCpu ? + with stdenv.hostPlatform; + if isx86_64 then + if avx512Support then + "x86-64-v4" + else if avx2Support then + "x86-64-v3" + else if sse4_2Support then + "x86-64-v2" + else + "x86-64" + else + "generic", }: let @@ -79,6 +108,7 @@ stdenv.mkDerivation (finalAttrs: { (lib.cmakeFeature "FLEX_INCLUDE_DIR" "${flex}/include") (lib.cmakeFeature "SuiteSparse_DIR" "${suitesparse-include}") (lib.cmakeFeature "TOMLPP_DIR" "${tomlplusplus}") + (lib.cmakeFeature "OPENVAF_OPTIONS" "--target_cpu ${openvafTargetCpu}") ]; doCheck = true;