Skip to content

Commit 3ba4f95

Browse files
hodoulpremia
andauthored
Fix support for ARM64 macOS python wheels (#1574) (#1585)
* Fix support for ARM64 macOS python wheels Signed-off-by: Rémi Achard <[email protected]> * Use $<SEMICOLON> generator expression to escape semicolon Signed-off-by: Rémi Achard <[email protected]> Co-authored-by: Patrick Hodoul <[email protected]> Co-authored-by: Rémi Achard <[email protected]>
1 parent 03cb778 commit 3ba4f95

File tree

10 files changed

+88
-36
lines changed

10 files changed

+88
-36
lines changed

.github/workflows/wheel_workflow.yml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,55 +52,55 @@ jobs:
5252
# CPython 32 bits
5353
# -------------------------------------------------------------------
5454
- build: CPython 3.6 32 bits
55-
python: cp36-*
55+
python: cp36-manylinux*
5656
arch: i686
5757
- build: CPython 3.7 32 bits
58-
python: cp37-*
58+
python: cp37-manylinux*
5959
arch: i686
6060
- build: CPython 3.8 32 bits
61-
python: cp38-*
61+
python: cp38-manylinux*
6262
arch: i686
6363
- build: CPython 3.9 32 bits
64-
python: cp39-*
64+
python: cp39-manylinux*
6565
arch: i686
6666
- build: CPython 3.10 32 bits
67-
python: cp310-*
67+
python: cp310-manylinux*
6868
arch: i686
6969
# -------------------------------------------------------------------
7070
# CPython 64 bits
7171
# -------------------------------------------------------------------
7272
- build: CPython 3.6 64 bits
73-
python: cp36-*
73+
python: cp36-manylinux*
7474
arch: x86_64
7575
- build: CPython 3.7 64 bits
76-
python: cp37-*
76+
python: cp37-manylinux*
7777
arch: x86_64
7878
- build: CPython 3.8 64 bits
79-
python: cp38-*
79+
python: cp38-manylinux*
8080
arch: x86_64
8181
- build: CPython 3.9 64 bits
82-
python: cp39-*
82+
python: cp39-manylinux*
8383
arch: x86_64
8484
- build: CPython 3.10 64 bits
85-
python: cp310-*
85+
python: cp310-manylinux*
8686
arch: x86_64
8787
# -------------------------------------------------------------------
8888
# CPython ARM 64 bits
8989
# -------------------------------------------------------------------
9090
- build: CPython 3.6 ARM 64 bits
91-
python: cp36-*
91+
python: cp36-manylinux*
9292
arch: aarch64
9393
- build: CPython 3.7 ARM 64 bits
94-
python: cp37-*
94+
python: cp37-manylinux*
9595
arch: aarch64
9696
- build: CPython 3.8 ARM 64 bits
97-
python: cp38-*
97+
python: cp38-manylinux*
9898
arch: aarch64
9999
- build: CPython 3.9 ARM 64 bits
100-
python: cp39-*
100+
python: cp39-manylinux*
101101
arch: aarch64
102102
- build: CPython 3.10 ARM 64 bits
103-
python: cp310-*
103+
python: cp310-manylinux*
104104
arch: aarch64
105105

106106
steps:
@@ -117,7 +117,7 @@ jobs:
117117
platforms: all
118118

119119
- name: Build wheels
120-
uses: pypa/cibuildwheel@v2.1.2
120+
uses: pypa/cibuildwheel@v2.3.1
121121
env:
122122
CIBW_BUILD: ${{ matrix.python }}
123123
CIBW_ARCHS: ${{ matrix.arch }}
@@ -163,13 +163,13 @@ jobs:
163163
# -------------------------------------------------------------------
164164
- build: CPython 3.8 ARM 64 bits
165165
python: cp38-*
166-
arch: arm64
166+
arch: universal2
167167
- build: CPython 3.9 ARM 64 bits
168168
python: cp39-*
169-
arch: arm64
169+
arch: universal2
170170
- build: CPython 3.10 ARM 64 bits
171171
python: cp310-*
172-
arch: arm64
172+
arch: universal2
173173

174174
steps:
175175
- uses: actions/checkout@v2
@@ -180,7 +180,7 @@ jobs:
180180
python-version: '3.8'
181181

182182
- name: Build wheels
183-
uses: pypa/cibuildwheel@v2.1.2
183+
uses: pypa/cibuildwheel@v2.3.1
184184
env:
185185
CIBW_BUILD: ${{ matrix.python }}
186186
CIBW_ARCHS: ${{ matrix.arch }}

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ requires = [
77
"setuptools>=42",
88
"wheel",
99
"cmake>=3.12",
10-
"ninja",
11-
"pybind11>=2.6.1",
10+
"ninja; sys_platform != 'win32' and platform_machine != 'arm64'",
1211
# Documentation requirements
1312
"six",
1413
"testresources",

setup.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ class CMakeBuild(build_ext):
6060
def build_extension(self, ext):
6161
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
6262

63-
# required for auto-detection of auxiliary "native" libs
63+
# required for auto-detection & inclusion of auxiliary "native" libs
6464
if not extdir.endswith(os.path.sep):
6565
extdir += os.path.sep
6666

67-
cfg = "Debug" if self.debug else "Release"
67+
debug = int(os.environ.get("DEBUG", 0)) if self.debug is None else self.debug
68+
cfg = "Debug" if debug else "Release"
6869

6970
# CMake lets you override the generator - we need to check this.
7071
# Can be set with Conda-Build, for example.
7172
cmake_generator = os.environ.get("CMAKE_GENERATOR", "")
7273

73-
# Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON
7474
cmake_args = [
7575
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={}".format(extdir),
7676
"-DPython_EXECUTABLE={}".format(sys.executable),
@@ -81,11 +81,14 @@ def build_extension(self, ext):
8181
"-DOCIO_BUILD_APPS=OFF",
8282
"-DOCIO_BUILD_TESTS=OFF",
8383
"-DOCIO_BUILD_GPU_TESTS=OFF",
84-
# Install pybind11 via pip to avoid issue on Windows where
85-
# ExternalProject pybind11 build detect the wrong version
86-
"-DOCIO_INSTALL_EXT_PACKAGES=MISSING",
84+
# Make sure we build everything for the requested architecture(s)
85+
"-DOCIO_INSTALL_EXT_PACKAGES=ALL",
8786
]
8887
build_args = []
88+
# Adding CMake arguments set as environment variable
89+
# (needed e.g. to build for ARM OSx on conda-forge)
90+
if "CMAKE_ARGS" in os.environ:
91+
cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item]
8992

9093
if self.compiler.compiler_type != "msvc":
9194
# Using Ninja-build since it a) is available as a wheel and b)
@@ -94,7 +97,12 @@ def build_extension(self, ext):
9497
# Users can override the generator with CMAKE_GENERATOR in CMake
9598
# 3.15+.
9699
if not cmake_generator:
97-
cmake_args += ["-GNinja"]
100+
try:
101+
import ninja # noqa: F401
102+
103+
cmake_args += ["-GNinja"]
104+
except ImportError:
105+
pass
98106

99107
else:
100108

@@ -117,6 +125,12 @@ def build_extension(self, ext):
117125
]
118126
build_args += ["--config", cfg]
119127

