From 9b34561d9bbafce6b5f4feadb1264375297a0d02 Mon Sep 17 00:00:00 2001 From: Benoit Bovy Date: Thu, 7 Nov 2024 15:03:35 +0100 Subject: [PATCH] Update CI and fix Python builds (#59) * ci test python: bump python version and actions * maybe fix compile error on MacOS silicon disable error for now (int vs. long in pointer function signature). * typo * try setting flags instead * set C flag (not Fortran flag) * set flag on macos arm64 only * win python build: use flang 5 Like for the conda-forge feedstock: issue with fortran-compiler metapakage? * python win: try fix flang not found * try fix flag path * apply patch from fastscapelib-f2py feedstock --- .github/workflows/test-python.yml | 29 +++++++++++++++++------------ CMakeLists.txt | 19 ++++++++++++++++++- cmake/FindF2PY.cmake | 5 ++++- pyproject.toml | 1 + 4 files changed, 40 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index 50da043..90966b6 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -10,7 +10,7 @@ on: jobs: unix: - name: 3.8 (${{ matrix.os }}) + name: 3.12 (${{ matrix.os }}) runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -18,12 +18,12 @@ jobs: os: [ubuntu-latest, macos-latest] steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: - python-version: '3.8' + python-version: '3.12' - name: Install Python dependencies run: | @@ -50,30 +50,35 @@ jobs: run: python -c "import sys; sys.path.pop(0); import fastscapelib_fortran" windows: - name: 3.8 (windows-latest) + name: 3.12 (windows-latest) runs-on: windows-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup Conda - uses: conda-incubator/setup-miniconda@v2 + uses: conda-incubator/setup-miniconda@v3 with: - python-version: 3.8 + python-version: 3.12 miniforge-version: latest - name: Install dependencies shell: cmd run: | - conda create -n test python=3.8 cmake c-compiler fortran-compiler scikit-build pip wheel setuptools numpy + conda create -n test python=3.12 cmake c-compiler flang=5.0 scikit-build pip wheel setuptools numpy + + - name: Conda env info + shell: cmd + run: >- + conda activate test && + echo %CONDA% && + ls %CONDA%\envs\test\Library\bin - name: Build and install project shell: cmd run: >- conda activate test && - ls %CONDA%\envs\test && - ls %CONDA%\envs\test\Library\bin && - set FC="C:/Miniconda3/envs/test/Library/bin/flang.exe" && + set FC=%CONDA%\envs\test\Library\bin\flang.exe && python setup.py bdist_wheel --dist-dir="dist" -G "NMake Makefiles" -- -DCMAKE_Fortran_COMPILER:FILEPATH="%FC%" && python -m pip install --no-index --find-links="dist" fastscapelib_fortran -vvv diff --git a/CMakeLists.txt b/CMakeLists.txt index ad9c5b2..f1b3724 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,12 @@ set(CMAKE_Fortran_FLAGS_DEBUG # let F2PY (scikit-build) configure flags for F77 and F90 source if(NOT SKBUILD) set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${dialect} ${ioflags}") +else() + if(APPLE AND MAKE_SYSTEM_PROCESSOR STREQUAL "arm64") + # https://github.com/numpy/numpy/issues/25869 ? + # (seems problematic only on MacOS Mx) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=incompatible-function-pointer-types") + endif() endif() # override flags for old-school F77 files @@ -147,9 +153,10 @@ if(SKBUILD) # TODO: remove when https://github.com/scikit-build/scikit-build/pull/495 is merged set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/" ${CMAKE_MODULE_PATH}) + find_package(PythonLibs REQUIRED) + find_package(PythonExtensions REQUIRED) find_package(NumPy REQUIRED) find_package(F2PY REQUIRED) - find_package(PythonExtensions REQUIRED) set(F2PY_MODULE_NAME "_fastscapelib_fortran") @@ -158,6 +165,16 @@ if(SKBUILD) INCLUDE_DIRECTORIES ${FASTSCAPELIB_SRC_DIR} ) + if (UNIX) + if (APPLE) + set_target_properties(${F2PY_MODULE_NAME} PROPERTIES + LINK_FLAGS '-Wl,-dylib,-undefined,dynamic_lookup') + else() + set_target_properties(${F2PY_MODULE_NAME} PROPERTIES + LINK_FLAGS '-Wl,--allow-shlib-undefined') + endif() + endif() + python_extension_module(${F2PY_MODULE_NAME}) install( diff --git a/cmake/FindF2PY.cmake b/cmake/FindF2PY.cmake index 5fa39a9..6942588 100644 --- a/cmake/FindF2PY.cmake +++ b/cmake/FindF2PY.cmake @@ -66,7 +66,10 @@ # case, CMake is not used to find the compiler and configure the associated build system. # -find_program(F2PY_EXECUTABLE NAMES f2py${PYTHON_VERSION_MAJOR} f2py) +# temporarily disable and force searching the program path through the python numpy module (below) +# (see patch added in https://github.com/conda-forge/fastscapelib-f2py-feedstock/pull/17) +# (see https://github.com/conda-forge/numpy-feedstock/issues/276) +# find_program(F2PY_EXECUTABLE NAMES f2py${PYTHON_VERSION_MAJOR} f2py) # XXX This is required to support NumPy < v0.15.0. See note in module documentation above. if(NOT F2PY_EXECUTABLE) diff --git a/pyproject.toml b/pyproject.toml index 470bf86..0dc6bb9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,3 @@ [build-system] requires = ["setuptools", "wheel", "scikit-build", "cmake", "ninja", "numpy"] +build-backend = "setuptools.build_meta"