1616
1717import glob
1818import os
19+ import platform
1920import re
2021import shutil
2122import subprocess
@@ -48,7 +49,7 @@ def build_extension(self, ext):
4849 # the bazel build.
4950 python_version = f'{ sys .version_info .major } .{ sys .version_info .minor } '
5051
51- print (f'Building for target Python version: { python_version } ' )
52+ print (f'Building for target Python version: { python_version } ' , flush = True )
5253
5354 module_bazel_path = os .path .join (os .path .dirname (__file__ ), 'MODULE.bazel' )
5455 if os .path .exists (module_bazel_path ):
@@ -75,8 +76,17 @@ def build_extension(self, ext):
7576 self .platform_config_windows (cmd , python_version )
7677 if sys .platform == 'darwin' :
7778 self .platform_config_macos (cmd )
78- print (f"Building { ext .name } with bazel: { ' ' .join (cmd )} " )
79+ print (f'Building { ext .name } with bazel: { " " .join (cmd )} ' , flush = True )
80+ sys .stdout .flush ()
7981 subprocess .check_call (cmd )
82+ if sys .platform == 'darwin' :
83+ try :
84+ if os .path .exists ('bazel-bin' ):
85+ print (f'bazel-bin symlink points to: { os .readlink ("bazel-bin" )} ' , flush = True )
86+ else :
87+ print ('bazel-bin directory/symlink does not exist!' , flush = True )
88+ except Exception as e :
89+ print (f'Failed to read bazel-bin symlink: { e } ' , flush = True )
8090
8191 # Determine the output path of the bazel build
8292 # We handle targets like //:py_cel and //ext:ext_math
@@ -111,8 +121,15 @@ def build_extension(self, ext):
111121 f'Could not find bazel output for { ext .target } at { candidate_base } .*'
112122 )
113123
114- print (f'Copying { found } to { dest_path } ' )
124+ print (f'Copying { found } to { dest_path } ' , flush = True )
115125 shutil .copyfile (found , dest_path )
126+ if sys .platform == 'darwin' :
127+ try :
128+ print (f'Checking file architecture for { dest_path } :' , flush = True )
129+ sys .stdout .flush ()
130+ subprocess .call (['file' , dest_path ])
131+ except Exception as e :
132+ print (f'Failed to run file command: { e } ' , flush = True )
116133
117134 def platform_config_windows (self , cmd , python_version ):
118135 """Applies Windows-specific Bazel workarounds for Hermetic Python."""
@@ -163,6 +180,24 @@ def platform_config_macos(self, cmd):
163180 """Applies macOS-specific Bazel configurations."""
164181 cmd .extend (['--macos_minimum_os=10.13' , '--cxxopt=-faligned-allocation' ])
165182
183+ archflags = os .environ .get ('ARCHFLAGS' , '' )
184+ if 'x86_64' in archflags :
185+ target_arch = 'x86_64'
186+ elif 'arm64' in archflags :
187+ target_arch = 'arm64'
188+ else :
189+ machine = platform .machine ()
190+ if machine in ('AMD64' , 'x86_64' ):
191+ target_arch = 'x86_64'
192+ elif machine in ('arm64' , 'aarch64' ):
193+ target_arch = 'arm64'
194+ else :
195+ target_arch = machine
196+
197+ print (f'Target architecture for macOS: { target_arch } ' , flush = True )
198+ cmd .append (f'--macos_cpus={ target_arch } ' )
199+ cmd .append (f'--cpu=darwin_{ target_arch } ' )
200+
166201
167202setuptools .setup (
168203 name = 'cel-expr-python' ,
0 commit comments