From e0a0b8e02abec994371946512be831b07fc24270 Mon Sep 17 00:00:00 2001 From: Dmitry Kropachev Date: Sun, 26 Jan 2025 09:52:42 -0400 Subject: [PATCH] cicd: fix macos builds --- .github/workflows/build-push.yml | 13 ++++++++++--- setup.py | 31 ++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-push.yml b/.github/workflows/build-push.yml index 24a1fd543..ab0e0f71d 100644 --- a/.github/workflows/build-push.yml +++ b/.github/workflows/build-push.yml @@ -40,7 +40,7 @@ jobs: - os: windows-latest platform: PyPy - - os: macos-latest + - os: macos-14 platform: all - os: macos-13 @@ -112,8 +112,15 @@ jobs: run: | echo "CIBW_BUILD=cp39* cp310* cp311* cp312* cp313*" >> $GITHUB_ENV echo "CIBW_BEFORE_TEST_MACOS=pip install -r {project}/test-requirements.txt pytest" >> $GITHUB_ENV - echo "MACOSX_DEPLOYMENT_TARGET=13.0" >> $GITHUB_ENV - + if [ "${{ matrix.os }}" == "macos-13" ]; then + echo "MACOSX_DEPLOYMENT_TARGET=13.0" >> $GITHUB_ENV; + echo "Enforcing target deployment for 13.0" + elif [ "${{ matrix.os }}" == "macos-14" ]; then + echo "MACOSX_DEPLOYMENT_TARGET=14.0" >> $GITHUB_ENV; + echo "Enforcing target deployment for 14.0" + else + echo "Unknown macos version" && false; + fi - name: Overwrite for MacOs PyPy if: runner.os == 'MacOs' && matrix.platform == 'PyPy' run: | diff --git a/setup.py b/setup.py index aff61c133..5f90da18c 100644 --- a/setup.py +++ b/setup.py @@ -134,6 +134,31 @@ def __init__(self, ext): self.ext = ext +def get_subdriname(directory_path): + try: + # List only subdirectories in the given directory + subdirectories = [name for dir in directory_path for name in os.listdir(dir) + if os.path.isdir(os.path.join(directory_path, name))] + return subdirectories + except Exception: + return [] + +def get_libev_headers_path(): + libev_hb_paths = ["/opt/homebrew/Cellar/libev", os.path.expanduser('~/homebrew/Cellar/libev')] + for hb_path in libev_hb_paths: + if not os.path.exists(hb_path): + continue + versions = [dir for dir in get_subdriname(hb_path) if dir[0] in "0123456789"] + if not versions: + continue + picked_version = sorted(versions, reverse=True)[0] + resulted_path = os.path.join(hb_path, picked_version, 'include') + warnings.warn("found libev headers in '%s'" % resulted_path) + return [resulted_path] + warnings.warn("did not find libev headers in '%s'" % libev_hb_paths) + return [] + + murmur3_ext = Extension('cassandra.cmurmur3', sources=['cassandra/cmurmur3.c']) @@ -142,7 +167,7 @@ def __init__(self, ext): libev_includes = ['/usr/include/libev', '/usr/local/include', '/opt/local/include', '/usr/include'] libev_libdirs = ['/usr/local/lib', '/opt/local/lib', '/usr/lib64'] if is_macos: - libev_includes.extend(['/opt/homebrew/include', os.path.expanduser('~/homebrew/include')]) + libev_includes.extend(['/opt/homebrew/include', os.path.expanduser('~/homebrew/include'), *get_libev_headers_path()]) libev_libdirs.extend(['/opt/homebrew/lib']) conan_envfile = Path(__file__).parent / 'build-release/conan/conandeps.env' @@ -153,9 +178,9 @@ def __init__(self, ext): libev_ext = Extension('cassandra.io.libevwrapper', sources=['cassandra/io/libevwrapper.c'], - include_dirs=['/usr/include/libev', '/usr/local/include', '/opt/local/include'], + include_dirs=libev_includes+['/usr/include/libev', '/usr/local/include', '/opt/local/include'], libraries=['ev'], - library_dirs=['/usr/local/lib', '/opt/local/lib']) + library_dirs=libev_libdirs+['/usr/local/lib', '/opt/local/lib']) platform_unsupported_msg = \ """