import os import subprocess import sys import shutil def build(setup_kwargs): """ Build the C++ extension using CMake. This function is called by poetry-core during the build process. The binary is placed directly inside the uLib directory in src/Python. """ # Root of the whole project where this build_extension.py is located project_root = os.path.abspath(os.path.dirname(__file__)) # Where the extension should go package_dir = os.path.join(project_root, "src/Python/uLib") # Ensure package directory exists os.makedirs(package_dir, exist_ok=True) # Temporary build directory build_temp = os.path.join(project_root, "build_python") os.makedirs(build_temp, exist_ok=True) print(f"--- Running CMake build in {build_temp} ---") print(f"Project root: {project_root}") print(f"Target binary dir: {package_dir}") # CMake configuration cmake_args = [ f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={package_dir}", f"-DPYTHON_EXECUTABLE={sys.executable}", "-DCMAKE_BUILD_TYPE=Release", "-DUSE_CUDA=OFF", "-G", "Unix Makefiles", ] # Use micromamba to ensure Boost and VTK are found during the build subprocess.check_call(["cmake", project_root] + cmake_args, cwd=build_temp) subprocess.check_call(["cmake", "--build", ".", "--parallel", "--target", "uLib_python"], cwd=build_temp) # Ensure the package is found by poetry during the wheel creation process. # Return setup_kwargs for poetry-core. return setup_kwargs if __name__ == "__main__": build({})