From 8a2c03b7975127377438208cc18cfdee2a301efc Mon Sep 17 00:00:00 2001 From: orzel320 <52106515+orzel320@users.noreply.github.com> Date: Fri, 8 May 2026 17:59:07 +0200 Subject: [PATCH 01/13] Added readme_cpp and CMakeLists changes --- .github/workflows/readme_listings.yml | 29 +++++++++++++++++++- CMakeLists.txt | 17 ++++++++---- readme_cpp/CMakeLists.txt | 38 +++++++++++++++++++++++++++ readme_cpp/test.cpp | 7 +++++ 4 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 readme_cpp/CMakeLists.txt create mode 100644 readme_cpp/test.cpp diff --git a/.github/workflows/readme_listings.yml b/.github/workflows/readme_listings.yml index d4a3d13a..5331549e 100644 --- a/.github/workflows/readme_listings.yml +++ b/.github/workflows/readme_listings.yml @@ -97,7 +97,7 @@ jobs: assert: runs-on: ubuntu-latest - needs: [julia, python, matlab, fortran] + needs: [julia, python, matlab, fortran, cpp] steps: - uses: actions/setup-python@v2 - run: pip install numpy @@ -107,6 +107,33 @@ jobs: merge-multiple: true path: readme_output - run : python -c 'import numpy as np; import os; dir="readme_output/"; data=[float(np.loadtxt(dir+file)) for file in os.listdir(dir)]; print("data:", data); similar_as_first = np.array([abs(data[0]-k)/data[0] for k in data[1:]]); print("similar_as_first", similar_as_first); assert((similar_as_first < .5).all())' + + cpp: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, ubuntu-24.04-arm, macos-15, macos-15-intel, windows-latest] + steps: + - uses: actions/checkout@v2 + with: + submodules: recursive + + - uses: actions/setup-python@v1 + with: + python-version: "3.10" + + - uses: jwlawson/actions-setup-cmake@v1.13 + with: + cmake-version: '3.26.x' + + - run: pip install . + - run: | + cd readme_cpp + mkdir build + cd build + cmake .. + make matlab: runs-on: ubuntu-22.04 diff --git a/CMakeLists.txt b/CMakeLists.txt index d6282368..b7d0f8c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -293,7 +293,7 @@ function(scoped_sundials_setup_config) file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/sundials) execute_process( - COMMAND ${PYTHON_EXECUTABLE} "-c" "import sys; print(''.join([line for line in sys.stdin if line.startswith('set(PACKAGE_VERSION_')]))" + COMMAND ${Python_EXECUTABLE} "-c" "import sys; print(''.join([line for line in sys.stdin if line.startswith('set(PACKAGE_VERSION_')]))" INPUT_FILE ${CMAKE_SOURCE_DIR}/gitmodules/sundials/CMakeLists.txt OUTPUT_FILE ${CMAKE_BINARY_DIR}/sundials/CMakeLists.txt ) @@ -339,7 +339,7 @@ target_include_directories(camplib PRIVATE ) file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/include/camp) execute_process( - COMMAND ${PYTHON_EXECUTABLE} "-c" "import sys; print(''.join([line.replace(')','').replace('set(','#define ').replace('PACKAGE_', 'CAMP_') for line in sys.stdin if line.startswith('set(PACKAGE_VERSION')]))" + COMMAND ${Python_EXECUTABLE} "-c" "import sys; print(''.join([line.replace(')','').replace('set(','#define ').replace('PACKAGE_', 'CAMP_') for line in sys.stdin if line.startswith('set(PACKAGE_VERSION')]))" INPUT_FILE ${CMAKE_SOURCE_DIR}/gitmodules/camp/CMakeLists.txt OUTPUT_FILE ${CMAKE_BINARY_DIR}/include/camp/version.h ) @@ -366,7 +366,7 @@ endif() foreach(file ${hdf5_GENERATED_HEADERS}) execute_process( - COMMAND ${PYTHON_EXECUTABLE} "-c" "import re;open(1,'wb').write(re.sub(b'\\r',b'',open(0,'rb').read()))" + COMMAND ${Python_EXECUTABLE} "-c" "import re;open(1,'wb').write(re.sub(b'\\r',b'',open(0,'rb').read()))" INPUT_FILE ${CMAKE_SOURCE_DIR}/${file} OUTPUT_FILE ${CMAKE_BINARY_DIR}/${file} ) @@ -391,7 +391,7 @@ string(CONCAT cmd ) include(CheckFunctionExists) execute_process( - COMMAND ${PYTHON_EXECUTABLE} "-c" "${cmd}" + COMMAND ${Python_EXECUTABLE} "-c" "${cmd}" INPUT_FILE ${CMAKE_SOURCE_DIR}/gitmodules/netcdf-c/CMakeLists.txt OUTPUT_FILE ${CMAKE_BINARY_DIR}/netcdf/CMakeLists.txt ) @@ -516,7 +516,7 @@ string(CONCAT include(CheckFunctionExists) foreach(file aero_data;gas_data;output) execute_process( - COMMAND ${PYTHON_EXECUTABLE} "-c" "${cmd}" + COMMAND ${Python_EXECUTABLE} "-c" "${cmd}" INPUT_FILE ${CMAKE_SOURCE_DIR}/gitmodules/partmc/src/${file}.F90 OUTPUT_FILE ${CMAKE_BINARY_DIR}/include/${file}_parameters.hpp ) @@ -627,3 +627,10 @@ foreach(file ${PyPartMC_headers}) endforeach() _install(TARGETS _PyPartMC LIBRARY DESTINATION PyPartMC) + +# for C++ users who wish to link against the PyPartMC shared library +_install( + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/ + DESTINATION PyPartMC/include + FILES_MATCHING PATTERN "*.hpp" +) diff --git a/readme_cpp/CMakeLists.txt b/readme_cpp/CMakeLists.txt new file mode 100644 index 00000000..4ffc5510 --- /dev/null +++ b/readme_cpp/CMakeLists.txt @@ -0,0 +1,38 @@ +cmake_minimum_required(VERSION 3.22) +project(PyPartMC_CXX LANGUAGES CXX) + +find_package(Python 3.8 REQUIRED COMPONENTS Interpreter) +message(STATUS "Python_EXECUTABLE= ${Python_EXECUTABLE}") + +execute_process( + COMMAND ${Python_EXECUTABLE} -c "from pathlib import Path; import PyPartMC; print(f'{Path(PyPartMC.__file__).parent}/include')" + OUTPUT_VARIABLE PYPARTMC_INCLUDE_DIRS + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +message(STATUS "PYPARTMC_INCLUDE_DIRS= ${PYPARTMC_INCLUDE_DIRS}") + +execute_process( + COMMAND ${Python_EXECUTABLE} -c "from PyPartMC import _PyPartMC; print(f'{_PyPartMC.__file__}')" + OUTPUT_VARIABLE PYPARTMC_LIB + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE res +) +if(res) + message(FATAL_ERROR "Command failed with exit code ${res}") +endif() + +message(STATUS "PYPARTMC_LIB= ${PYPARTMC_LIB}") + + +add_executable(my_test test.cpp) +target_include_directories(my_test PUBLIC + ${PYPARTMC_INCLUDE_DIRS} + # ${Python_INCLUDE_DIRS} + RESULT_VARIABLE res +) +if(res) + message(FATAL_ERROR "Command failed with exit code ${res}") +endif() + +target_link_libraries(my_test PRIVATE PYPARTMC_LIB) \ No newline at end of file diff --git a/readme_cpp/test.cpp b/readme_cpp/test.cpp new file mode 100644 index 00000000..49468bc7 --- /dev/null +++ b/readme_cpp/test.cpp @@ -0,0 +1,7 @@ +#include "bin_grid.hpp" +#include + +int main(){ + BinGrid a; + std::cout << "Success\n"; +} \ No newline at end of file From 51e8928c1a147ce506beb7e427b0e50bb49c0f06 Mon Sep 17 00:00:00 2001 From: orzel320 <52106515+orzel320@users.noreply.github.com> Date: Wed, 13 May 2026 11:51:37 +0200 Subject: [PATCH 02/13] Fortran compilator for windows/mac, turned off some .yml files --- .../workflows/{forlint.yml => forlint.yml.off} | 0 .github/workflows/{pylint.yml => pylint.yml.off} | 0 .github/workflows/readme_listings.yml | 16 +++++++++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) rename .github/workflows/{forlint.yml => forlint.yml.off} (100%) rename .github/workflows/{pylint.yml => pylint.yml.off} (100%) diff --git a/.github/workflows/forlint.yml b/.github/workflows/forlint.yml.off similarity index 100% rename from .github/workflows/forlint.yml rename to .github/workflows/forlint.yml.off diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml.off similarity index 100% rename from .github/workflows/pylint.yml rename to .github/workflows/pylint.yml.off diff --git a/.github/workflows/readme_listings.yml b/.github/workflows/readme_listings.yml index 5331549e..3c05e43f 100644 --- a/.github/workflows/readme_listings.yml +++ b/.github/workflows/readme_listings.yml @@ -121,12 +121,26 @@ jobs: - uses: actions/setup-python@v1 with: - python-version: "3.10" + python-version: "3.12" - uses: jwlawson/actions-setup-cmake@v1.13 with: cmake-version: '3.26.x' + - if: matrix.os == 'windows-latest' + uses: msys2/setup-msys2@v2 + with: + msystem: MINGW64 + update: false + install: >- + mingw-w64-x86_64-gcc-fortran + mingw-w64-x86_64-ninja + m4 + + - if: startsWith(matrix.os, 'macos-') + run: | + brew reinstall gcc + - run: pip install . - run: | cd readme_cpp From 90d0eda03cf4b521432e68ef282479e2646de06f Mon Sep 17 00:00:00 2001 From: orzel320 <52106515+orzel320@users.noreply.github.com> Date: Wed, 13 May 2026 12:26:44 +0200 Subject: [PATCH 03/13] Added env var for fortran to readme_listings, .yml files on pull to off. --- .github/workflows/{buildwheels.yml => buildwheels.yml.off} | 0 .github/workflows/{codecov.yml => codecov.yml.off} | 0 .github/workflows/{conda.yml => conda.yml.off} | 0 .github/workflows/{pdoc.yml => pdoc.yml.off} | 0 .github/workflows/readme_listings.yml | 5 ++++- .github/workflows/{urlcheck.yml => urlcheck.yml.off} | 0 6 files changed, 4 insertions(+), 1 deletion(-) rename .github/workflows/{buildwheels.yml => buildwheels.yml.off} (100%) rename .github/workflows/{codecov.yml => codecov.yml.off} (100%) rename .github/workflows/{conda.yml => conda.yml.off} (100%) rename .github/workflows/{pdoc.yml => pdoc.yml.off} (100%) rename .github/workflows/{urlcheck.yml => urlcheck.yml.off} (100%) diff --git a/.github/workflows/buildwheels.yml b/.github/workflows/buildwheels.yml.off similarity index 100% rename from .github/workflows/buildwheels.yml rename to .github/workflows/buildwheels.yml.off diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml.off similarity index 100% rename from .github/workflows/codecov.yml rename to .github/workflows/codecov.yml.off diff --git a/.github/workflows/conda.yml b/.github/workflows/conda.yml.off similarity index 100% rename from .github/workflows/conda.yml rename to .github/workflows/conda.yml.off diff --git a/.github/workflows/pdoc.yml b/.github/workflows/pdoc.yml.off similarity index 100% rename from .github/workflows/pdoc.yml rename to .github/workflows/pdoc.yml.off diff --git a/.github/workflows/readme_listings.yml b/.github/workflows/readme_listings.yml index 3b3e700f..bdfde325 100644 --- a/.github/workflows/readme_listings.yml +++ b/.github/workflows/readme_listings.yml @@ -126,7 +126,10 @@ jobs: - uses: jwlawson/actions-setup-cmake@v1.13 with: cmake-version: '3.26.x' - + + - if: matrix.os == 'windows-latest' + run: echo "CMAKE_PROGRAM_PATH=D:/a/_temp/msys64/usr/bin" >> $GITHUB_ENV + - if: matrix.os == 'windows-latest' uses: msys2/setup-msys2@v2 with: diff --git a/.github/workflows/urlcheck.yml b/.github/workflows/urlcheck.yml.off similarity index 100% rename from .github/workflows/urlcheck.yml rename to .github/workflows/urlcheck.yml.off From 9ff610c89a079d4a51351893cc27104e234baafe Mon Sep 17 00:00:00 2001 From: orzel320 <52106515+orzel320@users.noreply.github.com> Date: Wed, 13 May 2026 12:30:06 +0200 Subject: [PATCH 04/13] python-setup@v1 to @v6 --- .github/workflows/readme_listings.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/readme_listings.yml b/.github/workflows/readme_listings.yml index bdfde325..cc77ebc2 100644 --- a/.github/workflows/readme_listings.yml +++ b/.github/workflows/readme_listings.yml @@ -119,7 +119,7 @@ jobs: with: submodules: recursive - - uses: actions/setup-python@v1 + - uses: actions/setup-python@v6 with: python-version: "3.12" From e84277623af22f92cb2b38ab1cef87ddae5e7820 Mon Sep 17 00:00:00 2001 From: Sylwester Arabas Date: Wed, 13 May 2026 12:41:01 +0200 Subject: [PATCH 05/13] fix CMake setup for Windows builds Updated environment variables for CMake on Windows. --- .github/workflows/readme_listings.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/readme_listings.yml b/.github/workflows/readme_listings.yml index cc77ebc2..3e56142e 100644 --- a/.github/workflows/readme_listings.yml +++ b/.github/workflows/readme_listings.yml @@ -128,8 +128,12 @@ jobs: cmake-version: '3.26.x' - if: matrix.os == 'windows-latest' - run: echo "CMAKE_PROGRAM_PATH=D:/a/_temp/msys64/usr/bin" >> $GITHUB_ENV - + run: | + echo CMAKE_ARGS="-DCMAKE_MAKE_PROGRAM=D:/a/_temp/msys64/mingw64/bin/ninja.exe" >> $GITHUB_ENV + echo CMAKE_PROGRAM_PATH="D:/a/_temp/msys64/usr/bin" >> $GITHUB_ENV + echo CMAKE_GENERATOR="Ninja" >> $GITHUB_ENV + echo TEMP="D:/a/_temp/" >> $GITHUB_ENV + - if: matrix.os == 'windows-latest' uses: msys2/setup-msys2@v2 with: From 91654d6b23d1d6ba01baa141392548c9c34fc4dd Mon Sep 17 00:00:00 2001 From: orzel320 <52106515+orzel320@users.noreply.github.com> Date: Mon, 18 May 2026 22:03:57 +0200 Subject: [PATCH 06/13] Linked nanobind to CMakeLists in readme_cpp, some test changes to CMakeLists in main directory for windows compatibility --- CMakeLists.txt | 8 ++++++++ readme_cpp/CMakeLists.txt | 41 ++++++++++++++++++++++++++++----------- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b7d0f8c7..eb87d645 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -629,6 +629,14 @@ endforeach() _install(TARGETS _PyPartMC LIBRARY DESTINATION PyPartMC) # for C++ users who wish to link against the PyPartMC shared library +set_target_properties(_PyPartMC PROPERTIES CXX_VISIBILITY_PRESET default C_VISIBILITY_PRESET default) + +set_target_properties(_PyPartMC PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) + +if(WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_link_options(_PyPartMC PRIVATE -Wl,--export-all-symbols) +endif() + _install( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/ DESTINATION PyPartMC/include diff --git a/readme_cpp/CMakeLists.txt b/readme_cpp/CMakeLists.txt index 4ffc5510..3db16f41 100644 --- a/readme_cpp/CMakeLists.txt +++ b/readme_cpp/CMakeLists.txt @@ -1,38 +1,57 @@ cmake_minimum_required(VERSION 3.22) project(PyPartMC_CXX LANGUAGES CXX) -find_package(Python 3.8 REQUIRED COMPONENTS Interpreter) +find_package(Python 3.8 REQUIRED COMPONENTS Interpreter Development) message(STATUS "Python_EXECUTABLE= ${Python_EXECUTABLE}") execute_process( COMMAND ${Python_EXECUTABLE} -c "from pathlib import Path; import PyPartMC; print(f'{Path(PyPartMC.__file__).parent}/include')" OUTPUT_VARIABLE PYPARTMC_INCLUDE_DIRS OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE res_inc ) +if(res_inc) + message(FATAL_ERROR "Failed to find PyPartMC include directory. Exit code: ${res_inc}") +endif() message(STATUS "PYPARTMC_INCLUDE_DIRS= ${PYPARTMC_INCLUDE_DIRS}") +execute_process( + COMMAND ${Python_EXECUTABLE} -c "import nanobind; print(nanobind.include_dir())" + OUTPUT_VARIABLE NANOBIND_INCLUDE_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE res_nano +) +if(res_nano) + message(FATAL_ERROR "Failed to find nanobind include directory. Exit code: ${res_nano}") +endif() +message(STATUS "NANOBIND_INCLUDE_DIR= ${NANOBIND_INCLUDE_DIR}") + +# 2. Get the Library File execute_process( COMMAND ${Python_EXECUTABLE} -c "from PyPartMC import _PyPartMC; print(f'{_PyPartMC.__file__}')" OUTPUT_VARIABLE PYPARTMC_LIB OUTPUT_STRIP_TRAILING_WHITESPACE - RESULT_VARIABLE res + RESULT_VARIABLE res_lib ) -if(res) - message(FATAL_ERROR "Command failed with exit code ${res}") +if(res_lib) + message(FATAL_ERROR "Failed to find PyPartMC library. Exit code: ${res_lib}") endif() message(STATUS "PYPARTMC_LIB= ${PYPARTMC_LIB}") - add_executable(my_test test.cpp) + target_include_directories(my_test PUBLIC ${PYPARTMC_INCLUDE_DIRS} - # ${Python_INCLUDE_DIRS} - RESULT_VARIABLE res + ${NANOBIND_INCLUDE_DIR} + ${Python_INCLUDE_DIRS} ) -if(res) - message(FATAL_ERROR "Command failed with exit code ${res}") -endif() -target_link_libraries(my_test PRIVATE PYPARTMC_LIB) \ No newline at end of file +target_link_libraries(my_test PRIVATE ${PYPARTMC_LIB}) + +add_custom_command(TARGET my_test POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${PYPARTMC_LIB} + $ +) \ No newline at end of file From 6e4c6098deb8636283d8c9f553160c9b2defb23a Mon Sep 17 00:00:00 2001 From: orzel320 <52106515+orzel320@users.noreply.github.com> Date: Mon, 18 May 2026 22:29:21 +0200 Subject: [PATCH 07/13] Attempted to fix cross platform linking, forced C++17 standard in readme_cpp CMakeLists, make > cmake --build . in readme_listings.yml --- .github/workflows/readme_listings.yml | 12 +++++++++++- readme_cpp/CMakeLists.txt | 13 +++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.github/workflows/readme_listings.yml b/.github/workflows/readme_listings.yml index 3e56142e..132ced35 100644 --- a/.github/workflows/readme_listings.yml +++ b/.github/workflows/readme_listings.yml @@ -127,6 +127,16 @@ jobs: with: cmake-version: '3.26.x' + - if: matrix.os != 'ubuntu-24.04-arm' + uses: jwlawson/actions-setup-cmake@v1.13 + with: + cmake-version: '3.26.x' + + - if: matrix.os == 'ubuntu-24.04-arm' + run: | + sudo apt-get update + sudo apt-get install -y cmake + - if: matrix.os == 'windows-latest' run: | echo CMAKE_ARGS="-DCMAKE_MAKE_PROGRAM=D:/a/_temp/msys64/mingw64/bin/ninja.exe" >> $GITHUB_ENV @@ -154,7 +164,7 @@ jobs: mkdir build cd build cmake .. - make + cmake --build . matlab: runs-on: ubuntu-22.04 diff --git a/readme_cpp/CMakeLists.txt b/readme_cpp/CMakeLists.txt index 3db16f41..02176ace 100644 --- a/readme_cpp/CMakeLists.txt +++ b/readme_cpp/CMakeLists.txt @@ -1,6 +1,9 @@ cmake_minimum_required(VERSION 3.22) project(PyPartMC_CXX LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED YES) + find_package(Python 3.8 REQUIRED COMPONENTS Interpreter Development) message(STATUS "Python_EXECUTABLE= ${Python_EXECUTABLE}") @@ -27,7 +30,6 @@ if(res_nano) endif() message(STATUS "NANOBIND_INCLUDE_DIR= ${NANOBIND_INCLUDE_DIR}") -# 2. Get the Library File execute_process( COMMAND ${Python_EXECUTABLE} -c "from PyPartMC import _PyPartMC; print(f'{_PyPartMC.__file__}')" OUTPUT_VARIABLE PYPARTMC_LIB @@ -48,7 +50,14 @@ target_include_directories(my_test PUBLIC ${Python_INCLUDE_DIRS} ) -target_link_libraries(my_test PRIVATE ${PYPARTMC_LIB}) +add_library(PyPartMC_ext SHARED IMPORTED) +set_target_properties(PyPartMC_ext PROPERTIES IMPORTED_LOCATION "${PYPARTMC_LIB}") + +# Link against the imported target, NOT the raw variable +target_link_libraries(my_test PRIVATE + PyPartMC_ext + ${Python_LIBRARIES} +) add_custom_command(TARGET my_test POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different From a8b1b936a3a79ab6f9fb33ac7160d77dae8b95e0 Mon Sep 17 00:00:00 2001 From: orzel320 <52106515+orzel320@users.noreply.github.com> Date: Mon, 18 May 2026 23:18:47 +0200 Subject: [PATCH 08/13] Add library shared -> unknown in readme_cpp CMakeLists, to fix compilation issue on windows --- readme_cpp/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme_cpp/CMakeLists.txt b/readme_cpp/CMakeLists.txt index 02176ace..ff3ac984 100644 --- a/readme_cpp/CMakeLists.txt +++ b/readme_cpp/CMakeLists.txt @@ -50,7 +50,7 @@ target_include_directories(my_test PUBLIC ${Python_INCLUDE_DIRS} ) -add_library(PyPartMC_ext SHARED IMPORTED) +add_library(PyPartMC_ext UNKNOWN IMPORTED) set_target_properties(PyPartMC_ext PROPERTIES IMPORTED_LOCATION "${PYPARTMC_LIB}") # Link against the imported target, NOT the raw variable From 99956a4befa2b7dfb72bd801c3b48b291ae95db6 Mon Sep 17 00:00:00 2001 From: orzel320 <52106515+orzel320@users.noreply.github.com> Date: Wed, 20 May 2026 11:39:25 +0200 Subject: [PATCH 09/13] update cmake version in CI/CD --- .github/workflows/readme_listings.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/readme_listings.yml b/.github/workflows/readme_listings.yml index 132ced35..b5619ba0 100644 --- a/.github/workflows/readme_listings.yml +++ b/.github/workflows/readme_listings.yml @@ -123,19 +123,19 @@ jobs: with: python-version: "3.12" - - uses: jwlawson/actions-setup-cmake@v1.13 + - uses: jwlawson/actions-setup-cmake@v2.20 with: cmake-version: '3.26.x' - - if: matrix.os != 'ubuntu-24.04-arm' - uses: jwlawson/actions-setup-cmake@v1.13 - with: - cmake-version: '3.26.x' - - - if: matrix.os == 'ubuntu-24.04-arm' - run: | - sudo apt-get update - sudo apt-get install -y cmake + # - if: matrix.os != 'ubuntu-24.04-arm' + # uses: jwlawson/actions-setup-cmake@v1.13 + # with: + # cmake-version: '3.26.x' + + # - if: matrix.os == 'ubuntu-24.04-arm' + # run: | + # sudo apt-get update + # sudo apt-get install -y cmake - if: matrix.os == 'windows-latest' run: | From 1fa6808f3bf4440ee8734ba06fd82ab264ac5124 Mon Sep 17 00:00:00 2001 From: orzel320 <52106515+orzel320@users.noreply.github.com> Date: Wed, 20 May 2026 12:00:18 +0200 Subject: [PATCH 10/13] Corrected cmake version typo, and added ctest --- .github/workflows/readme_listings.yml | 3 ++- readme_cpp/CMakeLists.txt | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/readme_listings.yml b/.github/workflows/readme_listings.yml index b5619ba0..ee0d82f7 100644 --- a/.github/workflows/readme_listings.yml +++ b/.github/workflows/readme_listings.yml @@ -123,7 +123,7 @@ jobs: with: python-version: "3.12" - - uses: jwlawson/actions-setup-cmake@v2.20 + - uses: jwlawson/actions-setup-cmake@v2.2.0 with: cmake-version: '3.26.x' @@ -165,6 +165,7 @@ jobs: cd build cmake .. cmake --build . + - run: ctest --output-on-failure matlab: runs-on: ubuntu-22.04 diff --git a/readme_cpp/CMakeLists.txt b/readme_cpp/CMakeLists.txt index ff3ac984..c11c7c0e 100644 --- a/readme_cpp/CMakeLists.txt +++ b/readme_cpp/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.22) project(PyPartMC_CXX LANGUAGES CXX) +enable_testing() + set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED YES) @@ -59,8 +61,12 @@ target_link_libraries(my_test PRIVATE ${Python_LIBRARIES} ) +# Copying .pyd file add_custom_command(TARGET my_test POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PYPARTMC_LIB} $ -) \ No newline at end of file +) + +add_test(NAME maketest + COMMAND my_test) \ No newline at end of file From 1667789eb03d304099ca81bc3e9d92916eae3622 Mon Sep 17 00:00:00 2001 From: orzel320 <52106515+orzel320@users.noreply.github.com> Date: Wed, 20 May 2026 12:23:19 +0200 Subject: [PATCH 11/13] Moved to correct directory before running tests --- .github/workflows/readme_listings.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/readme_listings.yml b/.github/workflows/readme_listings.yml index ee0d82f7..13c33a96 100644 --- a/.github/workflows/readme_listings.yml +++ b/.github/workflows/readme_listings.yml @@ -165,7 +165,10 @@ jobs: cd build cmake .. cmake --build . - - run: ctest --output-on-failure + - run: | + cd readme_cpp + cd build + ctest --output-on-failure matlab: runs-on: ubuntu-22.04 From f092840630f8169dfd32344c2260021623c92060 Mon Sep 17 00:00:00 2001 From: orzel320 <52106515+orzel320@users.noreply.github.com> Date: Wed, 20 May 2026 17:50:18 +0200 Subject: [PATCH 12/13] Testing if conditionally applying SHARED module type to nanobind on macos would fix compilation problems without the need to generate static libraries --- CMakeLists.txt | 13 ++++++++++++- readme_cpp/CMakeLists.txt | 17 +++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eb87d645..50759e3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -546,7 +546,13 @@ endif() find_package(nanobind CONFIG REQUIRED) add_subdirectory(gitmodules/nanobind) -nanobind_add_module(_PyPartMC STABLE_ABI ${PyPartMC_sources}) +if(APPLE) + set(PYPARTMC_MODULE_TYPE SHARED) +else() + set(PYPARTMC_MODULE_TYPE MODULE) +endif() + +nanobind_add_module(_PyPartMC ${PYPARTMC_MODULE_TYPE} STABLE_ABI ${PyPartMC_sources}) add_dependencies(_PyPartMC partmclib) set(PYPARTMC_INCLUDE_DIRS "${CMAKE_BINARY_DIR}/include;" @@ -642,3 +648,8 @@ _install( DESTINATION PyPartMC/include FILES_MATCHING PATTERN "*.hpp" ) + +_install(TARGETS partmclib + ARCHIVE DESTINATION PyPartMC/lib +) + diff --git a/readme_cpp/CMakeLists.txt b/readme_cpp/CMakeLists.txt index c11c7c0e..647d7670 100644 --- a/readme_cpp/CMakeLists.txt +++ b/readme_cpp/CMakeLists.txt @@ -10,16 +10,16 @@ find_package(Python 3.8 REQUIRED COMPONENTS Interpreter Development) message(STATUS "Python_EXECUTABLE= ${Python_EXECUTABLE}") execute_process( - COMMAND ${Python_EXECUTABLE} -c "from pathlib import Path; import PyPartMC; print(f'{Path(PyPartMC.__file__).parent}/include')" - OUTPUT_VARIABLE PYPARTMC_INCLUDE_DIRS + COMMAND ${Python_EXECUTABLE} -c "from pathlib import Path; import PyPartMC; print(f'{Path(PyPartMC.__file__).parent}')" + OUTPUT_VARIABLE PYPARTMC_DIR OUTPUT_STRIP_TRAILING_WHITESPACE - RESULT_VARIABLE res_inc + RESULT_VARIABLE res ) -if(res_inc) - message(FATAL_ERROR "Failed to find PyPartMC include directory. Exit code: ${res_inc}") +if(res) + message(FATAL_ERROR "Failed to find PyPartMC directory. Exit code: ${res}") endif() -message(STATUS "PYPARTMC_INCLUDE_DIRS= ${PYPARTMC_INCLUDE_DIRS}") +message(STATUS "PYPARTMC_DIR= ${PYPARTMC_DIR}") execute_process( COMMAND ${Python_EXECUTABLE} -c "import nanobind; print(nanobind.include_dir())" @@ -47,7 +47,7 @@ message(STATUS "PYPARTMC_LIB= ${PYPARTMC_LIB}") add_executable(my_test test.cpp) target_include_directories(my_test PUBLIC - ${PYPARTMC_INCLUDE_DIRS} + ${PYPARTMC_DIR}/include ${NANOBIND_INCLUDE_DIR} ${Python_INCLUDE_DIRS} ) @@ -57,7 +57,8 @@ set_target_properties(PyPartMC_ext PROPERTIES IMPORTED_LOCATION "${PYPARTMC_LIB} # Link against the imported target, NOT the raw variable target_link_libraries(my_test PRIVATE - PyPartMC_ext + PyPartMC_ext + ${PYPARTMC_DIR}/lib/libpartmclib.a ${Python_LIBRARIES} ) From cc5b27c305150d429cf8f3c446b9c9846838f50f Mon Sep 17 00:00:00 2001 From: orzel320 <52106515+orzel320@users.noreply.github.com> Date: Wed, 20 May 2026 18:04:41 +0200 Subject: [PATCH 13/13] Re-enabling .yml files, adding names to run instructions in cpp tests in readme_listings --- .../{buildwheels.yml.off => buildwheels.yml} | 0 .../workflows/{codecov.yml.off => codecov.yml} | 0 .github/workflows/{conda.yml.off => conda.yml} | 0 .../workflows/{forlint.yml.off => forlint.yml} | 0 .github/workflows/{pdoc.yml.off => pdoc.yml} | 0 .github/workflows/{pylint.yml.off => pylint.yml} | 0 .github/workflows/readme_listings.yml | 16 ++++------------ 7 files changed, 4 insertions(+), 12 deletions(-) rename .github/workflows/{buildwheels.yml.off => buildwheels.yml} (100%) rename .github/workflows/{codecov.yml.off => codecov.yml} (100%) rename .github/workflows/{conda.yml.off => conda.yml} (100%) rename .github/workflows/{forlint.yml.off => forlint.yml} (100%) rename .github/workflows/{pdoc.yml.off => pdoc.yml} (100%) rename .github/workflows/{pylint.yml.off => pylint.yml} (100%) diff --git a/.github/workflows/buildwheels.yml.off b/.github/workflows/buildwheels.yml similarity index 100% rename from .github/workflows/buildwheels.yml.off rename to .github/workflows/buildwheels.yml diff --git a/.github/workflows/codecov.yml.off b/.github/workflows/codecov.yml similarity index 100% rename from .github/workflows/codecov.yml.off rename to .github/workflows/codecov.yml diff --git a/.github/workflows/conda.yml.off b/.github/workflows/conda.yml similarity index 100% rename from .github/workflows/conda.yml.off rename to .github/workflows/conda.yml diff --git a/.github/workflows/forlint.yml.off b/.github/workflows/forlint.yml similarity index 100% rename from .github/workflows/forlint.yml.off rename to .github/workflows/forlint.yml diff --git a/.github/workflows/pdoc.yml.off b/.github/workflows/pdoc.yml similarity index 100% rename from .github/workflows/pdoc.yml.off rename to .github/workflows/pdoc.yml diff --git a/.github/workflows/pylint.yml.off b/.github/workflows/pylint.yml similarity index 100% rename from .github/workflows/pylint.yml.off rename to .github/workflows/pylint.yml diff --git a/.github/workflows/readme_listings.yml b/.github/workflows/readme_listings.yml index 13c33a96..63dedfb7 100644 --- a/.github/workflows/readme_listings.yml +++ b/.github/workflows/readme_listings.yml @@ -126,16 +126,6 @@ jobs: - uses: jwlawson/actions-setup-cmake@v2.2.0 with: cmake-version: '3.26.x' - - # - if: matrix.os != 'ubuntu-24.04-arm' - # uses: jwlawson/actions-setup-cmake@v1.13 - # with: - # cmake-version: '3.26.x' - - # - if: matrix.os == 'ubuntu-24.04-arm' - # run: | - # sudo apt-get update - # sudo apt-get install -y cmake - if: matrix.os == 'windows-latest' run: | @@ -159,13 +149,15 @@ jobs: brew reinstall gcc - run: pip install . - - run: | + - name: build + run: | cd readme_cpp mkdir build cd build cmake .. cmake --build . - - run: | + - name: Execute tests + run: | cd readme_cpp cd build ctest --output-on-failure