Skip to content

Commit

Permalink
Another try for universal build on macOS
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Heitzmann Gabrielli <[email protected]>
  • Loading branch information
heitzmann committed Dec 29, 2023
1 parent 4ec745d commit c189796
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pypi-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- uses: pypa/[email protected]
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 &&
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
30 changes: 4 additions & 26 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import numpy
import pathlib
import platform
import re
import setuptools
from setuptools.command.build_ext import build_ext

Expand Down Expand Up @@ -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]]
)
Expand All @@ -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=[
Expand Down

0 comments on commit c189796

Please sign in to comment.