55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
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}")
|
|
|
|
# Determine if CUDA should be enabled
|
|
use_cuda = os.environ.get("USE_CUDA", "OFF").upper()
|
|
if use_cuda in ["ON", "1", "TRUE", "YES"]:
|
|
use_cuda = "ON"
|
|
else:
|
|
use_cuda = "OFF"
|
|
|
|
# CMake configuration
|
|
cmake_args = [
|
|
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={package_dir}",
|
|
f"-DPYTHON_EXECUTABLE={sys.executable}",
|
|
"-DCMAKE_BUILD_TYPE=Release",
|
|
f"-DUSE_CUDA={use_cuda}",
|
|
"-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({})
|