From a126d5b36ebf233167ddf22ac04fc815bf50ca6a Mon Sep 17 00:00:00 2001 From: qubitnano <146656568+qubitnano@users.noreply.github.com> Date: Mon, 7 Oct 2024 07:20:47 -0400 Subject: [PATCH] mongodb-7_0: fix avxSupport (#346979) mozjs uses avx2 instructions in mongodb 7 --- pkgs/servers/nosql/mongodb/7.0.nix | 7 +++++- pkgs/servers/nosql/mongodb/mozjs-noavx.patch | 25 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 pkgs/servers/nosql/mongodb/mozjs-noavx.patch diff --git a/pkgs/servers/nosql/mongodb/7.0.nix b/pkgs/servers/nosql/mongodb/7.0.nix index ccd5eade79b8..42a425f4288e 100644 --- a/pkgs/servers/nosql/mongodb/7.0.nix +++ b/pkgs/servers/nosql/mongodb/7.0.nix @@ -8,6 +8,7 @@ cctools, avxSupport ? stdenv.hostPlatform.avxSupport, nixosTests, + lib, }: let @@ -34,7 +35,11 @@ buildMongoDB { # Fix building with python 3.12 since the imp module was removed ./mongodb-python312.patch - ]; + + # mongodb-7_0's mozjs uses avx2 instructions + # https://github.com/GermanAizek/mongodb-without-avx/issues/16 + ] ++ lib.optionals (!avxSupport) [ ./mozjs-noavx.patch ]; + passthru.tests = { inherit (nixosTests) mongodb; }; diff --git a/pkgs/servers/nosql/mongodb/mozjs-noavx.patch b/pkgs/servers/nosql/mongodb/mozjs-noavx.patch new file mode 100644 index 000000000000..a8f85b465979 --- /dev/null +++ b/pkgs/servers/nosql/mongodb/mozjs-noavx.patch @@ -0,0 +1,25 @@ +--- a/src/third_party/mozjs/SConscript ++++ b/src/third_party/mozjs/SConscript +@@ -145,8 +145,7 @@ sources = [ + ] + + if env['TARGET_ARCH'] == 'x86_64' and not env.TargetOSIs('windows'): +- env.Append(CCFLAGS=['-mavx2']) +- sources.extend(["extract/mozglue/misc/SIMD_avx2.cpp", "extract/mozglue/misc/SSE.cpp"]) ++ sources.extend(["extract/mozglue/misc/SSE.cpp"]) + + if env.TargetOSIs('windows'): + sources.extend([ +diff --git a/src/third_party/mozjs/extract/mozglue/misc/SIMD.cpp b/src/third_party/mozjs/extract/mozglue/misc/SIMD.cpp +index 3893de57b32..4ea0a657fbb 100644 +--- a/src/third_party/mozjs/extract/mozglue/misc/SIMD.cpp ++++ b/src/third_party/mozjs/extract/mozglue/misc/SIMD.cpp +@@ -448,7 +448,7 @@ const char* SIMD::memchr8SSE2(const char* ptr, char value, size_t length) { + // assertion failure. Accordingly, we just don't allow that to happen. We + // are not particularly concerned about ensuring that newer 32 bit processors + // get access to the AVX2 functions exposed here. +-# if defined(MOZILLA_MAY_SUPPORT_AVX2) && defined(__x86_64__) ++# if 0 + + bool SupportsAVX2() { return supports_avx2(); } +