Skip to content

Commit dacf13f

Browse files
committed
feat: use limited API to build PyPI wheels
1 parent b888cdb commit dacf13f

File tree

6 files changed

+34
-47
lines changed

6 files changed

+34
-47
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[build-system]
22
# Minimum requirements for the build system to execute.
3-
requires = ["setuptools", "wheel"] # PEP 508 specifications.
3+
requires = ["setuptools"] # PEP 508 specifications.

scripts/manylinux/build_on_centos.sh

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -39,45 +39,15 @@ ${MAIN_PYTHON_BIN}/cmake \
3939
..
4040
make all install
4141

42-
PYTHON_VERSIONS=""
43-
if [[ -z ${BUILD_PYTHON} ]]; then
44-
# Collect all target Python versions.
45-
for PYTHON_BIN in /opt/python/*/bin; do
46-
# H/T: https://stackoverflow.com/a/229606/1068170
47-
if [[ "${PYTHON_BIN}" == *"39"* ]]; then
48-
PYTHON_VERSIONS="${PYTHON_VERSIONS} ${PYTHON_BIN}"
49-
continue
50-
elif [[ "${PYTHON_BIN}" == *"310"* ]]; then
51-
PYTHON_VERSIONS="${PYTHON_VERSIONS} ${PYTHON_BIN}"
52-
continue
53-
elif [[ "${PYTHON_BIN}" == *"311"* ]]; then
54-
PYTHON_VERSIONS="${PYTHON_VERSIONS} ${PYTHON_BIN}"
55-
continue
56-
elif [[ "${PYTHON_BIN}" == *"312"* ]]; then
57-
PYTHON_VERSIONS="${PYTHON_VERSIONS} ${PYTHON_BIN}"
58-
continue
59-
else
60-
echo "Ignoring unsupported version: ${PYTHON_BIN}"
61-
echo "====================================="
62-
fi
63-
done
64-
else
65-
STRIPPED_PYTHON=$(echo ${BUILD_PYTHON} | sed -e "s/\.//g" | sed -e "s/-dev$//")
66-
for PYTHON_BIN in /opt/python/*/bin; do
67-
if [[ "${PYTHON_BIN}" == *"${STRIPPED_PYTHON}"* ]]; then
68-
PYTHON_VERSIONS="${PYTHON_VERSIONS} ${PYTHON_BIN}"
69-
fi
70-
done
71-
fi
7242

73-
# Build the wheels.
43+
# Build the wheel.
44+
export CRC32C_PURE_PYTHON=0
45+
export CRC32C_LIMITED_API=1
7446
cd ${REPO_ROOT}
75-
for PYTHON_BIN in ${PYTHON_VERSIONS}; do
76-
${PYTHON_BIN}/python -m pip install --upgrade pip
77-
${PYTHON_BIN}/python -m pip install \
78-
--requirement ${REPO_ROOT}/scripts/dev-requirements.txt
79-
${PYTHON_BIN}/python -m pip wheel . --wheel-dir dist_wheels/
80-
done
47+
${MAIN_PYTHON_BIN}/python -m pip install --upgrade pip
48+
${MAIN_PYTHON_BIN}/python -m pip install \
49+
--requirement ${REPO_ROOT}/scripts/dev-requirements.txt
50+
${MAIN_PYTHON_BIN}/python -m pip wheel . --wheel-dir dist_wheels/
8151

8252
# Bundle external shared libraries into the wheels
8353
for whl in dist_wheels/google_crc32c*.whl; do

scripts/manylinux/check.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ for PYTHON_VERSION in "${SUPPORTED_PYTHON_VERSIONS[@]}"; do
4848
${PYTHON} -m venv venv
4949

5050
# Install the wheel.
51-
WHEEL_FILE="wheels/google_crc32c-${PACKAGE_VERSION}-cp${PYTHON_VERSION//.}-cp${PYTHON_VERSION//.}-manylinux_2_17_x86_64.manylinux2014_x86_64.whl"
51+
WHEEL_FILE="wheels/google_crc32c-${PACKAGE_VERSION}-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl"
5252
venv/bin/pip install ${WHEEL_FILE}
5353

5454
# Verify that the module is installed and peek at contents.

scripts/osx/build.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ git submodule update --init --recursive
4242

