From c18979689c866c6fbe6378452d5be58dee29f0e1 Mon Sep 17 00:00:00 2001 From: Lucas Heitzmann Gabrielli Date: Fri, 29 Dec 2023 09:33:35 -0300 Subject: [PATCH] Another try for universal build on macOS Signed-off-by: Lucas Heitzmann Gabrielli --- .github/workflows/pypi-packages.yml | 2 +- CMakeLists.txt | 2 ++ setup.py | 30 ++++------------------------- 3 files changed, 7 insertions(+), 27 deletions(-) diff --git a/.github/workflows/pypi-packages.yml b/.github/workflows/pypi-packages.yml index 4411265bf..7be33aec0 100644 --- a/.github/workflows/pypi-packages.yml +++ b/.github/workflows/pypi-packages.yml @@ -21,7 +21,7 @@ jobs: - uses: pypa/cibuildwheel@v2.16.2 env: CIBW_SKIP: "cp36-* cp37-* pp* *_ppc64le *_s390x" - CIBW_ARCHS_MACOS: "x86_64 arm64" + CIBW_ARCHS_MACOS: "x86_64 universal2" CIBW_BEFORE_ALL_LINUX: > yum install -y wget || apk add qhull-dev; wget https://github.com/qhull/qhull/archive/refs/tags/v8.0.2.tar.gz && diff --git a/CMakeLists.txt b/CMakeLists.txt index 630be1336..25e9d6049 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.14) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules") +set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "Target architectures on macOS") + file(READ include/gdstk/gdstk.hpp HEADER_CONTENTS) string(REGEX MATCH "GDSTK_VERSION \"([^\"]*)\"" _ ${HEADER_CONTENTS}) set(GDSTK_VERSION ${CMAKE_MATCH_1}) diff --git a/setup.py b/setup.py index a8efbee46..4e0bd2869 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,6 @@ import numpy import pathlib import platform -import re import setuptools from setuptools.command.build_ext import build_ext @@ -63,12 +62,12 @@ def run(self): elif line.startswith("Libs:"): for arg in line.split()[1:]: if darwin and (arg == "-lpython" or arg.endswith("Python.framework")): - # Do not link to python in MacOS, we use the -undefined dynamic_lookup + # Do not link to python in macOS, we use the -undefined dynamic_lookup # linker flag instead. # See https://blog.tim-smith.us/2015/09/python-extension-modules-os-x/ continue if arg.endswith(".framework"): - # MacOS-specific + # macOS-specific self.extensions[0].extra_link_args.extend( ["-framework", arg[arg.rfind("/") + 1 : -10]] ) @@ -82,32 +81,11 @@ def run(self): super().run() -def loose_version(version_string): - """Extracted from distutils.version.LooseVersion""" - version = [] - for component in re.split(r"(\d+ | [a-z]+ | \.)", version_string, flags=re.VERBOSE): - if len(component) == 0 or component == ".": - continue - try: - version.append(int(component)) - except ValueError: - version.append(component) - return tuple(version) - - extra_compile_args = [] extra_link_args = [] -if platform.system() == "Darwin" and loose_version(platform.release()) >= (17, 7): +if platform.system() == "Darwin": extra_compile_args.extend(["-std=c++11", "-mmacosx-version-min=10.9"]) - extra_link_args.extend( - [ - "-stdlib=libc++", - "-mmacosx-version-min=10.9", - "-undefined", - "dynamic_lookup", - "-flat_namespace", - ] - ) + extra_link_args.extend(["-undefined", "dynamic_lookup", "-flat_namespace"]) setuptools.setup( ext_modules=[