diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index f308156c..00000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,87 +0,0 @@ -name: Win - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -env: - OPENBLAS_COMMIT: "c2f4bdb" - OPENBLAS_ROOT: "c:\\opt" - # Preserve working directory for calls into bash - CHERE_INVOKING: "yes" - BASH_PATH: "c:\\rtools40\\usr\\bin\\bash.exe" - -jobs: - build: - strategy: - matrix: - BUILD_BITS: [64, 32] - INTERFACE64: ['1', '0'] - os: [windows-latest] - exclude: - - BUILD_BITS: 32 - INTERFACE64: 1 - fail-fast: false - runs-on: ${{ matrix.os }} - - steps: - - uses: actions/checkout@v3 - - name: install-rtools - run: | - # rtools 42+ does not support 32 bits builds. - choco install -y rtools --noprogress --force --version=4.0.0.20220206 - - - name: Set env variables - run: | - echo "START_DIR=$PWD" >> $env:GITHUB_ENV - $BITS = ${{ matrix.BUILD_BITS }} - echo "BUILD_BITS=$BITS" >> $env:GITHUB_ENV - # For interpretation of MSYSTEM, see: - # https://sourceforge.net/p/msys2/discussion/general/thread/b7dfdac8/#3939 - if ($BITS -eq 32) { - echo "PLAT=i686" >> $env:GITHUB_ENV - echo "MSYSTEM=MINGW32" >> $env:GITHUB_ENV - echo "LDFLAGS=-static -static-libgcc" >> $env:GITHUB_ENV - } else { - echo "PLAT=x86_64" >> $env:GITHUB_ENV - echo "MSYSTEM=UCRT64" >> $env:GITHUB_ENV - echo "LDFLAGS=-lucrt -static -static-libgcc" >> $env:GITHUB_ENV - } - if ( ${{ matrix.INTERFACE64 }} -eq 1 ) { - echo "INTERFACE64=1" >> $env:GITHUB_ENV - } - - - name: Build - run: | - git submodule update --init --recursive - & $env:BASH_PATH -lc tools/build_openblas.sh - - - name: Test - run: | - & $env:BASH_PATH -lc tools/build_gfortran.sh - echo "Static test" - .\for_test\test.exe - echo "Dynamic test" - .\for_test\test_dyn.exe - - - name: Copy - run: | - cp for_test\test*.exe builds - - - uses: actions/upload-artifact@v3 - with: - path: builds/openblas*.zip - - - uses: conda-incubator/setup-miniconda@v2 - with: - activate-environment: upload - - - name: Upload - env: - ANACONDA_SCIENTIFIC_PYTHON_UPLOAD: ${{ secrets.ANACONDA_SCIENTIFIC_PYTHON_UPLOAD }} - run: | - # Pin urllib3<2 due to github.com/Anaconda-Platform/anaconda-client/issues/654 - conda install "urllib3<2" anaconda-client - & $env:BASH_PATH -lc tools/upload_to_anaconda_staging.sh diff --git a/.github/workflows/multibuild.yml b/.github/workflows/posix.yml similarity index 83% rename from .github/workflows/multibuild.yml rename to .github/workflows/posix.yml index 273d9ce0..16ce6f69 100644 --- a/.github/workflows/multibuild.yml +++ b/.github/workflows/posix.yml @@ -1,4 +1,4 @@ -name: multibuild +name: posix on: push: @@ -19,38 +19,29 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-11] - platform: [x64] PLAT: [i686, x86_64] INTERFACE64: ['0', '1'] - MB_ML_VER: ['', 2010, 2014] + MB_ML_VER: ['2014'] include: - os: macos-11 PLAT: arm64 INTERFACE64: '1' - platform: [x64] - os: macos-11 PLAT: arm64 INTERFACE64: '0' - platform: [x64] - os: ubuntu-latest PLAT: x86_64 INTERFACE64: '1' MB_ML_LIBC: musllinux MB_ML_VER: _1_1 - platform: [x64] - os: ubuntu-latest PLAT: x86_64 INTERFACE64: '0' MB_ML_LIBC: musllinux MB_ML_VER: _1_1 - platform: [x64] exclude: - - os: macos-11 - PLAT: i686 - - os: macos-11 - MB_ML_VER: 2010 - - os: macos-11 - MB_ML_VER: 2014 + - PLAT: i686 + os: macos-11 - PLAT: i686 INTERFACE64: '1' env: @@ -71,14 +62,13 @@ jobs: with: submodules: recursive fetch-depth: 0 - - name: Set up Python 3.8 - uses: actions/setup-python@v2 + - name: Set up Python + uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: 3.7 - name: Set extra env run: | if [ "macos-11" == "${{ matrix.os }}" ]; then - ls /Library/Developer/CommandLineTools/SDKs echo "TRAVIS_OS_NAME=osx" >> $GITHUB_ENV; echo "LDFLAGS=-L/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/lib" >> $GITHUB_ENV; echo "LIBRARY_PATH=-L/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/lib" >> $GITHUB_ENV; @@ -93,9 +83,9 @@ jobs: echo "DOCKER_TEST_IMAGE: ${DOCKER_TEST_IMAGE}" - name: Install VirtualEnv run: | - python -m pip install --upgrade pip + python3 -m pip install --upgrade pip pip install virtualenv - - name: Build and Install Wheels + - name: Build OpenBLAS run: | set -xeo pipefail if [[ "$PLAT" == "arm64" ]]; then @@ -118,11 +108,30 @@ jobs: build_lib "$PLAT" "$INTERFACE64" "0" fi + - name: Build and test wheel + run: | + if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then + source travis-ci/build_wheel.sh + else + libc=${MB_ML_LIBC:-manylinux} + docker_image=quay.io/pypa/${libc}${MB_ML_VER}_${PLAT} + docker run --rm -e INTERFACE64="${INTERFACE64}" \ + -e MB_ML_LIBC="${MB_ML_LIBC}" \ + -v $(pwd):/openblas $docker_image \ + /bin/bash -xe /openblas/travis-ci/build_wheel.sh + fi + - uses: actions/upload-artifact@v3 with: + name: openblas path: libs/openblas*.tar.gz - - name: Upload tarballs + - uses: actions/upload-artifact@v3 + with: + name: wheels + path: dist/scipy_openblas*.whl + + - name: Upload run: | set -ex TOKEN=${{ secrets.ANACONDA_SCIENTIFIC_PYTHON_UPLOAD }} diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 00000000..49e99a49 --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,158 @@ +name: Win + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +env: + OPENBLAS_COMMIT: "c2f4bdb" + OPENBLAS_ROOT: "c:\\opt" + # Preserve working directory for calls into bash + # Without this, invoking bash will cd to the home directory + CHERE_INVOKING: "yes" + BASH_PATH: "c:\\rtools40\\usr\\bin\\bash.exe" + +jobs: + build: + strategy: + matrix: + plat: ['x64', 'x86'] + INTERFACE64: ['1', '0'] + os: [windows-latest] + exclude: + - plat: x86 + INTERFACE64: '1' + fail-fast: false + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v3 + - name: install-rtools + run: | + # rtools 42+ does not support 32 bits builds. + choco install -y rtools --noprogress --force --version=4.0.0.20220206 + + - name: Set env variables + run: | + echo "START_DIR=$PWD" >> $env:GITHUB_ENV + # For interpretation of MSYSTEM, see: + # https://sourceforge.net/p/msys2/discussion/general/thread/b7dfdac8/#3939 + if ( "${{ matrix.plat }}" -eq "x86") { + echo "PLAT=i686" >> $env:GITHUB_ENV + echo "WHEEL_PLAT=win32" >> $env:GITHUB_ENV + echo "MSYSTEM=MINGW32" >> $env:GITHUB_ENV + echo "LDFLAGS=-static -static-libgcc" >> $env:GITHUB_ENV + echo "BUILD_BITS=32" >> $env:GITHUB_ENV + } else { + echo "PLAT=x86_64" >> $env:GITHUB_ENV + echo "WHEEL_PLAT=win_amd64" >> $env:GITHUB_ENV + echo "MSYSTEM=UCRT64" >> $env:GITHUB_ENV + echo "LDFLAGS=-lucrt -static -static-libgcc" >> $env:GITHUB_ENV + echo "BUILD_BITS=64" >> $env:GITHUB_ENV + } + if ( ${{ matrix.INTERFACE64 }} -eq "1" ) { + echo "INTERFACE64=1" >> $env:GITHUB_ENV + } + + - name: Build + run: | + git submodule update --init --recursive + & $env:BASH_PATH -lc tools/build_openblas.sh + + - name: Test + run: | + & $env:BASH_PATH -lc tools/build_gfortran.sh + echo "Static test" + .\for_test\test.exe + echo "Dynamic test" + .\for_test\test_dyn.exe + + - name: Copy + run: | + cp for_test\test*.exe builds + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.7 + architecture: ${{ matrix.plat }} + + + - name: Build wheel + shell: bash + run: | + set -xeo pipefail + python -m pip install wheel + # This will fail if there is more than one file in libs + unzip -d local/scipy_openblas64 builds/openblas*.zip + if [[ -d local/scipy_openblas64/64 ]]; then + mv local/scipy_openblas64/64/* local/scipy_openblas64 + else + mv local/scipy_openblas64/32/* local/scipy_openblas64 + fi + mv local/scipy_openblas64/bin/*.dll local/scipy_openblas64/lib + rm local/scipy_openblas64/lib/*.a + rm local/scipy_openblas64/lib/*.exp + rm local/scipy_openblas64/lib/*.def + if [[ -d local/scipy_openblas64/64 ]]; then + rm -rf local/scipy_openblas64/64 + else + rm -rf local/scipy_openblas64/32 + fi + if [[ "${INTERFACE64}" != "1" ]]; then + mv local/scipy_openblas64 local/scipy_openblas32 + # rewrite the name of the project to scipy_openblas32 + # this is a hack, but apparently there is no other way to change the name + # of a pyproject.toml project + sed -e "s/openblas64/openblas32/" -i pyproject.toml + sed -e "s/openblas_get_config64_/openblas_get_config/" -i local/scipy_openblas32/__init__.py + sed -e "s/openblas64/openblas32/" -i local/scipy_openblas32/__main__.py + fi + + python -m pip wheel -w dist -vv . + # move the mis-named scipy_openblas64-none-any.whl to a platform-specific name + for f in dist/*.whl; do mv $f "${f/%any.whl/$WHEEL_PLAT.whl}"; done + + - name: Set up different Python + uses: actions/setup-python@v4 + with: + python-version: 3.11 + architecture: ${{ matrix.plat }} + + - uses: actions/upload-artifact@v3 + with: + name: openblas + path: builds/openblas*.zip + + - uses: actions/upload-artifact@v3 + with: + name: wheels + path: dist/scipy_openblas*.whl + + - name: Test 64-bit interface wheel + if: matrix.INTERFACE64 == '1' + shell: bash + run: | + python -m pip install --no-index --find-links dist scipy_openblas64 + python -m scipy_openblas64 + + - name: Test 32-bit interface wheel + if: matrix.INTERFACE64 != '1' + shell: bash + run: | + python -m pip install --no-index --find-links dist scipy_openblas32 + python -m scipy_openblas32 + + - uses: conda-incubator/setup-miniconda@v2 + with: + activate-environment: upload + + - name: Upload + env: + ANACONDA_SCIENTIFIC_PYTHON_UPLOAD: ${{ secrets.ANACONDA_SCIENTIFIC_PYTHON_UPLOAD }} + run: | + # Pin urllib3<2 due to github.com/Anaconda-Platform/anaconda-client/issues/654 + conda install "urllib3<2" anaconda-client + & $env:BASH_PATH -lc tools/upload_to_anaconda_staging.sh diff --git a/.gitignore b/.gitignore index 2d8e2638..74bbc8c3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,16 @@ builds/ *.pyc *.swp for_test/ +test.exe +dist/ +build/ +libs/ +# These are artifacts when using editable builds +local/lib +local/include +local/scipy_openblas64.egg-info +local/scipy_openblas64/lib +local/scipy_openblas64/include +local/scipy_openblas64/*.so +local/scipy_openblas64/*.pyd +local/scipy_openblas64/*.dylib diff --git a/.travis.yml b/.travis.yml index bb04b5b1..c351ab50 100644 --- a/.travis.yml +++ b/.travis.yml @@ -86,6 +86,9 @@ install: script: # Build library and collect into libs subdirectory - build_lib "$PLAT" "$INTERFACE64" + - libc=${MB_ML_LIBC:-manylinux} + - docker_image=quay.io/pypa/${libc}${MB_ML_VER}_${PLAT} + - docker run --rm -e INTERFACE64="${INTERFACE64}" -v $(pwd):/openblas $docker_image /bin/bash -xe /openblas/travis-ci/build_wheel.sh after_success: # Upload libraries to the shared staging area on anaconda.org diff --git a/OpenBLAS b/OpenBLAS index 2183dbcf..9f815cf1 160000 --- a/OpenBLAS +++ b/OpenBLAS @@ -1 +1 @@ -Subproject commit 2183dbcfe245f20bd5a6c90f3df2c402b78453bb +Subproject commit 9f815cf1bf16b4e64d4aee681b33558fc090b62a diff --git a/README.md b/README.md index ba276ae6..bf67d285 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,34 @@ -# Building OpenBLAS +# OpenBLAS -This is a repository to trigger builds of OpenBLAS on Travis-CI (for aarch64, -ppc64, s390x) and github actions for all the others. +We build OpenBLAS on Travis-CI (for linux aarch64, ppc64, s390x) and github actions +for linux, windows, macOS x86_64 and macOS arm64. -The OpenBLAS libraries get uploaded to +Tarballs are at https://anaconda.org/scientific-python-nightly-wheels/openblas-libs/files -A project using these libraries, for Manylinux or macOS, will need the +A project using the tarball, for Manylinux or macOS, will need the ``gfortran-install`` submodule used here, from https://github.com/MacPython/gfortran-install +We also build and upload a pip-installable wheel. The wheel is self-contained, +it includes all needed gfortran support libraries. On windows, this is a single +DLL. On linux we use `auditwheel repair` to mangle the shared object names. + +The wheel supplies interfaces for building and using OpenBLAS in a python +project like SciPy or NumPy: + +## Buildtime + +- `get_include_dir()`, `get_lib_dir()` and `get_library()` for use in compiler + or project arguments +- `get_pkg_config()` will return a multi-line text that can be saved into a + file and used with pkg-config for build systems like meson. This works around + the problem of [relocatable pkg-config + files](https://docs.conan.io/en/1.43/integrations/build_system/pkg_config_pc_files.html) + since the windows build uses pkgconfiglite v0.28 which does not support + `--define-prefix`. + +## Runtime + +- importing will load openblas into the executable and provide the openblas + symbols. diff --git a/local/scipy_openblas64/__init__.py b/local/scipy_openblas64/__init__.py new file mode 100644 index 00000000..a870fc5a --- /dev/null +++ b/local/scipy_openblas64/__init__.py @@ -0,0 +1,118 @@ +""" + +""" + +import ctypes +import os +from pathlib import Path +import sys +from textwrap import dedent + + +_HERE = Path(__file__).resolve().parent + +__all__ = ["get_include_dir", "get_lib_dir", "get_library", "get_pkg_config", + "get_openblas_config"] + +# Use importlib.metadata to single-source the version + +try: + # importlib.metadata is present in Python 3.8 and later + import importlib.metadata as importlib_metadata +except ImportError: + # use the shim package importlib-metadata pre-3.8 + import importlib_metadata as importlib_metadata + +try: + # __package__ allows for the case where __name__ is "__main__" + __version__ = importlib_metadata.version(__package__ or __name__) +except importlib_metadata.PackageNotFoundError: + __version__ = "0.0.0" + + +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 dedent(f"""\ + libdir={get_lib_dir()} + includedir={get_include_dir()} + openblas_config= {get_openblas_config()} + version={get_openblas_config().split(" ")[1]} + extralib={extralib} + Name: openblas + Description: OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version + Version: ${{version}} + URL: https://github.com/xianyi/OpenBLAS + 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"""\ + ''' + Helper to preload OpenBLAS from scipy_openblas64 + ''' + import scipy_openblas64 + """)) + +dll = None +def get_openblas_config(): + """Use ctypes to pull out the config string from the OpenBLAS library. + """ + # Keep the dll alive + global dll + if not dll: + lib_dir = get_lib_dir() + if sys.platform == "win32": + # Get libopenblas*.lib + libnames = [x for x in os.listdir(lib_dir) if x.endswith(".dll")] + else: + # Get openblas* + libnames = [x for x in os.listdir(lib_dir) if x.startswith("libopenblas")] + + dll = ctypes.CDLL(os.path.join(lib_dir, libnames[0])) + openblas_config = dll.openblas_get_config64_ + openblas_config.restype = ctypes.c_char_p + bytes = openblas_config() + return bytes.decode("utf8") + +# Import the DLL which will make the namespace available to NumPy/SciPy +get_openblas_config() diff --git a/local/scipy_openblas64/__main__.py b/local/scipy_openblas64/__main__.py new file mode 100644 index 00000000..f35d32ef --- /dev/null +++ b/local/scipy_openblas64/__main__.py @@ -0,0 +1,4 @@ +import scipy_openblas64 + +if __name__ == "__main__": + print(f"OpenBLAS using '{scipy_openblas64.get_openblas_config()}'") diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..2fcfacdc --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,39 @@ +[build-system] +# Minimum requirements for the build system to execute. +requires = [ + "setuptools", + "wheel", +] +build-backend = "setuptools.build_meta" + +[project] +name = "scipy_openblas64" +version = "0.3.23.293" +requires-python = ">=3.7" +description = "Provides OpenBLAS for python packaging" +readme = "README.md" +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Programming Language :: C++", + "License :: OSI Approved :: BSD License", +] +# authors = [ +# ] +# maintainers = [ +# ] + +[project.urls] +homepage = "https://github.com/MacPython/openblas-libs" +upstream = "https://github.com/xianyi/OpenBLAS" + +[tool.setuptools.packages.find] +# scanning for namespace packages is true by default in pyproject.toml, so +# # you do NOT need to include the following line. +namespaces = true +where = ["local"] + +[options] +install_requires = "importlib-metadata ~= 1.0 ; python_version < '3.8'" + +[tool.setuptools.package-data] +scipy_openblas64 = ["lib/*", "include/*", "lib/pkgconfig/*", "lib/cmake/openblas/*"] diff --git a/setup.py b/setup.py new file mode 100644 index 00000000..60684932 --- /dev/null +++ b/setup.py @@ -0,0 +1,3 @@ +from setuptools import setup + +setup() diff --git a/tools/local_build.sh b/tools/local_build.sh new file mode 100644 index 00000000..efd5be89 --- /dev/null +++ b/tools/local_build.sh @@ -0,0 +1,59 @@ +# Replicate the workflow from posix.yml locally on posix +# This may bitrot, compare it to the original file before using + + +# Set extra env +if [ "uname -m" == "x86_64" ]; then + export TRAVIS_OS_NAME=ubuntu-latest + export PLAT=x86_64 + # export PLAT=i86 + DOCKER_TEST_IMAGE=multibuild/xenial_${PLAT} +else + export TRAVIS_OS_NAME=osx + export LDFLAGS="-L/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/lib" + export LIBRARY_PATH="-L/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/lib" + export PLAT=x86_64 + # export PLAT=arm64 + export SUFFIX=gf_c469a42 + +fi +export REPO_DIR=OpenBLAS +export OPENBLAS_COMMIT="c2f4bdb" + +# export MB_ML_LIBC=musllinux +# export MB_ML_VER=_1_1 +# export MB_ML_VER=2014 +export INTERFACE64=1 + +function install_virtualenv { + # Install VirtualEnv + python3 -m pip install --upgrade pip + pip install virtualenv +} + +function build_openblas { + # Build OpenBLAS + set -xeo pipefail + if [ "$PLAT" == "arm64" ]; then + sudo xcode-select -switch /Applications/Xcode_12.5.1.app + export SDKROOT=/Applications/Xcode_12.5.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk + clang --version + fi + source travis-ci/build_steps.sh + echo "------ BEFORE BUILD ---------" + before_build + if [[ "$NIGHTLY" = "true" ]]; then + echo "------ CLEAN CODE --------" + clean_code $REPO_DIR develop + echo "------ BUILD LIB --------" + build_lib "$PLAT" "$INTERFACE64" "1" + else + echo "------ CLEAN CODE --------" + clean_code $REPO_DIR $OPENBLAS_COMMIT + echo "------ BUILD LIB --------" + build_lib "$PLAT" "$INTERFACE64" "0" + fi +} + +# install_virtualenv +# build_openblas diff --git a/travis-ci/build_steps.sh b/travis-ci/build_steps.sh index 934975a3..9a2b9127 100644 --- a/travis-ci/build_steps.sh +++ b/travis-ci/build_steps.sh @@ -165,7 +165,10 @@ 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 \ + BINARY=$bitness $interface64_flags $target_flags > /dev/null make PREFIX=$BUILD_PREFIX $interface64_flags install popd stop_spinner diff --git a/travis-ci/build_wheel.sh b/travis-ci/build_wheel.sh new file mode 100644 index 00000000..c8151702 --- /dev/null +++ b/travis-ci/build_wheel.sh @@ -0,0 +1,88 @@ +# Needs: +# $INTERFACE64 ("1" or "0") +# $PLAT (x86_64, i686, arm64, aarch64, s390x, ppc64le) + + +set -xe + +ls libs/openblas* >/dev/null 2>&1 && true +if [ "$?" != "0" ]; then + # inside docker + cd /openblas +fi + +mkdir -p local/openblas +mkdir -p dist +python3.7 -m pip install wheel auditwheel + +# This will fail if there is more than one file in libs +tar -C local/scipy_openblas64 --strip-components=2 -xf libs/openblas*.tar.gz + +# do not package the static libs and symlinks, only take the shared object +find local/scipy_openblas64/lib -maxdepth 1 -type l -delete +rm local/scipy_openblas64/lib/*.a +# cleanup from a possible earlier run of the script +rm -f local/scipy_openblas64/lib/libopenblas_python.so +mv local/scipy_openblas64/lib/libopenblas* local/scipy_openblas64/lib/libopenblas_python.so + +if [ $(uname) != "Darwin" ]; then + patchelf --set-soname libopenblas_python.so local/scipy_openblas64/lib/libopenblas_python.so +elif [ "{PLAT}" == "arm64" ]; then + source multibuild/osx_utils.sh + macos_arm64_cross_build_setup +fi + +if [ "${INTERFACE64}" != "1" ]; then + # rewrite the name of the project to scipy_openblas32 + # this is a hack, but apparently there is no other way to change the name + # of a pyproject.toml project + # + # use the BSD variant of sed -i and remove the backup + sed -e "s/openblas64/openblas32/" -i.bak pyproject.toml + rm *.bak + mv local/scipy_openblas64 local/scipy_openblas32 + sed -e "s/openblas_get_config64_/openblas_get_config/" -i.bak local/scipy_openblas32/__init__.py + sed -e "s/openblas64/openblas32/" -i.bak local/scipy_openblas32/__main__.py + sed -e "s/openblas64/openblas32/" -i.bak local/scipy_openblas32/__init__.py + rm local/scipy_openblas32/*.bak +fi + +rm -rf dist/* +python3.7 -m pip wheel -w dist -vv . + +if [ $(uname) == "Darwin" ]; then + python3.7 -m pip install delocate + # move the mis-named scipy_openblas64-none-any.whl to a platform-specific name + if [ "{PLAT}" == "arm64" ]; then + for f in dist/*.whl; do mv $f "${f/%any.whl/macosx_11_0_$PLAT.whl}"; done + else + for f in dist/*.whl; do mv $f "${f/%any.whl/macosx_10_9_$PLAT.whl}"; done + fi + delocate-wheel -v dist/*.whl +else + auditwheel repair -w dist --lib-sdir /lib dist/*.whl + rm dist/scipy_openblas*-none-any.whl + # Add an RPATH to libgfortran: + # https://github.com/pypa/auditwheel/issues/451 + if [ "$MB_ML_LIBC" == "musllinux" ]; then + apk add zip + else + yum install -y zip + fi + unzip dist/*.whl "*libgfortran*" + patchelf --force-rpath --set-rpath '$ORIGIN' */lib/libgfortran* + zip dist/*.whl */lib/libgfortran* +fi + +if [ "${PLAT}" == "arm64" ]; then + # Cannot test + exit 0 +fi +# Test that the wheel works with a different python +if [ "${INTERFACE64}" != "1" ]; then + python3.11 -m pip install --no-index --find-links dist scipy_openblas32 + python3.11 -m scipy_openblas32 +else + python3.11 -m pip install --no-index --find-links dist scipy_openblas64 + python3.11 -m scipy_openblas64 +fi