Skip to content

Commit 0a27dd1

Browse files
committed
python: more fixes to packaging
1 parent cc6515d commit 0a27dd1

4 files changed

Lines changed: 44 additions & 8 deletions

File tree

.github/workflows/build_python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ jobs:
101101
102102
- name: Build
103103
run: |
104-
cmake --build build --config Debug
104+
${{matrix.config.environment}} cmake --build build --config Debug
105105
106106
- name: Test
107107
if: runner.os == 'Windows'

bindings/python/CMakeLists.txt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ set(LIBREMIDI_NEEDS_READERWRITERQUEUE 1)
1111

1212
add_subdirectory(../.. libremidi-src)
1313

14-
find_package(Python 3.9 COMPONENTS Interpreter Development.Module REQUIRED)
14+
find_package(Python 3.10 COMPONENTS Interpreter Development.Module REQUIRED)
15+
find_package(Python 3.10 COMPONENTS Development.SABIModule QUIET)
1516

1617
if(NOT readerwriterqueue_FOUND AND NOT TARGET readerwriterqueue)
1718
FetchContent_Declare(
@@ -30,12 +31,26 @@ FetchContent_Declare(
3031
)
3132

3233
FetchContent_MakeAvailable(nanobind)
33-
nanobind_add_module(pylibremidi pylibremidi.cpp)
34+
35+
if(Python_VERSION VERSION_GREATER_EQUAL "3.12")
36+
nanobind_add_module(pylibremidi STABLE_ABI NB_STATIC pylibremidi.cpp)
37+
else()
38+
nanobind_add_module(pylibremidi NB_STATIC pylibremidi.cpp)
39+
endif()
3440
target_link_libraries(pylibremidi PUBLIC libremidi readerwriterqueue Boost::headers Boost::variant2 Boost::container)
3541

42+
nanobind_add_stub(
43+
pylibremidi_stub
44+
MODULE pylibremidi
45+
OUTPUT pylibremidi.pyi
46+
PYTHON_PATH $<TARGET_FILE_DIR:pylibremidi>
47+
DEPENDS pylibremidi
48+
)
49+
3650
install(TARGETS pylibremidi LIBRARY DESTINATION .)
3751

3852
install(
39-
FILES __init__.py
53+
FILES ${CMAKE_CURRENT_BINARY_DIR}/pylibremidi.pyi
4054
DESTINATION .
55+
OPTIONAL
4156
)

bindings/python/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

pyproject.toml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,30 @@ cmake.source-dir = "./bindings/python"
113113
# Setuptools-style build caching in a local directory
114114
build-dir = "build/{wheel_tag}"
115115

116-
# Build stable ABI wheels for CPython 3.10+
117-
wheel.py-api = "cp310"
118-
119116
[tool.cibuildwheel]
117+
# Build for Python 3.10, 3.11 (version-specific) and 3.12+ (stable ABI)
118+
build = "cp310-* cp311-* cp312-*"
119+
config-settings = "cmake.build-type=Release"
120+
121+
# Skip 32-bit builds, musl, and PyPy
122+
skip = "*-win32 *-manylinux_i686 *-musllinux_* pp*"
123+
124+
[tool.cibuildwheel.linux]
125+
archs = ["x86_64", "aarch64"]
126+
# Use manylinux_2_28 for pipewire availability (AlmaLinux 8 based)
127+
manylinux-x86_64-image = "manylinux_2_28"
128+
manylinux-aarch64-image = "manylinux_2_28"
129+
before-all = "dnf install -y alsa-lib-devel pipewire-devel jack-audio-connection-kit-devel"
130+
131+
[tool.cibuildwheel.macos]
132+
archs = ["x86_64", "arm64"]
133+
134+
[tool.cibuildwheel.windows]
135+
archs = ["AMD64", "ARM64"]
136+
137+
# For Python 3.12+, use stable ABI
138+
[[tool.cibuildwheel.overrides]]
139+
select = "cp312-*"
120140
config-settings = "cmake.build-type=Release"
141+
inherit.environment = "append"
142+
environment = { SKBUILD_WHEEL_PY_API = "cp312" }

0 commit comments

Comments
 (0)