Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/pip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ jobs:
CMAKE_GENERATOR=Ninja
CMAKE_PREFIX_PATH='${{ github.workspace }}\opt'
SETUPTOOLS_SCM_OVERRIDES_FOR_HALIDE='{local_scheme="no-local-version"}'
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: delvewheel repair --ignore-existing -w {dest_dir} {wheel}
CIBW_BEFORE_TEST_LINUX: pip install cmake ninja
CIBW_TEST_COMMAND: >
cmake -G Ninja -S {project}/python_bindings/apps -B build -DCMAKE_BUILD_TYPE=Release &&
Expand Down
35 changes: 27 additions & 8 deletions python_bindings/src/halide/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
def patch_dll_dirs():
def _preload_bundled_halide_library():
# Force-load our own copy of the Halide runtime library by absolute path before
# importing halide_, so that halide_'s implicit load of the same library (by
# soname/module name) resolves to this already-loaded instance instead of
# searching LD_LIBRARY_PATH / PATH / the default dynamic linker paths, where a
# foreign, incompatible libHalide could shadow ours.
# See: https://github.com/halide/Halide/issues/8866
import ctypes
import os

if hasattr(os, "add_dll_directory"):
from pathlib import Path
from pathlib import Path

bin_dir = Path(__file__).parent / "bin"
if bin_dir.exists():
os.add_dll_directory(str(bin_dir))
root = Path(__file__).parent

bin_dir = root / "bin"
if hasattr(os, "add_dll_directory") and bin_dir.is_dir():
os.add_dll_directory(str(bin_dir))

patch_dll_dirs()
del patch_dll_dirs
for relpath in (
"bin/Halide.dll",
"lib/libHalide.dylib",
"lib64/libHalide.so",
"lib/libHalide.so",
):
lib_path = root / relpath
if lib_path.exists():
ctypes.CDLL(str(lib_path))
return


_preload_bundled_halide_library()
del _preload_bundled_halide_library

from .halide_ import * # noqa: E402, F403

Expand Down
Loading