Skip to content

Commit fdfd21f

Browse files
Transurgeonclaude
andcommitted
add BLAS linking for all platforms (Accelerate/OpenBLAS/vcpkg)
The updated SparseDiffEngine submodule introduces dense_matrix.c which requires CBLAS. Link Accelerate on macOS, OpenBLAS on Linux, and OpenBLAS via vcpkg on Windows. Install BLAS dev packages in CI via CIBW_BEFORE_BUILD for Linux and Windows. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3fec61a commit fdfd21f

2 files changed

Lines changed: 30 additions & 13 deletions

File tree

.github/workflows/build-and-publish.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ jobs:
6464
CIBW_SKIP: "*-win32 *-manylinux_i686 *-musllinux*"
6565
CIBW_ARCHS_MACOS: "x86_64 universal2"
6666
CIBW_ARCHS_LINUX: "auto aarch64"
67+
CIBW_BEFORE_BUILD_LINUX: "yum install -y openblas-devel || apt-get install -y libopenblas-dev"
68+
CIBW_BEFORE_BUILD_WINDOWS: "vcpkg install openblas:x64-windows"
69+
CIBW_ENVIRONMENT_WINDOWS: "VCPKG_INSTALLED_DIR=C:\\vcpkg\\installed\\x64-windows"
6770

6871
- name: Check wheels
6972
shell: bash

setup.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616

1717
import builtins
1818
import glob
19+
import os
1920
import platform
2021

2122
from setuptools import Extension, setup
2223
from setuptools.command.build_ext import build_ext
2324

24-
25-
def not_on_windows(s: str) -> str:
26-
return s if platform.system().lower() != "windows" else ""
25+
system = platform.system().lower()
2726

2827

2928
class build_ext_numpy(build_ext):
@@ -44,26 +43,41 @@ def finalize_options(self) -> None:
4443

4544
# Define _POSIX_C_SOURCE on Linux for clock_gettime and struct timespec
4645
defines = []
47-
if platform.system().lower() == "linux":
46+
if system == "linux":
4847
defines.append(("_POSIX_C_SOURCE", "200809L"))
4948

49+
# Platform-specific BLAS configuration
50+
if system == "darwin":
51+
blas_link_args = ["-framework", "Accelerate"]
52+
blas_include_dirs = []
53+
elif system == "linux":
54+
blas_link_args = ["-lopenblas"]
55+
blas_include_dirs = []
56+
else:
57+
# Windows: OpenBLAS via vcpkg
58+
vcpkg_root = os.environ.get(
59+
"VCPKG_INSTALLED_DIR",
60+
r"C:\vcpkg\installed\x64-windows",
61+
)
62+
blas_link_args = [os.path.join(vcpkg_root, "lib", "openblas.lib")]
63+
blas_include_dirs = [os.path.join(vcpkg_root, "include")]
64+
5065
sparsediffengine = Extension(
5166
"sparsediffpy._sparsediffengine",
5267
sources=diff_engine_sources,
5368
include_dirs=[
5469
"SparseDiffEngine/include/",
5570
"SparseDiffEngine/src/",
5671
"sparsediffpy/_bindings/",
57-
],
72+
] + blas_include_dirs,
5873
define_macros=defines,
59-
extra_compile_args=[
60-
"-O3",
61-
"-std=c99",
62-
"-Wall",
63-
not_on_windows("-Wextra"),
64-
'-DDIFF_ENGINE_VERSION="0.1.3"',
65-
],
66-
extra_link_args=["-lm"] if platform.system().lower() != "windows" else [],
74+
extra_compile_args=(
75+
["-O3", "-std=c99", "-Wall", "-Wextra",
76+
'-DDIFF_ENGINE_VERSION="0.1.3"']
77+
if system != "windows" else
78+
['/O2', '/DDIFF_ENGINE_VERSION="0.1.3"']
79+
),
80+
extra_link_args=(["-lm"] if system != "windows" else []) + blas_link_args,
6781
)
6882

6983
setup(

0 commit comments

Comments
 (0)