Skip to content

Commit c780a03

Browse files
committed
Build release wheels with matrix Python versions
1 parent 529bc3d commit c780a03

4 files changed

Lines changed: 76 additions & 34 deletions

File tree

BUILD

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,58 @@
1+
load("@python_versions//3.11:defs.bzl", py_binary_311 = "py_binary")
2+
load("@python_versions//3.12:defs.bzl", py_binary_312 = "py_binary")
3+
load("@python_versions//3.13:defs.bzl", py_binary_313 = "py_binary")
14
load("@rules_python//python:defs.bzl", "py_binary")
25
load("//envpool:requirements.bzl", "requirement")
36

7+
_SETUP_SRCS = [
8+
"setup.py",
9+
]
10+
11+
_SETUP_DATA = [
12+
"README.md",
13+
"setup.cfg",
14+
"//envpool",
15+
]
16+
17+
_SETUP_DEPS = [
18+
requirement("setuptools"),
19+
requirement("wheel"),
20+
]
21+
422
filegroup(
523
name = "clang_tidy_config",
624
data = [".clang-tidy"],
725
)
826

927
py_binary(
1028
name = "setup",
11-
srcs = [
12-
"setup.py",
13-
],
14-
data = [
15-
"README.md",
16-
"setup.cfg",
17-
"//envpool",
18-
],
29+
srcs = _SETUP_SRCS,
30+
data = _SETUP_DATA,
1931
main = "setup.py",
2032
python_version = "PY3",
21-
deps = [
22-
requirement("setuptools"),
23-
requirement("wheel"),
24-
],
33+
deps = _SETUP_DEPS,
34+
)
35+
36+
py_binary_311(
37+
name = "setup_py311",
38+
srcs = _SETUP_SRCS,
39+
data = _SETUP_DATA,
40+
main = "setup.py",
41+
deps = _SETUP_DEPS,
42+
)
43+
44+
py_binary_312(
45+
name = "setup_py312",
46+
srcs = _SETUP_SRCS,
47+
data = _SETUP_DATA,
48+
main = "setup.py",
49+
deps = _SETUP_DEPS,
50+
)
51+
52+
py_binary_313(
53+
name = "setup_py313",
54+
srcs = _SETUP_SRCS,
55+
data = _SETUP_DATA,
56+
main = "setup.py",
57+
deps = _SETUP_DEPS,
2558
)

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ BAZEL = USE_BAZEL_VERSION=$(BAZEL_VERSION) $(BAZELISK_BIN)
1313
DATE = $(shell date "+%Y-%m-%d")
1414
DOCKER_TAG = $(DATE)-$(COMMIT_HASH)
1515
DOCKER_USER = trinkle23897
16+
RELEASE_PYTHON ?= $(shell python3 -c 'import sys; print("{}.{}".format(sys.version_info[0], sys.version_info[1]))')
17+
RELEASE_SETUP_TARGET = //:setup_py$(subst .,,$(RELEASE_PYTHON))
1618
CLANG_TIDY_MAJOR = 18
1719
CLANG_TIDY_BIN = clang-tidy-$(CLANG_TIDY_MAJOR)
1820
CLANG_TIDY_WRAPPER_DIR = $(HOME)/.cache/$(PROJECT_NAME)/bin
@@ -132,9 +134,9 @@ bazel-build: bazel-install bazel-pip-requirement-dev
132134
cp bazel-bin/setup.runfiles/$(PROJECT_NAME)/dist/*.whl ./dist
133135

134136
bazel-release: bazel-install bazel-pip-requirement-release release-system-install
135-
$(BAZEL) run $(BAZELOPT) //:setup --config=release -- bdist_wheel
137+
$(BAZEL) run $(BAZELOPT) $(RELEASE_SETUP_TARGET) --config=release -- bdist_wheel
136138
mkdir -p dist
137-
cp bazel-bin/setup.runfiles/$(PROJECT_NAME)/dist/*.whl ./dist
139+
cp bazel-bin/$(subst //:,,$(RELEASE_SETUP_TARGET)).runfiles/$(PROJECT_NAME)/dist/*.whl ./dist
138140

139141
bazel-test: bazel-install bazel-pip-requirement-dev
140142
$(BAZEL) test --test_output=all $(BAZELOPT) //... --config=test --spawn_strategy=local --color=yes

envpool/python_tool_versions.bzl

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,26 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""Additional Python toolchain versions for rules_python 0.12."""
15+
"""Additional Python toolchain versions for rules_python."""
1616

17-
# Sourced from bazelbuild/rules_python 0.37.0.
18-
PYTHON_TOOL_VERSIONS = {
19-
"3.12.7": {
20-
"url": "20241008/cpython-{python_version}+20241008-{platform}-{build}.tar.gz",
21-
"sha256": {
22-
"aarch64-apple-darwin": "dd07d467f1d533b93d06e4d2ff88b91f491329510c6434297b88b584641bff5d",
23-
"aarch64-unknown-linux-gnu": "ce3230da53aacb17ff77e912170786f47db4a446d4acb6cde7c397953a032bca",
24-
"ppc64le-unknown-linux-gnu": "27d3cba42e94593c49f8610dcadd74f5b731c78f04ebabc2b0e1ba031ec09441",
25-
"s390x-unknown-linux-gnu": "1e28e0fc9cd1fa0365a149c715c44d3030b2c989ca397fc074809b943449df41",
26-
"x86_64-apple-darwin": "2347bf53ed3623645bed35adfca950b2c5291e3a759ec6c7765aa707b5dc866b",
27-
"x86_64-pc-windows-msvc": "4ed1a146c66c7dbd85b87df69b17afc166ea7d70056aaf59a49c3d987a030d3b",
28-
"x86_64-unknown-linux-gnu": "adbda1f3b77d7b65a551206e34a225375f408f9823e2e11df4c332aaecb8714b",
29-
},
30-
"strip_prefix": "python",
17+
load("@rules_python//python:versions.bzl", "MINOR_MAPPING", "TOOL_VERSIONS")
18+
19+
_PYTHON_3_12_7 = {
20+
"url": "20241008/cpython-{python_version}+20241008-{platform}-{build}.tar.gz",
21+
"sha256": {
22+
"aarch64-apple-darwin": "dd07d467f1d533b93d06e4d2ff88b91f491329510c6434297b88b584641bff5d",
23+
"aarch64-unknown-linux-gnu": "ce3230da53aacb17ff77e912170786f47db4a446d4acb6cde7c397953a032bca",
24+
"ppc64le-unknown-linux-gnu": "27d3cba42e94593c49f8610dcadd74f5b731c78f04ebabc2b0e1ba031ec09441",
25+
"s390x-unknown-linux-gnu": "1e28e0fc9cd1fa0365a149c715c44d3030b2c989ca397fc074809b943449df41",
26+
"x86_64-apple-darwin": "2347bf53ed3623645bed35adfca950b2c5291e3a759ec6c7765aa707b5dc866b",
27+
"x86_64-pc-windows-msvc": "4ed1a146c66c7dbd85b87df69b17afc166ea7d70056aaf59a49c3d987a030d3b",
28+
"x86_64-unknown-linux-gnu": "adbda1f3b77d7b65a551206e34a225375f408f9823e2e11df4c332aaecb8714b",
3129
},
30+
"strip_prefix": "python",
3231
}
32+
33+
PYTHON_TOOL_VERSIONS = dict(TOOL_VERSIONS)
34+
PYTHON_TOOL_VERSIONS["3.12.7"] = _PYTHON_3_12_7
35+
36+
PYTHON_MINOR_MAPPING = dict(MINOR_MAPPING)
37+
PYTHON_MINOR_MAPPING["3.12"] = "3.12.7"

envpool/workspace1.bzl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@
1717
load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps")
1818
load("@com_justbuchanan_rules_qt//:qt_configure.bzl", "qt_configure")
1919
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
20-
load("@rules_python//python:repositories.bzl", "python_register_toolchains")
21-
load("//envpool:python_tool_versions.bzl", "PYTHON_TOOL_VERSIONS")
20+
load("@rules_python//python:repositories.bzl", "python_register_multi_toolchains")
21+
load("//envpool:python_tool_versions.bzl", "PYTHON_MINOR_MAPPING", "PYTHON_TOOL_VERSIONS")
2222

2323
def workspace():
2424
"""Configure pip requirements."""
25-
python_register_toolchains(
26-
name = "python3_12",
27-
python_version = "3.12.7",
25+
python_register_multi_toolchains(
26+
name = "python_versions",
27+
python_versions = ["3.11", "3.12", "3.13"],
28+
default_version = "3.12",
2829
ignore_root_user_error = True,
30+
minor_mapping = PYTHON_MINOR_MAPPING,
2931
tool_versions = PYTHON_TOOL_VERSIONS,
3032
)
3133

0 commit comments

Comments
 (0)