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,18 @@ 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+ cmd .append ('--subcommands' )
80+ print (f'Building { ext .name } with bazel: { " " .join (cmd )} ' , flush = True )
81+ sys .stdout .flush ()
7982 subprocess .check_call (cmd )
83+ if sys .platform == 'darwin' :
84+ try :
85+ if os .path .exists ('bazel-bin' ):
86+ print (f'bazel-bin symlink points to: { os .readlink ("bazel-bin" )} ' , flush = True )
87+ else :
88+ print ('bazel-bin directory/symlink does not exist!' , flush = True )
89+ except Exception as e :
90+ print (f'Failed to read bazel-bin symlink: { e } ' , flush = True )
8091
8192 # Determine the output path of the bazel build
8293 # We handle targets like //:py_cel and //ext:ext_math
@@ -111,8 +122,15 @@ def build_extension(self, ext):
111122 f'Could not find bazel output for { ext .target } at { candidate_base } .*'
112123 )
113124
114- print (f'Copying { found } to { dest_path } ' )
125+ print (f'Copying { found } to { dest_path } ' , flush = True )
115126 shutil .copyfile (found , dest_path )
127+ if sys .platform == 'darwin' :
128+ try :
129+ print (f'Checking file architecture for { dest_path } :' , flush = True )
130+ sys .stdout .flush ()
131+ subprocess .call (['file' , dest_path ])
132+ except Exception as e :
133+ print (f'Failed to run file command: { e } ' , flush = True )
116134
117135 def platform_config_windows (self , cmd , python_version ):
118136 """Applies Windows-specific Bazel workarounds for Hermetic Python."""
@@ -163,6 +181,26 @@ def platform_config_macos(self, cmd):
163181 """Applies macOS-specific Bazel configurations."""
164182 cmd .extend (['--macos_minimum_os=10.13' , '--cxxopt=-faligned-allocation' ])
165183
184+ archflags = os .environ .get ('ARCHFLAGS' , '' )
185+ if 'x86_64' in archflags :
186+ target_arch = 'x86_64'
187+ elif 'arm64' in archflags :
188+ target_arch = 'arm64'
189+ else :
190+ machine = platform .machine ()
191+ if machine in ('AMD64' , 'x86_64' ):
192+ target_arch = 'x86_64'
193+ elif machine in ('arm64' , 'aarch64' ):
194+ target_arch = 'arm64'
195+ else :
196+ target_arch = machine
197+
198+ print (f'Target architecture for macOS: { target_arch } ' , flush = True )
199+ cmd .append (f'--macos_cpus={ target_arch } ' )
200+ cmd .append (f'--cpu=darwin_{ target_arch } ' )
201+ if target_arch == 'x86_64' :
202+ cmd .append ('--platforms=//cel_expr_python:macos_x86_64' )
203+
166204
167205setuptools .setup (
168206 name = 'cel-expr-python' ,
0 commit comments