Skip to content

Commit b840e12

Browse files
mayeutmattip
authored andcommitted
create an ABI3 wheel when possible
1 parent f132e61 commit b840e12

File tree

5 files changed

+42
-48
lines changed

5 files changed

+42
-48
lines changed

.github/workflows/posix.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,21 @@ jobs:
122122
run: |
123123
mkdir -p local/openblas
124124
tar -C local/openblas --strip-components=2 -xf libs/openblas*.tar.gz
125-
# do not package the static libs, they are ~55MB
126-
rm local/openblas/*.a
127-
python -m pip wheel -w dist -vv .
125+
cp local/openblas/lib/libopenblas64_.so local/openblas/libopenblas_python.so
126+
# do not package the static libs and symlinks, they are ~55MB
127+
rm -rf local/openblas/lib/*
128+
mv local/openblas/libopenblas_python.so local/openblas/lib/
129+
130+
cat <<EOF > run_in_docker.sh
131+
cd /openblas
132+
patchelf --set-soname libopenblas_python.so local/openblas/lib/libopenblas_python.so
133+
python3.7 -m pip wheel -w /tmp/wheelhouse -vv .
134+
auditwheel repair -w dist/ /tmp/wheelhouse/openblas-*.whl
135+
python3.10 -m pip install dist/openblas-*.whl
136+
python3.10 -m openblas
137+
EOF
138+
139+
docker run --rm -v $(pwd):/openblas quay.io/pypa/manylinux2014_x86_64 /bin/bash -xe /openblas/run_in_docker.sh
128140
129141
- uses: actions/upload-artifact@v3
130142
with:

local/openblas/__init__.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,3 @@
1717
__version__ = "0.0.0"
1818

1919
openblas_config = _init_openblas.get_config()
20-
21-
path_to_so = os.path.join(os.path.dirname(__file__), 'lib', 'libopenblas64_.so')
22-
23-
24-
def open_so():
25-
_init_openblas.open_so(path_to_so)
26-
27-

pyproject.toml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ build-backend = "setuptools.build_meta"
99
[project]
1010
name = "openblas"
1111
version = "0.3.20"
12+
requires-python = ">=3.7"
1213
description = "Provides OpenBLAS for python packaging"
1314
readme = "README.md"
1415
classifiers = [
@@ -36,14 +37,3 @@ install_requires = "importlib-metadata ~= 1.0 ; python_version < '3.8'"
3637

3738
[tool.setuptools.package-data]
3839
openblas = ["lib/*", "include/*", "lib/pkgconfig/*", "lib/cmake/openblas/*"]
39-
40-
41-
#[tool.setuptools.data_files]
42-
# Deprecated in setuptools, but may be revived as a new standard, see
43-
# https://discuss.python.org/t/pep-proposal-external-data-for-python-packages
44-
#"/local" = [
45-
# "local/include/*.h",
46-
# "local/lib/*",
47-
# "local/lib/pkgconfig/*",
48-
# "local/lib/cmake/OpenBLAS/*",
49-
#]

setup.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,41 @@
11
import os
2+
import sys
23
from setuptools import setup, Extension
4+
from wheel.bdist_wheel import bdist_wheel
5+
36

47
mydir = os.path.abspath(os.path.dirname(__file__))
58

9+
10+
class bdist_wheel_abi3(bdist_wheel):
11+
def get_tag(self):
12+
python, abi, plat = bdist_wheel.get_tag(self)
13+
return python, "abi3", plat
14+
15+
616
# TODO: determine if we are building 64- or 32- bit interfaces
717
use_64=True
818
if use_64:
9-
libraries = ["openblas64_",]
1019
macros = [("SUFFIX", "64_")]
1120
else:
12-
libraries = ["openblas",]
1321
macros = []
1422

23+
if sys.implementation.name == "cpython":
24+
cmdclass = {"bdist_wheel": bdist_wheel_abi3}
25+
py_limited_api = {"py_limited_api": True}
26+
macros.append(('Py_LIMITED_API', '0x03070000'))
27+
else:
28+
cmdclass = {}
29+
py_limited_api = {}
30+
1531
setup(
32+
cmdclass=cmdclass,
1633
ext_modules=[Extension(
17-
"openblas._init_openblas", ["src/_init_openblas.c"],
18-
libraries=libraries,
19-
library_dirs=[os.path.join(mydir, 'local', 'openblas', 'lib'),],
20-
extra_link_args=["-Wl,-rpath,$ORIGIN/lib"],
21-
define_macros=macros,
34+
"openblas._init_openblas", ["src/_init_openblas.c"],
35+
libraries=["openblas_python"],
36+
library_dirs=[os.path.join(mydir, 'local', 'openblas', 'lib'),],
37+
extra_link_args=["-Wl,-rpath,$ORIGIN/lib"],
38+
define_macros=macros,
39+
**py_limited_api
2240
)],
2341
)

src/_init_openblas.c

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#include "Python.h"
2-
#include <dlfcn.h>
3-
#include <stdio.h>
1+
#include <Python.h>
42

53
#ifdef SUFFIX
64
#define openblas_get_config openblas_get_config64_
@@ -14,25 +12,9 @@ get_config(PyObject *self, PyObject *args) {
1412
return PyUnicode_FromString(config);
1513
}
1614

17-
PyObject*
18-
open_so(PyObject *self, PyObject *args) {
19-
const char *utf8 = PyUnicode_AsUTF8(args);
20-
if (utf8 == NULL) {
21-
return NULL;
22-
}
23-
void *handle = dlopen(utf8, RTLD_GLOBAL | RTLD_NOW);
24-
if (handle == NULL) {
25-
PyErr_SetString(PyExc_ValueError, "Could not open SO");
26-
return NULL;
27-
}
28-
Py_RETURN_TRUE;
29-
}
30-
3115
static PyMethodDef InitMethods[] = {
3216
{"get_config", get_config, METH_NOARGS,
3317
"Return openblas_get_config(), see https://github.com/xianyi/OpenBLAS/wiki/OpenBLAS-Extensions"},
34-
{"open_so", open_so, METH_O,
35-
"Use dlopen to load the shared object, which must exist"},
3618
{NULL, NULL, 0, NULL} /* Sentinel */
3719
};
3820

0 commit comments

Comments
 (0)