openblas: swap to CMake build to resolve duplicate symbols on aarch64

This commit is contained in:
Luna Nova
2026-03-12 08:57:51 -07:00
parent f0210e2e27
commit a3569ecabd
3 changed files with 73 additions and 74 deletions
@@ -0,0 +1,29 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1fa4d96..ac4dd0e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -641,7 +641,6 @@ endif()
# Install headers
set(CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR}/openblas${SUFFIX64})
-set(CMAKE_INSTALL_FULL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})
message(STATUS "Generating openblas_config.h in ${CMAKE_INSTALL_INCLUDEDIR}")
diff --git a/cmake/system.cmake b/cmake/system.cmake
index f16be31..d75d1ce 100644
--- a/cmake/system.cmake
+++ b/cmake/system.cmake
@@ -431,8 +431,10 @@ include("${PROJECT_SOURCE_DIR}/cmake/arch.cmake")
include("${PROJECT_SOURCE_DIR}/cmake/cc.cmake")
if (INTERFACE64)
- set(SUFFIX64 64)
- set(SUFFIX64_UNDERSCORE _64)
+ if (NOT NO_SUFFIX64)
+ set(SUFFIX64 64)
+ set(SUFFIX64_UNDERSCORE _64)
+ endif()
endif()
if (NOT NOFORTRAN)
@@ -3,8 +3,7 @@
stdenv,
fetchFromGitHub,
fetchpatch,
perl,
which,
cmake,
# Most packages depending on openblas expect integer width to match
# pointer width, but some expect to use 32-bit integers always
# (for compatibility with reference BLAS).
@@ -165,19 +164,6 @@ in
let
blas64 = if blas64_ != null then blas64_ else lib.hasPrefix "x86_64" stdenv.hostPlatform.system;
# Convert flag values to format OpenBLAS's build expects.
# `toString` is almost what we need other than bools,
# which we need to map {true -> 1, false -> 0}
# (`toString` produces empty string `""` for false instead of `0`)
mkMakeFlagValue =
val:
if !builtins.isBool val then
toString val
else if val then
"1"
else
"0";
mkMakeFlagsFromConfig = lib.mapAttrsToList (var: val: "${var}=${mkMakeFlagValue val}");
shlibExt = stdenv.hostPlatform.extensions.sharedLibrary;
@@ -198,7 +184,14 @@ stdenv.mkDerivation (finalAttrs: {
hash = "sha256-YBR81GOLnTsc0g1SZL+j31/OFucJrBRFqtOTV8lcy8U=";
};
${if singleThreaded then "patches" else null} = [
patches = [
# Fix broken cmake config file path when CMAKE_INSTALL_INCLUDEDIR is an absolute path
# Add NO_SUFFIX64 option to suppress _64 library name suffix
# INCLUDEDIR already fixed in upstream HEAD & significant refactor
# to config gen so not PRing changes
./cmake-include-fixes.patch
]
++ lib.optionals singleThreaded [
# fix single threaded build
(fetchpatch {
url = "https://github.com/OpenMathLib/OpenBLAS/commit/874243421298866d116e1e8bdbd7e0ed4e31e4f6.diff";
@@ -235,8 +228,7 @@ stdenv.mkDerivation (finalAttrs: {
];
nativeBuildInputs = [
perl
which
cmake
];
buildInputs = lib.optional (stdenv.cc.isClang && config.USE_OPENMP) openmp;
@@ -246,53 +238,44 @@ stdenv.mkDerivation (finalAttrs: {
buildPackages.stdenv.cc
];
enableParallelBuilding = true;
makeFlags = mkMakeFlagsFromConfig (
config
// {
FC = "${stdenv.cc.targetPrefix}gfortran";
CC = "${stdenv.cc.targetPrefix}${if stdenv.cc.isClang then "clang" else "cc"}";
PREFIX = placeholder "out";
OPENBLAS_INCLUDE_DIR = "${placeholder "dev"}/include";
NUM_THREADS = 64;
INTERFACE64 = blas64;
NO_STATIC = !enableStatic;
NO_SHARED = !enableShared;
CROSS = stdenv.hostPlatform != stdenv.buildPlatform;
HOSTCC = "cc";
# Makefile.system only checks defined status
# This seems to be a bug in the openblas Makefile:
# on x86_64 it expects NO_BINARY_MODE=
# but on aarch64 it expects NO_BINARY_MODE=0
NO_BINARY_MODE =
if stdenv.hostPlatform.isx86_64 then
toString (stdenv.hostPlatform != stdenv.buildPlatform)
else
stdenv.hostPlatform != stdenv.buildPlatform;
# This disables automatic build job count detection (which honours neither enableParallelBuilding nor NIX_BUILD_CORES)
# and uses the main make invocation's job count, falling back to 1 if no parallelism is used.
# https://github.com/OpenMathLib/OpenBLAS/blob/v0.3.20/getarch.c#L1781-L1792
MAKE_NB_JOBS = 0;
}
// (lib.optionalAttrs stdenv.cc.isClang {
LDFLAGS = "-L${lib.getLib buildPackages.gfortran.cc}/lib"; # contains `libgfortran.so`; building with clang needs this, gcc has it implicit
})
// (lib.optionalAttrs singleThreaded {
# As described on https://github.com/OpenMathLib/OpenBLAS/wiki/Faq/4bded95e8dc8aadc70ce65267d1093ca7bdefc4c#multi-threaded
USE_THREAD = false;
USE_LOCKING = true; # available with openblas >= 0.3.7
USE_OPENMP = false; # openblas will refuse building with both USE_OPENMP=1 and USE_THREAD=0
})
);
# The default "all" target unconditionally builds the "tests" target.
buildFlags = lib.optionals (!finalAttrs.doCheck) [ "shared" ];
cmakeFlags = [
(lib.cmakeFeature "TARGET" config.TARGET)
(lib.cmakeBool "DYNAMIC_ARCH" config.DYNAMIC_ARCH)
(lib.cmakeBool "USE_OPENMP" config.USE_OPENMP)
(lib.cmakeFeature "NUM_THREADS" "64")
(lib.cmakeBool "INTERFACE64" blas64)
# Don't suffix library/pkgconfig/cmake-config names with _64 for 64-bit
# FIXME: investigate if this is actually ok? maybe not! maintaining old behavior for now
(lib.cmakeBool "NO_SUFFIX64" true)
(lib.cmakeBool "BUILD_STATIC_LIBS" enableStatic)
(lib.cmakeBool "BUILD_SHARED_LIBS" enableShared)
(lib.cmakeFeature "CMAKE_Fortran_COMPILER" "${stdenv.cc.targetPrefix}gfortran")
# Disable the LAPACK test suite which is very slow and isn't part of the make test target
# Somewhat confusingly this overall-sounding flag turns off only the LAPACK tests
(lib.cmakeBool "BUILD_TESTING" false)
]
++ lib.optionals (config ? BINARY) [
(lib.cmakeFeature "BINARY" (toString config.BINARY))
]
++ lib.optionals (config ? MACOSX_DEPLOYMENT_TARGET) [
(lib.cmakeFeature "CMAKE_OSX_DEPLOYMENT_TARGET" config.MACOSX_DEPLOYMENT_TARGET)
]
++ lib.optionals (config ? NO_AVX512) [
(lib.cmakeBool "NO_AVX512" config.NO_AVX512)
]
++ lib.optionals singleThreaded [
# As described on https://github.com/OpenMathLib/OpenBLAS/wiki/Faq/4bded95e8dc8aadc70ce65267d1093ca7bdefc4c#multi-threaded
(lib.cmakeBool "USE_THREAD" false)
(lib.cmakeBool "USE_LOCKING" true) # available with openblas >= 0.3.7
(lib.cmakeBool "USE_OPENMP" false) # openblas will refuse building with both USE_OPENMP=ON and USE_THREAD=OFF
];
doCheck = true;
checkTarget = "tests";
postInstall = ''
# Provide headers in /include directly for compat with some consumers like flint
(cd $dev/include && ln -sf openblas/*.h .)
# Write pkgconfig aliases. Upstream report:
# https://github.com/OpenMathLib/OpenBLAS/issues/1740
for alias in blas cblas lapack; do
@@ -1,13 +0,0 @@
diff --git a/interface/gemm.c b/interface/gemm.c
index c5182c266..7056422e1 100644
--- a/interface/gemm.c
+++ b/interface/gemm.c
@@ -436,7 +436,7 @@ void CNAME(enum CBLAS_ORDER order, enum CBLAS_TRANSPOSE TransA, enum CBLAS_TRANS
#endif
#if defined(ARCH_ARM64) && (defined(USE_SGEMM_KERNEL_DIRECT)||defined(DYNAMIC_ARCH))
#if defined(DYNAMIC_ARCH)
- if (support_sme1())
+ if (false)
#endif
if (beta == 0 && alpha == 1.0 && order == CblasRowMajor && TransA == CblasNoTrans && TransB == CblasNoTrans) {
SGEMM_DIRECT(m, n, k, a, lda, b, ldb, c, ldc);