From 1978d7a5a4593407c8a16bab491c36cd9b1d79a3 Mon Sep 17 00:00:00 2001 From: Michele Nottoli Date: Thu, 2 Oct 2025 09:42:28 +0200 Subject: [PATCH 1/3] Trying to fix cross compilation on conda. --- setup.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/setup.py b/setup.py index badde73b..025051f7 100755 --- a/setup.py +++ b/setup.py @@ -47,6 +47,12 @@ def build_extension(self, ext): # Add Pybind11 info cmake_args += [f"-DPYBIND11_DIR={pybind11.get_cmake_dir()}"] + # Handle cross-compilation on conda + if os.environ.get('CONDA_BUILD_CROSS_COMPILATION') == '1': + cmake_args.extend([ + f"-DCMAKE_TOOLCHAIN_FILE={os.environ.get('CMAKE_TOOLCHAIN_FILE')}", + ]) + # Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level # across all generators. if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ: From 9322d0d1f18c7411230e8d9445565977b200f4fd Mon Sep 17 00:00:00 2001 From: Michele Nottoli Date: Thu, 2 Oct 2025 10:00:42 +0200 Subject: [PATCH 2/3] Another trial to fix cross-compilation. --- setup.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 025051f7..abd58984 100755 --- a/setup.py +++ b/setup.py @@ -48,10 +48,8 @@ def build_extension(self, ext): cmake_args += [f"-DPYBIND11_DIR={pybind11.get_cmake_dir()}"] # Handle cross-compilation on conda - if os.environ.get('CONDA_BUILD_CROSS_COMPILATION') == '1': - cmake_args.extend([ - f"-DCMAKE_TOOLCHAIN_FILE={os.environ.get('CMAKE_TOOLCHAIN_FILE')}", - ]) + if "CMAKE_ARGS" in os.environ: + cmake_args += os.environ["CMAKE_ARGS"].split() # Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level # across all generators. From 2cc514088cfcda723de95d438aec7a8f058c70f2 Mon Sep 17 00:00:00 2001 From: Michele Nottoli Date: Thu, 2 Oct 2025 10:57:03 +0200 Subject: [PATCH 3/3] Capturing suffix for shared object. --- setup.py | 12 +++++++++++- src/CMakeLists.txt | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index abd58984..f7036ae7 100755 --- a/setup.py +++ b/setup.py @@ -4,10 +4,17 @@ import sys import pybind11 import subprocess +import sysconfig from setuptools import Extension, setup from setuptools.command.build_ext import build_ext +def get_ext_suffix(): + # Prefer conda-forge provided suffix (cross-compile safe) + if "PYTHON_EXT_SUFFIX" in os.environ: + return os.environ["PYTHON_EXT_SUFFIX"] + return sysconfig.get_config_var("EXT_SUFFIX") + # A CMakeExtension needs a sourcedir instead of a file list. # The name must be the _single_ output extension from the CMake build. # If you need multiple extensions, see scikit-build. @@ -28,6 +35,8 @@ def build_extension(self, ext): cfg = "Debug" if self.debug else "Release" # cfg = "Debug" + ext_suffix = get_ext_suffix() + # Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON # EXAMPLE_VERSION_INFO shows you how to pass a value into the C++ code # from Python. @@ -36,7 +45,8 @@ def build_extension(self, ext): "-DPYTHON_EXECUTABLE={}".format(sys.executable), "-DCMAKE_BUILD_TYPE={}".format(cfg), # not used on MSVC, but no harm "-DCMAKE_POSITION_INDEPENDENT_CODE=ON", - "-DCMAKE_CXX_STANDARD=14" + "-DCMAKE_CXX_STANDARD=14", + "-DPYTHON_EXT_SUFFIX={}".format(ext_suffix) ] build_args = [] diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3d498a52..4ad1b06b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -55,6 +55,9 @@ if (PYTHON) ${LAPACK_LIBRARIES} OpenMP::OpenMP_Fortran ) + if(PYTHON_EXT_SUFFIX) + set_target_properties(pyddx PROPERTIES SUFFIX "${PYTHON_EXT_SUFFIX}") + endif() endif() #