1+ import  os 
12import  pathlib 
23import  subprocess 
34import  shlex 
45import  shutil 
56import  sys 
67import  tempfile 
8+ import  textwrap 
79import  typing  as  T 
810
911from  packaging .requirements  import  Requirement 
@@ -43,9 +45,14 @@ def is_meson_project(self) -> bool:
4345    # Tasks 
4446    # 
4547
46-     def  _cmd (self , * args : str , cwd = None ):
48+     def  _cmd (self , * args : str , cwd = None ,  env = None ):
4749        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 )
4956
5057    def  _run_pip (self , * args : str , cwd = None ):
5158        self ._cmd (
@@ -119,6 +126,8 @@ def build_wheel(
119126        # TODO: eventually it would be nice to use build isolation 
120127
121128        with  tempfile .TemporaryDirectory () as  td :
129+             tdp  =  pathlib .Path (td )
130+ 
122131            # I wonder if we should use hatch build instead? 
123132            self ._cmd (
124133                sys .executable ,
@@ -131,9 +140,39 @@ def build_wheel(
131140                cwd = self .path ,
132141            )
133142
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" :
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+ 
137176            shutil .move (twhl , dst_whl )
138177
139178        if  install :
0 commit comments