Fix Windows pip packaging and cross-platform libHalide shadowing#9233
Merged
Conversation
Fixes #8866. The Python bindings could load a foreign libHalide.so/ Halide.dll that shadows the one bundled in the wheel, because halide_ depends on it by soname/module name alone, and the dynamic linker's search order (RUNPATH < LD_LIBRARY_PATH on Linux; PATH/default dirs on Windows) lets a same-named library elsewhere on the system take precedence. Confirmed via readelf (halide_.so has RUNPATH, not RPATH) and reproduced end-to-end in WSL: a garbage libHalide.so on LD_LIBRARY_PATH broke `import halide` before this fix, and no longer does after it. The fix is to explicitly load our own copy via ctypes with an absolute path before importing halide_. Both Linux's and Windows's loaders recognize a module already mapped into the process by its soname/module name and reuse it instead of searching again, so halide_'s implicit dependency resolves to our copy regardless of what else is on the search path. Separately, cibuildwheel 4.0 made delvewheel repair the Windows default, and it was erroring out trying to locate Halide.dll itself (it doesn't search inside the not-yet-repaired wheel), breaking the Windows pip packaging workflow. Re-enable it with --ignore-existing, which tells delvewheel to treat DLLs already bundled in the wheel as satisfying their own dependencies rather than erroring out trying to locate them itself. Verified against the current published win_amd64 wheel: with this flag, delvewheel leaves Halide.dll alone but still correctly vendors msvcp140.dll, a genuine external MSVC runtime dependency that isn't currently bundled at all -- so this isn't just a no-op safety net, it fixes a real gap in the Windows wheel's self-containedness. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Member
Author
|
No CI actually touches these files pre-merge. I'll merge upon approval. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9233 +/- ##
=======================================
Coverage ? 70.21%
=======================================
Files ? 255
Lines ? 78939
Branches ? 18882
=======================================
Hits ? 55424
Misses ? 17897
Partials ? 5618 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
shoaibkamil
approved these changes
Jul 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
libHalide.so. #8866: the Python bindings could load a foreignlibHalide.so/Halide.dllthat shadows the one bundled in the wheel.halide_depends on it by soname/module name alone, and the dynamic linker's search order (RUNPATH <LD_LIBRARY_PATHon Linux; PATH/default dirs on Windows) lets a same-named library elsewhere on the system take precedence over the bundled copy. Confirmed viareadelfthathalide_.sohas RUNPATH (not RPATH), and reproduced the failure end-to-end in WSL: a garbagelibHalide.soonLD_LIBRARY_PATHbrokeimport halidebefore this fix, and no longer does after it.ctypeswith an absolute path before importinghalide_. Both Linux's and Windows's loaders recognize a module already mapped into the process by its soname/module name and reuse it instead of searching again, sohalide_'s implicit dependency resolves to our copy regardless of what else is on the search path.delvewheel repairthe Windows default, and it was erroring out trying to locateHalide.dllitself (it doesn't search inside the not-yet-repaired wheel), breaking the Windows pip packaging workflow. Re-enabled with--ignore-existing, which tells delvewheel to treat DLLs already bundled in the wheel as satisfying their own dependencies rather than erroring out. Verified against the current publishedwin_amd64wheel: with this flag, delvewheel leavesHalide.dllalone but still correctly vendorsmsvcp140.dll, a genuine external MSVC runtime dependency that isn't currently bundled at all -- so this isn't just a no-op safety net, it closes a real gap in the Windows wheel's self-containedness.Test plan
libHalide.so. #8866 in WSL against the publishedhalide==21.0.0manylinux wheel (garbagelibHalide.soonLD_LIBRARY_PATHbreaks import)Func/realize) still worksdelvewheel repair --ignore-existingagainst the publishedwin_amd64wheel: no error,Halide.dlluntouched,msvcp140.dllcorrectly vendored🤖 Generated with Claude Code