Skip to content

Commit 815cd26

Browse files
committed
refactor: build: bundle C dispatcher and enable cp37-abi3 stable wheels
- Create the target scripts directory during wheel builds to prevent GCC `ld` crashes. - Bundle the compiled C dispatcher binary inside the wheel instead of unconditionally deleting it. - Define the `Py_LIMITED_API` macro (0x03070000) for the `omnipkg_atomic` extension to guarantee stable ABI compatibility. - Override `bdist_wheel` to enforce `cp37-abi3` tags across all CPython builds, eliminating version-specific wheel bloat and ensuring forward compatibility with Python 3.14+. - Bump setuptools upper bound to <75.0 in pyproject.toml. Modified: • pyproject.toml (+1/-1 lines) • setup.py (+32/-8 lines) [gitship-generated]
1 parent 911f916 commit 815cd26

2 files changed

Lines changed: 33 additions & 9 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build-system]
22
# Python 3.7 compatible setuptools (newer versions require Python 3.8+)
3-
requires = ["setuptools>=50.0,<70.0", "wheel", "packaging>=21.3"]
3+
requires = ["setuptools>=50.0,<75.0", "wheel", "packaging>=21.3"]
44
build-backend = "build_hooks"
55
backend-path = ["."]
66

setup.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ def _install_dispatcher_binary(install_dir=None):
4343
install_dir = Path(sys.executable).parent # $VENV/bin
4444

4545
binary_out = Path(install_dir) / "_omnipkg_dispatch_bin"
46+
47+
# 1. FIX: Create the wheel's scripts directory so GCC doesn't crash
48+
binary_out.parent.mkdir(parents=True, exist_ok=True)
4649

4750
try:
4851
result = subprocess.run(
@@ -51,18 +54,16 @@ def _install_dispatcher_binary(install_dir=None):
5154
)
5255
if result.returncode != 0:
5356
print(f" [dispatcher] Compilation failed, using Python dispatcher:")
54-
subprocess.run(
55-
["gcc", "-v", "-O2", "-o", str(binary_out), str(c_source)],
57+
subprocess.run(["gcc", "-v", "-O2", "-o", str(binary_out), str(c_source)],
5658
capture_output=False,
5759
text=True
5860
)
5961
return
6062

6163
import time
6264
print(f" [dispatcher] Looking for scripts in: {install_dir}")
63-
print(f" [dispatcher] Files in dir: {list(Path(install_dir).glob('*pkg*'))}")
6465
for attempt in range(10):
65-
replaced = []
66+
replaced =[]
6667
for name in ("8pkg", "omnipkg", "OMNIPKG", "8PKG"):
6768
target = Path(install_dir) / name
6869
if target.exists():
@@ -73,11 +74,13 @@ def _install_dispatcher_binary(install_dir=None):
7374
break
7475
time.sleep(0.5)
7576

76-
binary_out.unlink()
77+
# 2. FIX: Only delete the binary if we actually overwrote scripts!
78+
# If we are building a wheel, we WANT to keep it in the wheel.
7779
if replaced:
78-
print(f" [dispatcher] ✅ Fast C dispatcher installed in {install_dir}")
80+
binary_out.unlink()
81+
print(f" [dispatcher] ✅ Fast C dispatcher installed over: {replaced}")
7982
else:
80-
print(f" [dispatcher] No entry points found in {install_dir} — run after pip installs scripts")
83+
print(f" [dispatcher] Bundling compiled C dispatcher into the wheel.")
8184

8285
except Exception as e:
8386
print(f" [dispatcher] Skipping C dispatcher: {e}")
@@ -156,7 +159,9 @@ def _build_uv_ffi(install_dir=None):
156159
sources=["src/omnipkg/isolation/atomic_ops.c"],
157160
extra_compile_args=_c_args,
158161
optional=True,
159-
py_limited_api=True, # ← add this
162+
py_limited_api=True,
163+
# 3. FIX: You MUST define the macro for the target Python version (3.7)
164+
define_macros=[('Py_LIMITED_API', '0x03070000')],
160165
)
161166

162167
class OptionalBuildExt(build_ext):
@@ -223,6 +228,25 @@ def run(self):
223228
_install_dispatcher_binary(Path(sys.executable).parent)
224229
_build_uv_ffi(Path(sys.executable).parent)
225230

231+
# 4. FIX: Force the wheel to be tagged as cp37-abi3
232+
try:
233+
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
234+
class BdistWheelCommand(_bdist_wheel):
235+
def get_tag(self):
236+
python, abi, plat = super().get_tag()
237+
# If it's a CPython wheel, force it to cp37-abi3
238+
if python.startswith("cp"):
239+
return "cp37", "abi3", plat
240+
return python, abi, plat
241+
except ImportError:
242+
BdistWheelCommand = None
243+
244+
ext_modules = [atomic_extension]
245+
cmdclass = {'build_ext': OptionalBuildExt}
246+
247+
if BdistWheelCommand:
248+
cmdclass['bdist_wheel'] = BdistWheelCommand
249+
226250

227251
cmdclass['install'] = InstallWithDispatcher
228252
cmdclass['develop'] = DevelopWithDispatcher

0 commit comments

Comments
 (0)