Skip to content

Commit 80595f2

Browse files
TristonianJonescopybara-github
authored andcommitted
Update Python cibuildwheel to build for MacOS
PiperOrigin-RevId: 911008904
1 parent 501b2c5 commit 80595f2

4 files changed

Lines changed: 36 additions & 21 deletions

File tree

MODULE.bazel

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,14 @@ bazel_dep(name = "abseil-py", version = "2.1.0", repo_name = "com_google_absl_py
1212
bazel_dep(name = "bazel_skylib", version = "1.8.2")
1313

1414
# https://registry.bazel.build/modules/cel-cpp
15-
bazel_dep(name = "cel-cpp", version = "0.14.0", repo_name = "com_google_cel_cpp")
16-
17-
# 04/07/2025
18-
_CEL_CPP_COMMIT = "7022451780867bd9c173956f5793b5dfb600928e"
19-
20-
_CEL_CPP_SHA256 = "d1b9b2c2e9745826c1c8540a49f972ea4b93dffd5878c6a67756a2627b0119ef"
21-
22-
archive_override(
15+
bazel_dep(name = "cel-cpp", version = "0.15.0", repo_name = "com_google_cel_cpp")
16+
single_version_override(
2317
module_name = "cel-cpp",
2418
patch_cmds = [
2519
# ABSL_CONST_INIT is incompatible with MSVC-CL with the /std:c++20 option
2620
"sed -i 's/ABSL_CONST_INIT //g' common/values/optional_value.cc",
2721
],
28-
sha256 = _CEL_CPP_SHA256,
29-
strip_prefix = "cel-cpp-" + _CEL_CPP_COMMIT,
30-
url = "https://github.com/google/cel-cpp/archive/" + _CEL_CPP_COMMIT + ".tar.gz",
22+
version = "0.15.0",
3123
)
3224

3325
# https://registry.bazel.build/modules/cel-spec

release/build_wheel.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,28 @@ echo "Build directory: ${TMP_DIR}"
6464

6565
pushd "${TMP_DIR}"
6666

67-
cp -r "${SRC_DIR}"/{*,.*} .
67+
if [[ "$OSTYPE" == "darwin"* ]]; then
68+
cp -a "${SRC_DIR}"/. .
69+
else
70+
cp -r "${SRC_DIR}"/{*,.*} .
71+
fi
6872
cp "${SRC_DIR}"/release/* .
6973
rm -rf cel_expr_python/*_test.py
7074

7175
# Substitute $VERSION in pyproject.toml with the value of VERSION.
72-
sed -i "s/\$VERSION/${VERSION}/g" pyproject.toml
76+
if [[ "$OSTYPE" == "darwin"* ]]; then
77+
sed -i '' "s/\$VERSION/${VERSION}/g" pyproject.toml
78+
else
79+
sed -i "s/\$VERSION/${VERSION}/g" pyproject.toml
80+
fi
7381

7482
echo "Running cibuildwheel: ${CIBWHEEL_BIN}"
75-
python -m cibuildwheel "$@"
83+
PYTHON_BIN="python"
84+
if command -v python3 &> /dev/null; then
85+
PYTHON_BIN="python3"
86+
fi
87+
88+
"$PYTHON_BIN" -m cibuildwheel "$@"
7689

7790
echo "Copying generated wheels to ${SRC_DIR}/wheelhouse"
7891
mkdir -p "${SRC_DIR}"/wheelhouse

release/pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ where = ["."]
3636
exclude = ["codelab*", "conformance*", "custom_ext*", "release*", "testing*", "wheelhouse*"]
3737

3838
[tool.cibuildwheel]
39-
build = "cp311-* cp312-* cp313-*"
39+
build = "cp311-* cp312-* cp313-* cp314-*"
4040
skip = "*musllinux*"
4141
test-command = "python {project}/cel_basic_test.py"
4242

4343
[tool.cibuildwheel.linux]
4444
before-all = "echo 'Installing bazelisk'; curl -LO https://github.com/bazelbuild/bazelisk/releases/download/v1.19.0/bazelisk-linux-amd64 && chmod +x bazelisk-linux-amd64 && mv bazelisk-linux-amd64 /usr/local/bin/bazel"
45+
46+
[tool.cibuildwheel.macos]
47+
before-all = "echo 'Installing bazelisk'; brew install bazelisk"

release/setup.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""Helper for building py_cel with bazel for PyPI releases."""
1616

1717
import os
18+
import re
1819
import shutil
1920
import subprocess
2021
import sys
@@ -49,11 +50,15 @@ def build_extension(self, ext):
4950

5051
module_bazel_path = os.path.join(os.path.dirname(__file__), 'MODULE.bazel')
5152
if os.path.exists(module_bazel_path):
52-
sed_command = (
53-
"sed -i 's/python_version\\s*=\\s*\".*\"/"
54-
f"python_version = \"{python_version}\"/' {module_bazel_path}"
53+
with open(module_bazel_path, 'r') as f:
54+
content = f.read()
55+
content = re.sub(
56+
r'python_version\s*=\s*".*"',
57+
f'python_version = "{python_version}"',
58+
content,
5559
)
56-
subprocess.check_call(sed_command, shell=True)
60+
with open(module_bazel_path, 'w') as f:
61+
f.write(content)
5762
else:
5863
raise RuntimeError(
5964
f'MODULE.bazel not found at {module_bazel_path}'
@@ -66,6 +71,8 @@ def build_extension(self, ext):
6671
# Build with bazel
6772
# Use --compilation_mode=opt for release builds
6873
cmd = ['bazel', 'build', ext.target, '--compilation_mode=opt']
74+
if sys.platform == 'darwin':
75+
cmd.extend(['--macos_minimum_os=10.13', '--cxxopt=-faligned-allocation'])
6976
print(f"Building {ext.name} with bazel: {' '.join(cmd)}")
7077
subprocess.check_call(cmd)
7178

@@ -134,8 +141,8 @@ def build_extension(self, ext):
134141
'//cel_expr_python/ext:ext_proto',
135142
),
136143
BazelExtension(
137-
'cel_expr_python.ext.ext_string',
138-
'//cel_expr_python/ext:ext_string',
144+
'cel_expr_python.ext.ext_strings',
145+
'//cel_expr_python/ext:ext_strings',
139146
),
140147
],
141148
cmdclass={'build_ext': BazelBuild},

0 commit comments

Comments
 (0)