Skip to content

Commit 00d1539

Browse files
committed
BLD: mangle the before_build script to set up link libraries [wheel build]
1 parent 061b1e0 commit 00d1539

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

numpy/meson.build

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ python_sources = [
243243
'version.pyi',
244244
]
245245

246-
if blas_name == 'scipy-openblas'
246+
if fs.exists('_distributor_init_local.py')
247247
python_sources += ['_distributor_init_local.py']
248248
endif
249249

pyproject.toml

+10-6
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ tracker = "https://github.com/numpy/numpy/issues"
142142
# `tools/ci/cirrus_wheels.yml`.
143143
build-frontend = "build"
144144
skip = "cp36-* cp37-* cp-38* pp37-* *-manylinux_i686 *_ppc64le *_s390x"
145-
build-verbosity = "3"
146145
before-build = "bash {project}/tools/wheels/cibw_before_build.sh {project}"
147146
# The build will use openblas64 everywhere, except on arm64 macOS >=14.0 (uses Accelerate)
148147
config-settings = "setup-args=-Duse-ilp64=true setup-args=-Dallow-noblas=false build-dir=build"
@@ -154,22 +153,27 @@ manylinux-x86_64-image = "manylinux2014"
154153
manylinux-aarch64-image = "manylinux2014"
155154
musllinux-x86_64-image = "musllinux_1_1"
156155
# RUNNER_OS is a GitHub Actions specific env var; define it here so it works on Cirrus CI too
157-
environment = {RUNNER_OS="Linux"}
156+
[tool.cibuildwheel.linux.environment]
157+
RUNNER_OS="Linux"
158+
PKG_CONFIG_PATH="/project/.openblas"
159+
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/project/.openblas/lib"
158160

159161
[tool.cibuildwheel.macos]
160162
# universal2 wheels are not supported (see gh-21233), use `delocate-fuse` if you need them
161163
archs = "x86_64 arm64"
162164
test-skip = "*_universal2:arm64"
163-
environment = {RUNNER_OS="macOS"}
165+
[tool.cibuildwheel.macos.environment]
166+
RUNNER_OS="macOS"
167+
PKG_CONFIG_PATH="/project/.openblas"
168+
DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/project/.openblas/lib"
164169

165170
[tool.cibuildwheel.windows]
166-
environment = {PKG_CONFIG_PATH="C:/opt/64/lib/pkgconfig"}
167-
config-settings = "setup-args=--vsenv setup-args=-Duse-ilp64=true setup-args=-Dblas=openblas setup-args=-Dlapack=openblas"
171+
environment = {PKG_CONFIG_PATH="./.openblas"}
172+
config-settings = "setup-args=--vsenv setup-args=-Duse-ilp64=true setup-args=-Dblas=openblas setup-args=-Dlapack=openblas -Dallow-noblas=false"
168173
repair-wheel-command = "bash ./tools/wheels/repair_windows.sh {wheel} {dest_dir}"
169174

170175
[[tool.cibuildwheel.overrides]]
171176
select = "*-win32"
172-
environment = {PKG_CONFIG_PATH="/opt/32/lib/pkgconfig"}
173177
config-settings = "setup-args=--vsenv setup-args=-Dallow-noblas=true"
174178
repair-wheel-command = ""
175179

tools/wheels/cibw_before_build.sh

+26-4
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,33 @@ fi
2525

2626
# Install Openblas
2727
if [[ $INSTALL_OPENBLAS ]] ; then
28-
export PKG_CONFIG_PATH=$PROJECT_DIR/.openblas
29-
mkdir -p $PKG_CONFIG_PATH
28+
# PKG_CONFIG_PATH=$PROJECT_DIR/.openblas
29+
mkdir -p $PKG_CONFIG_PATH/lib
3030
python -m pip install scipy-openblas64
31-
pkg_config=$(python -c "import scipy_openblas64; print(scipy_openblas64.get_pkg_config())")
32-
echo $pkg_config > $PKG_CONFIG_PATH/scipy-openblas.pc
31+
python -c "import scipy_openblas64; print(scipy_openblas64.get_pkg_config())" > $PKG_CONFIG_PATH/scipy-openblas.pc
32+
# Explicitly link the openblas so instead of using the "import
33+
# scipy-openblas64" preload trick
34+
sed -e "s/Libs:.*$/Libs: \${extralib}/" -i.bak $PKG_CONFIG_PATH/scipy-openblas.pc
35+
sed -e "s/-lm -lpthread -lgfortran -lquadmath//" -i.back $PKG_CONFIG_PATH/scipy-openblas.pc
36+
rm $PKG_CONFIG_PATH/*.bak
37+
# Also copy the shared objects to a path under $PKG_CONFIG_PATH, the build
38+
# will point $LD_LIBRARY_PATH there and then auditwheel/delocate-wheel will
39+
# pull these into the wheel
40+
cp -r $(python -c "import os, scipy_openblas64; print(os.path.dirname(scipy_openblas64.__file__))")/lib/* $PKG_CONFIG_PATH/lib
41+
pkg-config scipy-openblas --print-provides
42+
43+
if [[ $RUNNER_OS != "Windows" ]]; then
44+
# Link the internal SONAME to the shared object,
45+
# since the runtime loader will look for a file with this name
46+
# objdump -p will output something like
47+
# SONAME libscipy_openblas64_0.so
48+
# on linux and
49+
# name libscipy_openblas64_0.dylib (offset 24)
50+
# on macos, so trim off the first and last parts of the line
51+
soname=$(objdump -p $PKG_CONFIG_PATH/lib/libscipy* | grep -v "p-r" | grep libscipy | sed -e"s/^.*libsci/libsci/" | cut -f1 -d" ")
52+
echo "linking shared object to '$soname'"
53+
ln -s $PKG_CONFIG_PATH/lib/libscipy* $PKG_CONFIG_PATH/lib/$soname
54+
fi
3355
fi
3456
if [[ $RUNNER_OS == "Windows" ]]; then
3557
# delvewheel is the equivalent of delocate/auditwheel for windows.

0 commit comments

Comments
 (0)