Skip to content

Commit e33b6dd

Browse files
Add macOS/i86 wheels
PiperOrigin-RevId: 932631343
1 parent 9d5a61d commit e33b6dd

3 files changed

Lines changed: 51 additions & 3 deletions

File tree

cel_expr_python/BUILD

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,12 @@ py_test(
177177
],
178178
}),
179179
)
180+
181+
platform(
182+
name = "macos_x86_64",
183+
constraint_values = [
184+
"@platforms//os:osx",
185+
"@platforms//cpu:x86_64",
186+
],
187+
visibility = ["//visibility:public"],
188+
)

release/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ container-engine = "docker; disable_host_mount: True"
5454
before-all = "git config --global http.sslVerify false && echo 'Installing bazelisk' && cp {project}/bazelisk-linux-amd64 /usr/local/bin/bazel"
5555

5656
[tool.cibuildwheel.macos]
57+
archs = ["x86_64", "arm64"]
5758
before-all = "echo 'Installing bazelisk'; brew install bazelisk"
5859

5960
[tool.cibuildwheel.windows]

release/setup.py

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import glob
1818
import os
19+
import platform
1920
import re
2021
import shutil
2122
import 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

167205
setuptools.setup(
168206
name='cel-expr-python',

0 commit comments

Comments
 (0)