Skip to content

Commit 6be4a46

Browse files
committed
more tweaks to globally load the dll, run aarch64 wheel build inside docker
1 parent faa9a55 commit 6be4a46

File tree

4 files changed

+35
-22
lines changed

4 files changed

+35
-22
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ install:
8686
script:
8787
# Build library and collect into libs subdirectory
8888
- build_lib "$PLAT" "$INTERFACE64"
89-
- source travis-ci/build_wheel.sh
89+
- libc=${MB_ML_LIBC:-manylinux}
90+
- docker_image=quay.io/pypa/${libc}${MB_ML_VER}_${PLAT}
91+
- docker run --rm -e INTERFACE64="${INTERFACE64}" -v $(pwd):/openblas $docker_image /bin/bash -xe /openblas/travis-ci/build_wheel.sh
9092

9193
after_success:
9294
# Upload libraries to the shared staging area on anaconda.org

local/scipy_openblas64/__init__.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
_HERE = Path(__file__).resolve().parent
1313

14-
__all__ = ["get_include_dir", "get_lib_dir", "get_library", "get_pkg_config", "openblas_config"]
14+
__all__ = ["get_include_dir", "get_lib_dir", "get_library", "get_pkg_config",
15+
"get_openblas_config"]
1516

1617
# Use importlib.metadata to single-source the version
1718

@@ -61,16 +62,16 @@ def get_pkg_config():
6162
return dedent(f"""\
6263
libdir={get_lib_dir()}
6364
includedir={get_include_dir()}
64-
openblas_config= {openblas_config}
65-
version={openblas_config.split(" ")[1]}
65+
openblas_config= {get_openblas_config()}
66+
version={get_openblas_config().split(" ")[1]}
6667
extralib={extralib}
6768
Name: openblas
6869
Description: OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version
6970
Version: ${{version}}
7071
URL: https://github.com/xianyi/OpenBLAS
71-
Libs: -L${libdir} -l{get_library()}
72-
Libs.private: ${extralib}
73-
Cflags: -I${includedir}
72+
Libs: -L${{libdir}} -l{get_library()}
73+
Libs.private: ${{extralib}}
74+
Cflags: -I${{includedir}}
7475
""")
7576

7677

@@ -92,22 +93,26 @@ def write__distributor_init(target):
9293
import scipy_openblas64
9394
"""))
9495

95-
def _get_openblas_config():
96+
dll = None
97+
def get_openblas_config():
9698
"""Use ctypes to pull out the config string from the OpenBLAS library.
97-
It will be available as `openblas_config`
9899
"""
99-
lib_dir = get_lib_dir()
100-
if sys.platform == "win32":
101-
# Get libopenblas*.lib
102-
libnames = [x for x in os.listdir(lib_dir) if x.endswith(".dll")]
103-
else:
104-
# Get openblas*
105-
libnames = [x for x in os.listdir(lib_dir) if x.startswith("libopenblas")]
100+
# Keep the dll alive
101+
global dll
102+
if not dll:
103+
lib_dir = get_lib_dir()
104+
if sys.platform == "win32":
105+
# Get libopenblas*.lib
106+
libnames = [x for x in os.listdir(lib_dir) if x.endswith(".dll")]
107+
else:
108+
# Get openblas*
109+
libnames = [x for x in os.listdir(lib_dir) if x.startswith("libopenblas")]
106110

107-
dll = ctypes.CDLL(os.path.join(lib_dir, libnames[0]))
111+
dll = ctypes.CDLL(os.path.join(lib_dir, libnames[0]))
108112
openblas_config = dll.openblas_get_config64_
109113
openblas_config.restype = ctypes.c_char_p
110-
return openblas_config()
111-
112-
# This global will keep the shared object in memory
113-
openblas_config = _get_openblas_config()
114+
bytes = openblas_config()
115+
return bytes.decode("utf8")
116+
117+
# Import the DLL which will make the namespace available to NumPy/SciPy
118+
get_openblas_config()

local/scipy_openblas64/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import scipy_openblas64
22

33
if __name__ == "__main__":
4-
print(f"OpenBLAS using '{scipy_openblas64.openblas_config}'")
4+
print(f"OpenBLAS using '{scipy_openblas64.get_openblas_config()}'")

travis-ci/build_wheel.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ if [ "${INTERFACE64}" != "1" ]; then
4646
rm local/scipy_openblas32/*.bak
4747
fi
4848

49+
rm -rf dist/*
4950
python3.7 -m pip wheel -w dist -vv .
5051

5152
if [ $(uname) == "Darwin" ]; then
@@ -56,6 +57,11 @@ if [ $(uname) == "Darwin" ]; then
5657
else
5758
auditwheel repair -w dist --lib-sdir /lib dist/*.whl
5859
rm dist/scipy_openblas*-none-any.whl
60+
# Add an RPATH to libgfortran:
61+
# https://github.com/pypa/auditwheel/issues/451
62+
unzip dist/*.whl "*libgfortran*"
63+
patchelf --force-rpath --set-rpath '$ORIGIN' */lib/libgfortran*
64+
zip dist/*.whl */lib/libgfortran*
5965
fi
6066

6167
if [ "${PLAT}" == "arm64" ]; then

0 commit comments

Comments
 (0)