4343
${OSX_DIR}/build_c_lib.sh
4444

45+
export CRC32C_PURE_PYTHON=0
46+
export CRC32C_LIMITED_API=1
4547
SUPPORTED_PYTHON_VERSIONS=("3.9" "3.10" "3.11" "3.12")
46-
47-
for PYTHON_VERSION in ${SUPPORTED_PYTHON_VERSIONS[@]}; do
48-
echo "Build wheel for Python ${PYTHON_VERSION}"
49-
export PY_BIN=$PYTHON_VERSION
50-
export PY_TAG="cp${PYTHON_VERSION//.}-cp${PYTHON_VERSION//.}"
51-
. /${OSX_DIR}/build_python_wheel.sh
52-
done
48+
PYTHON_VERSION=${SUPPORTED_PYTHON_VERSIONS[0]};
49+
echo "Build wheel for Python ${PYTHON_VERSION}"
50+
export PY_BIN=$PYTHON_VERSION
51+
export PY_TAG="cp${PYTHON_VERSION//.}-abi3"
52+
. /${OSX_DIR}/build_python_wheel.sh
5353

5454
# Clean up.
5555
rm -fr ${CRC32C_INSTALL_PREFIX}

scripts/windows/build.bat

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ setlocal ENABLEDELAYEDEXPANSION
1818
set CMAKE_GENERATOR="Visual Studio 17 2022"
1919
set CONFIGURATION=RelWithDebInfo
2020
set CRC32C_INSTALL_PREFIX=%cd%\build\%CONFIGURATION%
21+
set CRC32C_PURE_PYTHON=0
22+
set CRC32C_LIMITED_API=1
23+
set BUILT=0
2124

2225
@rem Iterate through supported Python versions.
2326
@rem Unfortunately pyenv for Windows has an out-of-date versions list. Choco's
@@ -33,6 +36,8 @@ FOR %%P IN (3.9, 3.10, 3.11, 3.12) DO (
3336

3437
py -%%P-64 -m pip install --upgrade pip
3538

39+
if "%BUILT%"=="1" (goto test)
40+
3641
echo "Installing cmake for Python %%P"
3742
py -%%P-64 -m pip install cmake
3843

@@ -73,6 +78,9 @@ FOR %%P IN (3.9, 3.10, 3.11, 3.12) DO (
7378
echo "Building Wheel"
7479
py -%%P-64 -m pip wheel . --wheel-dir wheels/
7580

81+
set BUILT=1
82+
83+
:test
7684
echo "Built wheel, now running tests."
7785
call %~dp0/test.bat %%P || goto :error
7886

setup.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
CRC32C_PURE_PYTHON_EXPLICIT = "CRC32C_PURE_PYTHON" in os.environ
2727
_FALSE_OPTIONS = ("0", "false", "no", "False", "No", None)
2828
CRC32C_PURE_PYTHON = os.getenv("CRC32C_PURE_PYTHON") not in _FALSE_OPTIONS
29+
# Wether or not we want to build using limited API (ABI3)
30+
CRC32C_LIMITED_API = os.getenv("CRC32C_LIMITED_API") not in _FALSE_OPTIONS
2931

3032

3133
def copy_dll(build_lib):
@@ -90,6 +92,13 @@ def build_c_extension():
9092
print("#### using global install of 'crc32c'")
9193
kwargs = {}
9294

95+
if CRC32C_LIMITED_API:
96+
kwargs["define_macros"] = [("Py_LIMITED_API", "0x03090000")]
97+
kwargs["py_limited_api"] = True
98+
options = {"bdist_wheel": {"py_limited_api": "cp39"}}
99+
else:
100+
options = {}
101+
93102
module_path = os.path.join("src", "google_crc32c", "_crc32c.c")
94103
sources=[os.path.normcase(module_path)]
95104
print(f"##### sources: {sources}")
@@ -106,7 +115,7 @@ def build_c_extension():
106115
package_dir={"": "src"},
107116
ext_modules=[module],
108117
cmdclass={"build_ext": BuildExtWithDLL},
109-
install_requires=["importlib_resources>=1.3 ; python_version < '3.9' and os_name == 'nt'"],
118+
options=options,
110119
)
111120

112121

0 commit comments

Comments
 (0)