diff --git a/MODULE.bazel b/MODULE.bazel index 3ff9aea..226a472 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -53,5 +53,8 @@ bazel_dep(name = "rules_proto", version = "7.1.0") # https://registry.bazel.build/modules/rules_python bazel_dep(name = "rules_python", version = "1.7.0") -python = use_extension("@pybind11_bazel//:python/python.bzl", "python") -python.toolchain(python_version = "3.11") +python_rules = use_extension("@rules_python//python/extensions:python.bzl", "python") +python_rules.toolchain( + is_default = True, + python_version = "3.11", +) diff --git a/release/README.md b/release/README.md index 326bbb1..266062f 100644 --- a/release/README.md +++ b/release/README.md @@ -25,17 +25,22 @@ To build the py_cel wheel locally for testing: - Update release version Edit `release/build_wheel.sh`: update `VERSION` -- Run `cibuildwheel` +- Run `release/build_wheel.sh` ``` - cibuildwheel + release/build_wheel.sh + ``` + + Optionally, provide the signature of a specific target configuration, e.g. + + ``` + release/build_wheel.sh --only "cp311-manylinux_x86_64" ``` - Install the resulting wheel: ``` - pip uninstall py-cel - pip install wheelhouse/py_cel-*.whl + pip install --force-reinstall wheelhouse/py_cel-*.whl ``` - Verify that the wheel is working correctly diff --git a/release/build_wheel.sh b/release/build_wheel.sh index c8af639..f17ea47 100755 --- a/release/build_wheel.sh +++ b/release/build_wheel.sh @@ -27,7 +27,7 @@ cp "${SRC_DIR}"/release/* . sed -i "s/\$VERSION/${VERSION}/g" pyproject.toml echo "Running cibuildwheel: ${CIBWHEEL_BIN}" -"${CIBWHEEL_BIN}" +"${CIBWHEEL_BIN}" "$@" echo "Copying generated wheels to ${SRC_DIR}/wheelhouse" mkdir -p "${SRC_DIR}"/wheelhouse diff --git a/release/pyproject.toml b/release/pyproject.toml index 1740bd9..34e02f0 100644 --- a/release/pyproject.toml +++ b/release/pyproject.toml @@ -29,7 +29,9 @@ where = ["."] exclude = ["wheelhouse*", "conformance*", "custom_ext*"] [tool.cibuildwheel] -build = "cp311-*" +build = "cp311-* cp312-* cp313-*" skip = "*musllinux*" -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" test-command = "python {project}/py_cel_basic_test.py" + +[tool.cibuildwheel.linux] +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" diff --git a/release/setup.py b/release/setup.py index 2f84830..4c848cb 100644 --- a/release/setup.py +++ b/release/setup.py @@ -17,6 +17,7 @@ import os import shutil import subprocess +import sys import setuptools import setuptools.command.build_ext @@ -40,6 +41,24 @@ def run(self): self.build_extension(ext) def build_extension(self, ext): + # cibuildwheel executes setup.py using the target Python version. + # Thus, we can use the current Python version as the target version for + # the bazel build. + python_version = f'{sys.version_info.major}.{sys.version_info.minor}' + print(f'Building for target Python version: {python_version}') + + module_bazel_path = os.path.join(os.path.dirname(__file__), 'MODULE.bazel') + if os.path.exists(module_bazel_path): + sed_command = ( + "sed -i 's/python_version\\s*=\\s*\".*\"/" + f"python_version = \"{python_version}\"/' {module_bazel_path}" + ) + subprocess.check_call(sed_command, shell=True) + else: + raise RuntimeError( + f'MODULE.bazel not found at {module_bazel_path}' + ) + dest_path = self.get_ext_fullpath(ext.name) dest_dir = os.path.dirname(dest_path) os.makedirs(dest_dir, exist_ok=True)