Skip to content

Commit ed11354

Browse files
committed
Fix?
1 parent eb31c4a commit ed11354

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,14 @@ if(BUILD_PYTHON_BINDINGS)
195195
endif()
196196

197197
# Add the Python binding module
198-
add_library(dsf_python_module MODULE src/dsf/bindings.cpp)
198+
pybind11_add_module(dsf_python_module src/dsf/bindings.cpp)
199199

200200
# Ensure the Python module name has no 'lib' prefix on Unix systems
201-
set_target_properties(dsf_python_module PROPERTIES PREFIX "" OUTPUT_NAME
202-
"dsf_cpp")
201+
set_target_properties(dsf_python_module PROPERTIES OUTPUT_NAME "dsf_cpp")
203202

204203
# Link the pybind11 module with your static library and pybind11
205204
target_link_libraries(
206-
dsf_python_module PRIVATE dsf pybind11::module pybind11::headers TBB::tbb
205+
dsf_python_module PRIVATE dsf pybind11::headers TBB::tbb
207206
spdlog::spdlog)
208207
target_compile_definitions(dsf_python_module PRIVATE SPDLOG_USE_STD_FORMAT)
209208

setup.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ def build_extension(self, ext: CMakeExtension):
7878
"-DBUILD_PYTHON_BINDINGS=ON",
7979
]
8080

81+
if platform.system() == "Windows":
82+
cmake_args += [
83+
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{cfg.upper()}={extdir}"
84+
]
85+
8186
# Add macOS-specific CMake prefix paths for Homebrew dependencies
8287
if platform.system() == "Darwin": # macOS
8388
try:
@@ -155,6 +160,33 @@ def build_extension(self, ext: CMakeExtension):
155160
else:
156161
print("Warning: No TBB shared libraries found to copy.")
157162

163+
elif platform.system() == "Windows":
164+
print(f"Searching for TBB DLLs in {build_temp}...")
165+
# Look for tbb*.dll recursively
166+
tbb_dlls = list(build_temp.glob("**/tbb*.dll"))
167+
168+
if tbb_dlls:
169+
print(f"Found TBB DLLs: {tbb_dlls}")
170+
# We want to copy them to the 'dsf' package directory so we can load them in __init__.py
171+
# extdir is where dsf_cpp.pyd is (site-packages root usually)
172+
# We want site-packages/dsf/
173+
174+
# self.build_lib is usually the root of the build (e.g. build/lib.win...)
175+
# So we can construct the path to dsf package
176+
dsf_pkg_dir = Path(self.build_lib) / "dsf"
177+
dsf_pkg_dir.mkdir(parents=True, exist_ok=True)
178+
179+
# Also copy to source directory for editable installs
180+
source_dsf_dir = Path(__file__).parent / "src" / "dsf"
181+
182+
for dll in tbb_dlls:
183+
print(f"Copying {dll} to {dsf_pkg_dir}")
184+
shutil.copy2(dll, dsf_pkg_dir)
185+
print(f"Copying {dll} to {source_dsf_dir}")
186+
shutil.copy2(dll, source_dsf_dir)
187+
else:
188+
print("Warning: No TBB DLLs found. This might cause import errors.")
189+
158190
def pre_build(self):
159191
"""Extracts doxygen documentation from XML files and creates a C++ unordered_map"""
160192

src/dsf/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
import sys
2+
import os
3+
4+
# On Windows, we need to explicitly load the bundled TBB DLLs
5+
if sys.platform == "win32":
6+
import glob
7+
import ctypes
8+
# Look for tbb dlls in the same directory as this __init__.py
9+
_dll_dir = os.path.dirname(__file__)
10+
for _dll in glob.glob(os.path.join(_dll_dir, "tbb*.dll")):
11+
try:
12+
ctypes.CDLL(_dll)
13+
except Exception as e:
14+
print(f"Warning: Failed to load {_dll}: {e}")
15+
116
from dsf_cpp import __version__, LogLevel, get_log_level, set_log_level, mobility, mdt
217

318
from .python.cartography import (

0 commit comments

Comments
 (0)