128+
if sys.platform.startswith("darwin"):
129+
# Cross-compile support for macOS - respect ARCHFLAGS if set
130+
archs = re.findall(r"-arch (\S+)", os.environ.get("ARCHFLAGS", ""))
131+
if archs:
132+
cmake_args += ["-DCMAKE_OSX_ARCHITECTURES={}".format(";".join(archs))]
133+
120134
# Set CMAKE_BUILD_PARALLEL_LEVEL to control the parallel build level
121135
# across all generators.
122136
if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ:

share/cmake/modules/FindHalf.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,13 @@ if(NOT Half_FOUND)
186186
endif()
187187

188188
if(APPLE)
189+
string(REPLACE ";" "$<SEMICOLON>" ESCAPED_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}")
190+
189191
set(Half_CMAKE_ARGS
190-
${Half_CMAKE_ARGS} -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET})
192+
${Half_CMAKE_ARGS}
193+
-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}
194+
-DCMAKE_OSX_ARCHITECTURES=${ESCAPED_CMAKE_OSX_ARCHITECTURES}
195+
)
191196
endif()
192197

193198
if (ANDROID)

share/cmake/modules/FindImath.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,13 @@ if(NOT Imath_FOUND)
184184
endif()
185185

186186
if(APPLE)
187+
string(REPLACE ";" "$<SEMICOLON>" ESCAPED_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}")
188+
187189
set(Imath_CMAKE_ARGS
188-
${Imath_CMAKE_ARGS} -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET})
190+
${Imath_CMAKE_ARGS}
191+
-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}
192+
-DCMAKE_OSX_ARCHITECTURES=${ESCAPED_CMAKE_OSX_ARCHITECTURES}
193+
)
189194
endif()
190195

