1
+ import os
1
2
import pathlib
2
3
import subprocess
3
4
import shlex
4
5
import shutil
5
6
import sys
6
7
import tempfile
8
+ import textwrap
7
9
import typing as T
8
10
9
11
from packaging .requirements import Requirement
@@ -43,9 +45,14 @@ def is_meson_project(self) -> bool:
43
45
# Tasks
44
46
#
45
47
46
- def _cmd (self , * args : str , cwd = None ):
48
+ def _cmd (self , * args : str , cwd = None , env = None ):
47
49
print ("+" , shlex .join (args ))
48
- subprocess .check_call (args , cwd = cwd )
50
+ if env :
51
+ envc = os .environ .copy ()
52
+ envc .update (env )
53
+ env = envc
54
+
55
+ subprocess .check_call (args , cwd = cwd , env = env )
49
56
50
57
def _run_pip (self , * args : str , cwd = None ):
51
58
self ._cmd (
@@ -119,6 +126,8 @@ def build_wheel(
119
126
# TODO: eventually it would be nice to use build isolation
120
127
121
128
with tempfile .TemporaryDirectory () as td :
129
+ tdp = pathlib .Path (td )
130
+
122
131
# I wonder if we should use hatch build instead?
123
132
self ._cmd (
124
133
sys .executable ,
@@ -131,9 +140,39 @@ def build_wheel(
131
140
cwd = self .path ,
132
141
)
133
142
134
- tdp = pathlib .Path (td )
135
- twhl = list (tdp .glob ("*.whl" ))[0 ]
136
- dst_whl = wheel_path / self ._fix_wheel_name (twhl .name )
143
+ # On macOS we need to build two wheels and merge them together to build
144
+ # a universal wheel. Fun?
145
+ # - Since this script is for CI, we assume that we are building on arm64
146
+ if sys .platform == "darwin" and self .is_meson_project ():
147
+
148
+ self ._cmd (
149
+ sys .executable ,
150
+ "-m" ,
151
+ "build" ,
152
+ "--no-isolation" ,
153
+ "--outdir" ,
154
+ td ,
155
+ * config_args ,
156
+ cwd = self .path ,
157
+ env = dict (ARCHFLAGS = "-arch x86_64" , SEMIWRAP_SKIP_PYI = "1" ),
158
+ )
159
+
160
+ native_wheels = list (map (str , tdp .glob ("*.whl" )))
161
+
162
+ self ._cmd (
163
+ sys .executable ,
164
+ "-m" ,
165
+ "delocate.cmd.delocate_merge" ,
166
+ "-vv" ,
167
+ * native_wheels ,
168
+ )
169
+
170
+ twhl = (set (map (str , tdp .glob ("*.whl" ))) - set (native_wheels )).pop ()
171
+ dst_whl = wheel_path / pathlib .Path (twhl ).name
172
+ else :
173
+ twhl = list (tdp .glob ("*.whl" ))[0 ]
174
+ dst_whl = wheel_path / self ._fix_wheel_name (twhl .name )
175
+
137
176
shutil .move (twhl , dst_whl )
138
177
139
178
if install :
0 commit comments