From a1372a405db08c20ff10c5dfc236f0adbdbe03ba Mon Sep 17 00:00:00 2001 From: ckaros Date: Sun, 10 Sep 2023 00:13:34 -0400 Subject: [PATCH 1/3] restore building openmp from source on apple --- .github/workflows/build_wheel.yml | 20 +++++----- swmm-toolkit/CMakeLists.txt | 14 +++++-- swmm-toolkit/extern/openmp.cmake | 64 +++++++++++++++++++++++++++++++ swmm-toolkit/swmm-solver | 2 +- 4 files changed, 86 insertions(+), 14 deletions(-) create mode 100644 swmm-toolkit/extern/openmp.cmake diff --git a/.github/workflows/build_wheel.yml b/.github/workflows/build_wheel.yml index 532a87da..38f970f7 100644 --- a/.github/workflows/build_wheel.yml +++ b/.github/workflows/build_wheel.yml @@ -3,12 +3,12 @@ name: Build Wheels # Cross compile wheels only on main branch and tags on: pull_request: - branches: - - master + branches: + - master push: - branches: + branches: - master - tags: + tags: - v* workflow_dispatch: @@ -44,7 +44,7 @@ jobs: build_wheels: runs-on: ${{ matrix.os }} strategy: - fail-fast: true + fail-fast: false matrix: os: [ubuntu-latest, windows-2022, macos-12] pyver: [cp38, cp39, cp310, cp311] @@ -59,15 +59,15 @@ jobs: uses: pypa/cibuildwheel@v2.15.0 with: package-dir: ./swmm-toolkit - env: + env: CIBW_TEST_COMMAND: "pytest {package}/tests" CIBW_BEFORE_TEST: pip install -r {package}/test-requirements.txt # mac needs ninja to build CIBW_BEFORE_BUILD_MACOS: brew install ninja # configure cibuildwheel to build native archs ('auto'), and some emulated ones CIBW_ARCHS_LINUX: x86_64 - CIBW_ARCHS_WINDOWS: AMD64 - CIBW_ARCHS_MACOS: x86_64 + CIBW_ARCHS_WINDOWS: AMD64 + CIBW_ARCHS_MACOS: x86_64 # only build current supported python: https://devguide.python.org/versions/ # don't build pypy or musllinux to save build time. TODO: find a good way to support those archs CIBW_BUILD: ${{matrix.pyver}}-* @@ -75,6 +75,7 @@ jobs: # Will avoid testing on emulated architectures # Skip trying to test arm64 builds on Intel Macs CIBW_TEST_SKIP: "*-*linux_{aarch64,ppc64le,s390x} *-macosx_arm64 *-macosx_universal2:arm64" + CIBW_BUILD_VERBOSITY: 1 - uses: actions/upload-artifact@v3 with: @@ -83,7 +84,7 @@ jobs: build_cross_wheels: runs-on: ${{ matrix.os }} strategy: - fail-fast: true + fail-fast: false matrix: os: [ubuntu-latest,macos-12] pyver: [cp38, cp39, cp310, cp311] @@ -114,6 +115,7 @@ jobs: # don't build pypy or musllinux to save build time. TODO: find a good way to support those archs CIBW_BUILD: ${{matrix.pyver}}-* CIBW_SKIP: cp36-* cp37-* cp312-* pp* *-musllinux* + CIBW_BUILD_VERBOSITY: 1 - uses: actions/upload-artifact@v3 with: diff --git a/swmm-toolkit/CMakeLists.txt b/swmm-toolkit/CMakeLists.txt index 0f3f608b..048b0eee 100644 --- a/swmm-toolkit/CMakeLists.txt +++ b/swmm-toolkit/CMakeLists.txt @@ -36,10 +36,16 @@ cmake_policy(SET CMP0078 NEW) cmake_policy(SET CMP0086 NEW) include(${SWIG_USE_FILE}) -find_package(OpenMP - OPTIONAL_COMPONENTS - C -) +# If wheel build on Apple fetch and build OpenMP Library +if (APPLE) + include(./extern/openmp.cmake) +else() + find_package(OpenMP + REQUIRED + OPTIONAL_COMPONENTS + C + ) +endif() # Add project subdirectories add_subdirectory(swmm-solver) diff --git a/swmm-toolkit/extern/openmp.cmake b/swmm-toolkit/extern/openmp.cmake new file mode 100644 index 00000000..95d64eaf --- /dev/null +++ b/swmm-toolkit/extern/openmp.cmake @@ -0,0 +1,64 @@ +# +# CMakeLists.txt - CMake configuration file for OpenMP Library on Darwin +# +# Created: Mar 17, 2021 +# Updated: May 19, 2021 +# +# Author: Michael E. Tryby +# US EPA ORD/CESER +# +# Note: +# Need to build libomp for binary compatibility with Python. +# +# OpenMP library build fails for Xcode generator. Use Ninja or Unix Makefiles +# instead. +# + +################################################################################ +##################### CMAKELISTS FOR OPENMP LIBRARY ###################### +################################################################################ + +include(FetchContent) + + +FetchContent_Declare(OpenMP + URL + https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.1/openmp-12.0.1.src.tar.xz + URL_HASH + SHA256=60fe79440eaa9ebf583a6ea7f81501310388c02754dbe7dc210776014d06b091 +) + +set(OPENMP_STANDALONE_BUILD TRUE) +set(LIBOMP_INSTALL_ALIASES OFF) + +FetchContent_MakeAvailable(OpenMP) +set(OpenMP_AVAILABLE TRUE) + + +target_link_directories(omp + PUBLIC + $ + $ +) + +# install(TARGETS omp +# LIBRARY +# DESTINATION +# "${LIBRARY_DIST}" +# ) + +if(CMAKE_C_COMPILER_ID MATCHES "Clang\$") + set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp -I${CMAKE_BINARY_DIR}/_deps/openmp-build/runtime/src") + set(OpenMP_C_LIB_NAMES "omp") + set(OpenMP_omp_LIBRARY "${CMAKE_BINARY_DIR}/_deps/openmp-build/runtime/src/libomp.dylib") +endif() + +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang\$") + set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I${CMAKE_BINARY_DIR}/_deps/openmp-build/runtime/src") + set(OpenMP_CXX_LIB_NAMES "omp") + set(OpenMP_omp_LIBRARY "${CMAKE_BINARY_DIR}/_deps/openmp-build/runtime/src/libomp.dylib") +endif() + +# Save the bin directory for later use with +# ci/cd build scripts +file(WRITE _skbuild/bindir ${CMAKE_BINARY_DIR}) diff --git a/swmm-toolkit/swmm-solver b/swmm-toolkit/swmm-solver index 27dc6990..f08343db 160000 --- a/swmm-toolkit/swmm-solver +++ b/swmm-toolkit/swmm-solver @@ -1 +1 @@ -Subproject commit 27dc6990cda8bce21f6c16ddae631b37e7510ffc +Subproject commit f08343dbd7e2879d93c2e944c67cefa0e0c2d81c From 8b45bf44442dd3455d01283323360a183094077b Mon Sep 17 00:00:00 2001 From: ckaros Date: Mon, 11 Sep 2023 10:07:47 -0400 Subject: [PATCH 2/3] update submodule to support OpenMP linkage on MacOS --- swmm-toolkit/swmm-solver | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swmm-toolkit/swmm-solver b/swmm-toolkit/swmm-solver index f08343db..459db1d4 160000 --- a/swmm-toolkit/swmm-solver +++ b/swmm-toolkit/swmm-solver @@ -1 +1 @@ -Subproject commit f08343dbd7e2879d93c2e944c67cefa0e0c2d81c +Subproject commit 459db1d4dfc61ff994ae01f92eae64e378e08915 From 691e9e9ca6a9d75e64f74cb0806351000ecf9808 Mon Sep 17 00:00:00 2001 From: ckaros Date: Mon, 11 Sep 2023 15:44:17 -0400 Subject: [PATCH 3/3] cleanup openmp.cmake --- swmm-toolkit/extern/openmp.cmake | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/swmm-toolkit/extern/openmp.cmake b/swmm-toolkit/extern/openmp.cmake index 95d64eaf..baf4635f 100644 --- a/swmm-toolkit/extern/openmp.cmake +++ b/swmm-toolkit/extern/openmp.cmake @@ -41,11 +41,11 @@ target_link_directories(omp $ ) -# install(TARGETS omp -# LIBRARY -# DESTINATION -# "${LIBRARY_DIST}" -# ) +install(TARGETS omp + LIBRARY + DESTINATION + "${LIBRARY_DIST}" +) if(CMAKE_C_COMPILER_ID MATCHES "Clang\$") set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp -I${CMAKE_BINARY_DIR}/_deps/openmp-build/runtime/src") @@ -57,8 +57,4 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang\$") set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I${CMAKE_BINARY_DIR}/_deps/openmp-build/runtime/src") set(OpenMP_CXX_LIB_NAMES "omp") set(OpenMP_omp_LIBRARY "${CMAKE_BINARY_DIR}/_deps/openmp-build/runtime/src/libomp.dylib") -endif() - -# Save the bin directory for later use with -# ci/cd build scripts -file(WRITE _skbuild/bindir ${CMAKE_BINARY_DIR}) +endif() \ No newline at end of file