191196
if (ANDROID)

share/cmake/modules/Findexpat.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,13 @@ if(NOT expat_FOUND)
222222
endif()
223223

224224
if(APPLE)
225+
string(REPLACE ";" "$<SEMICOLON>" ESCAPED_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}")
226+
225227
set(EXPAT_CMAKE_ARGS
226-
${EXPAT_CMAKE_ARGS} -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET})
228+
${EXPAT_CMAKE_ARGS}
229+
-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}
230+
-DCMAKE_OSX_ARCHITECTURES=${ESCAPED_CMAKE_OSX_ARCHITECTURES}
231+
)
227232
endif()
228233

229234
if (ANDROID)

share/cmake/modules/Findlcms2.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,13 @@ if(NOT lcms2_FOUND)
143143
endif()
144144

145145
if(APPLE)
146+
string(REPLACE ";" "$<SEMICOLON>" ESCAPED_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}")
147+
146148
set(lcms2_CMAKE_ARGS
147-
${lcms2_CMAKE_ARGS} -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET})
149+
${lcms2_CMAKE_ARGS}
150+
-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}
151+
-DCMAKE_OSX_ARCHITECTURES=${ESCAPED_CMAKE_OSX_ARCHITECTURES}
152+
)
148153
endif()
149154

150155
if (ANDROID)

share/cmake/modules/Findpybind11.cmake

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ if(NOT pybind11_FOUND)
165165
-DCMAKE_INSTALL_MESSAGE=${CMAKE_INSTALL_MESSAGE}
166166
-DCMAKE_INSTALL_PREFIX=${_EXT_DIST_ROOT}
167167
-DCMAKE_OBJECT_PATH_MAX=${CMAKE_OBJECT_PATH_MAX}
168+
# Using FindPython mode (PYBIND11_FINDPYTHON=ON) doesn't seem to
169+
# work when building on docker manylinux images where Development
170+
# component is not available but is hardcoded in pybind11 script.
171+
-DPYTHON_EXECUTABLE=${Python_EXECUTABLE}
168172
-DPYBIND11_INSTALL=ON
169173
-DPYBIND11_TEST=OFF
170174
)
@@ -175,8 +179,13 @@ if(NOT pybind11_FOUND)
175179
endif()
176180

177181
if(APPLE)
182+
string(REPLACE ";" "$<SEMICOLON>" ESCAPED_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}")
183+
178184
set(pybind11_CMAKE_ARGS
179-
${pybind11_CMAKE_ARGS} -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET})
185+
${pybind11_CMAKE_ARGS}
186+
-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}
187+
-DCMAKE_OSX_ARCHITECTURES=${ESCAPED_CMAKE_OSX_ARCHITECTURES}
188+
)
180189
endif()
181190

182191
if (ANDROID)

share/cmake/modules/Findpystring.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,13 @@ if(NOT pystring_FOUND)
103103
endif()
104104

105105
if(APPLE)
106+
string(REPLACE ";" "$<SEMICOLON>" ESCAPED_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}")
107+
106108
set(pystring_CMAKE_ARGS
107-
${pystring_CMAKE_ARGS} -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET})
109+
${pystring_CMAKE_ARGS}
110+
-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}
111+
-DCMAKE_OSX_ARCHITECTURES=${ESCAPED_CMAKE_OSX_ARCHITECTURES}
112+
)
108113
endif()
109114

110115

share/cmake/modules/Findyaml-cpp.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,13 @@ if(NOT yaml-cpp_FOUND)
192192
endif()
193193

194194
if(APPLE)
195+
string(REPLACE ";" "$<SEMICOLON>" ESCAPED_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}")
196+
195197
set(yaml-cpp_CMAKE_ARGS
196-
${yaml-cpp_CMAKE_ARGS} -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET})
198+
${yaml-cpp_CMAKE_ARGS}
199+
-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}
200+
-DCMAKE_OSX_ARCHITECTURES=${ESCAPED_CMAKE_OSX_ARCHITECTURES}
201+
)
197202
endif()
198203

199204

0 commit comments

Comments
 (0)