Skip to content

Commit

Permalink
statically link on posix, add aarch4 wheel build
Browse files Browse the repository at this point in the history
  • Loading branch information
mattip committed Sep 13, 2023
1 parent c62d943 commit ec4bbf1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 47 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ install:
script:
# Build library and collect into libs subdirectory
- build_lib "$PLAT" "$INTERFACE64"
- source travis-ci/build_wheel.sh

after_success:
# Upload libraries to the shared staging area on anaconda.org
Expand Down
33 changes: 29 additions & 4 deletions local/scipy_openblas64/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
"""

import ctypes
import os
from pathlib import Path
Expand Down Expand Up @@ -26,26 +30,35 @@


def get_include_dir():
"""Return the include directory needed for compilation
"""
return os.path.join(_HERE, "include")


def get_lib_dir():
"""Return the lib directory needed for linking
"""
return os.path.join(_HERE, "lib")


def get_library():
"""Return the lib name needed for linking
"""
if sys.platform == "win32":
libs = [x for x in os.listdir(get_lib_dir()) if x.endswith(".lib")]
return os.path.splitext(libs[0])[0]
else:
return "openblas_python"

def get_pkg_config():
"""Return a multi-line string that, when saved to a file, can be used with
pkg-config for build systems like meson
"""
if sys.platform == "win32":
extralib = "-defaultlib:advapi32 -lgfortran -defaultlib:advapi32 -lgfortran"
else:
extralib = "-lm -lpthread -lgfortran -lm -lpthread -lgfortran"
return f"""\
return dedent(f"""\
libdir={get_lib_dir()}
includedir={get_include_dir()}
openblas_config= {openblas_config}
Expand All @@ -58,15 +71,27 @@ def get_pkg_config():
Libs: -L${libdir} -l{get_library()}
Libs.private: ${extralib}
Cflags: -I${includedir}
"""
""")


if sys.platform == "win32":
os.add_dll_directory(get_lib_dir())


def write__distributor_init(target):
"""Accepts a Pathlib or string of a directory.
Write a pre-import file that will import scipy_openblas64 before
continuing to import the library. This will load OpenBLAS into the
executable's namespace and make the functions available for use.
"""
fname = os.path.join(target, "_distributor_init.py")
with open(fname, "wt", encoding="utf8") as fid:
fid.write(dedent(f"""\
""")

def _get_openblas_config():
"""Use ctypes to pull out the config string from the OpenBLAS library.
It will be available as `openblas_config`
"""
lib_dir = get_lib_dir()
if sys.platform == "win32":
# Get libopenblas*.lib
Expand All @@ -78,6 +103,6 @@ def _get_openblas_config():
dll = ctypes.CDLL(os.path.join(lib_dir, libnames[0]))
openblas_config = dll.openblas_get_config64_
openblas_config.restype = ctypes.c_char_p
return openblas_config
return openblas_config()

openblas_config = _get_openblas_config()
41 changes: 0 additions & 41 deletions src/_init_openblas.c

This file was deleted.

6 changes: 5 additions & 1 deletion travis-ci/build_steps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ function do_build_lib {
git config --global --add safe.directory '*'
pushd OpenBLAS
patch_source
CFLAGS="$CFLAGS -fvisibility=protected" make BUFFERSIZE=20 DYNAMIC_ARCH=1 USE_OPENMP=0 NUM_THREADS=64 BINARY=$bitness $interface64_flags $target_flags > /dev/null
CFLAGS="$CFLAGS -fvisibility=protected" \
make BUFFERSIZE=20 DYNAMIC_ARCH=1 \
USE_OPENMP=0 NUM_THREADS=64 \
LDFLAGS="-static ${LDFLAGS}"
BINARY=$bitness $interface64_flags $target_flags > /dev/null
make PREFIX=$BUILD_PREFIX $interface64_flags install
popd
stop_spinner
Expand Down
2 changes: 1 addition & 1 deletion travis-ci/build_wheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ if [ $(uname) == "Darwin" ]; then
for f in dist/*.whl; do mv $f "${f/%any.whl/macosx_10_9_$PLAT.whl}"; done
delocate-wheel -v dist/*.whl
else
auditwheel repair -w dist dist/*.whl
auditwheel repair -w dist --lib-sdir /lib dist/*.whl
rm dist/scipy_openblas*-none-any.whl
fi

Expand Down

0 comments on commit ec4bbf1

Please sign in to comment.