Fix build failure on Python 3.14t without --enable-shared#1487
Fix build failure on Python 3.14t without --enable-shared#1487leveretconey wants to merge 1 commit into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/meta-pytorch/torchcodec/1487
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 New Failures, 2 Cancelled JobsAs of commit 01aafaa with merge base 8bbce65 ( NEW FAILURES - The following jobs have failed:
CANCELLED JOBS - The following jobs were cancelled. Please retry:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
rebased latest main because new commits fixed ci failures |
|
Thanks for the PR @leveretconey , I pulled this in #1485 but there seem to still be build issues for the free-threaded builds on windows. Did you try to confirm the build was working on your side? And can you share about your needs for free-threaded wheels on Windows specifically? |
|
Thanks @NicolasHug! Yes, I confirmed the build works on Linux with Python 3.14.5t (free-threaded, without --enable-shared). Our use case is Linux wheels only — no specific need for Windows. This PR preserves ${Python3_LIBRARIES}` linking underif(WIN32), so it shouldn't change Windows behavior. I don't have a Windows environment to investigate further, but happy to adjust if needed. |
|
I see, I got the context wrong, sorry. So in that case my question becomes: in what context do you need this? We can build linux 3.14t wheels on our CI, e.g. here: https://github.com/meta-pytorch/torchcodec/actions/runs/26814497648/job/79052728683?pr=1477 |
|
@NicolasHug Your CI Python is likely built with --enable-shared. In our environment (and many others like pyenv, system Python, official python.org builds), --enable-shared is not enabled by default. Linking ${Python3_LIBRARIES}` then pulls in the static libpython3.14t.a and fails. Since extension modules don't need to link libpython on Linux anyway, this fix is correct regardless. |
Free-threaded Python (3.13t+) uses mimalloc, whose initial-exec TLS is incompatible with shared libraries loaded via dlopen(). When Python is built without --enable-shared (the default), linking ${Python3_LIBRARIES} pulls in the static libpython3.14t.a and triggers a link error.
On Linux/macOS, extension modules don't need to link libpython — symbols resolve from the interpreter at runtime. Only Windows requires it (DLL import library).
This is consistent with how PyTorch handles it in torch/CMakeLists.txt (only links Python libraries on MSVC), and also consistent with pybind_ops in this repo which already avoids linking ${Python3_LIBRARIES}.