Skip to content

Commit b4a2e87

Browse files
pybind11_protobuf authorscopybara-github
authored andcommitted
Add MODULE.bazel
Test Python dependencies now use rules_python Update deps PiperOrigin-RevId: 609605937
1 parent 1002ae3 commit b4a2e87

14 files changed

+288
-171
lines changed

.bazelversion

Lines changed: 0 additions & 1 deletion
This file was deleted.

MODULE.bazel

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
module(
2+
name = "pybind11_protobuf",
3+
version = "head",
4+
)
5+
6+
bazel_dep(
7+
name = "bazel_skylib",
8+
version = "1.5.0",
9+
)
10+
11+
bazel_dep(
12+
name = "abseil-cpp",
13+
version = "20230802.0.bcr.1",
14+
repo_name = "com_google_absl",
15+
)
16+
17+
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
18+
19+
http_archive(
20+
name = "com_google_absl_py",
21+
sha256 = "8a3d0830e4eb4f66c4fa907c06edf6ce1c719ced811a12e26d9d3162f8471758",
22+
strip_prefix = "abseil-py-2.1.0",
23+
urls = [
24+
"https://github.com/abseil/abseil-py/archive/refs/tags/v2.1.0.tar.gz",
25+
],
26+
)
27+
28+
bazel_dep(
29+
name = "platforms",
30+
version = "0.0.8"
31+
)
32+
33+
bazel_dep(
34+
name = "pybind11_bazel",
35+
version = "2.11.1.bzl.2",
36+
)
37+
38+
bazel_dep(
39+
name = "protobuf",
40+
version = "23.1",
41+
repo_name = "com_google_protobuf"
42+
)
43+
44+
bazel_dep(
45+
name = "grpc",
46+
version = "1.56.3.bcr.1",
47+
repo_name = "com_github_grpc_grpc",
48+
)
49+
50+
bazel_dep(
51+
name = "rules_python",
52+
version = "0.31.0",
53+
)
54+
55+
SUPPORTED_PYTHON_VERSIONS = [
56+
"3.12",
57+
"3.11",
58+
"3.10",
59+
"3.9",
60+
"3.8"
61+
]
62+
63+
DEFAULT_PYTHON = "3.11"
64+
65+
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
66+
[
67+
python.toolchain(
68+
python_version = version,
69+
is_default = version == DEFAULT_PYTHON,
70+
)
71+
for version in SUPPORTED_PYTHON_VERSIONS
72+
]
73+
74+
use_repo(
75+
python,
76+
python = "python_versions",
77+
)
78+
79+
#### DEV ONLY DEPENDENCIES BELOW HERE ####
80+
81+
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip", dev_dependency=True)
82+
[
83+
pip.parse(
84+
hub_name = "pypi",
85+
python_version = version,
86+
requirements_lock = "//pybind11_protobuf/requirements:requirements_lock_" + version.replace('.','_') + ".txt",
87+
)
88+
for version in SUPPORTED_PYTHON_VERSIONS
89+
90+
]
91+
92+
use_repo(pip, "pypi")

WORKSPACE

Lines changed: 69 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,92 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
55
http_archive(
66
name = "bazel_skylib",
77
urls = [
8-
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
9-
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.1.1/bazel-skylib-1.1.1.tar.gz",
8+
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.5.0/bazel-skylib-1.5.0.tar.gz"
109
],
11-
sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d",
10+
sha256 = "cd55a062e763b9349921f0f5db8c3933288dc8ba4f76dd9416aac68acee3cb94",
1211
)
1312

1413
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
1514

1615
bazel_skylib_workspace()
1716

18-
1917
http_archive(
2018
name = "com_google_absl",
21-
sha256 = "5366d7e7fa7ba0d915014d387b66d0d002c03236448e1ba9ef98122c13b35c36", # SHARED_ABSL_SHA
22-
strip_prefix = "abseil-cpp-20230125.3",
19+
sha256 = "59d2976af9d6ecf001a81a35749a6e551a335b949d34918cfade07737b9d93c5", # SHARED_ABSL_SHA
20+
strip_prefix = "abseil-cpp-20230802.0",
2321
urls = [
24-
"https://github.com/abseil/abseil-cpp/archive/refs/tags/20230125.3.tar.gz",
22+
"https://github.com/abseil/abseil-cpp/archive/refs/tags/20230802.0.tar.gz"
2523
],
2624
)
2725

2826
http_archive(
2927
name = "com_google_absl_py",
30-
repo_mapping = {"@six_archive": "@six"},
31-
sha256 = "0be59b82d65dfa1f995365dcfea2cc57989297b065fda696ef13f30fcc6c8e5b",
32-
strip_prefix = "abseil-py-pypi-v0.15.0",
28+
sha256 = "8a3d0830e4eb4f66c4fa907c06edf6ce1c719ced811a12e26d9d3162f8471758",
29+
strip_prefix = "abseil-py-2.1.0",
3330
urls = [
34-
"https://github.com/abseil/abseil-py/archive/refs/tags/pypi-v0.15.0.tar.gz",
31+
"https://github.com/abseil/abseil-py/archive/refs/tags/v2.1.0.tar.gz",
32+
],
33+
)
34+
35+
http_archive(
36+
name = "rules_python",
37+
sha256 = "c68bdc4fbec25de5b5493b8819cfc877c4ea299c0dcb15c244c5a00208cde311",
38+
strip_prefix = "rules_python-0.31.0",
39+
url = "https://github.com/bazelbuild/rules_python/releases/download/0.31.0/rules_python-0.31.0.tar.gz",
40+
)
41+
42+
load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_multi_toolchains")
43+
44+
py_repositories()
45+
46+
47+
DEFAULT_PYTHON = "3.11"
48+
49+
python_register_multi_toolchains(
50+
name = "python",
51+
default_version = DEFAULT_PYTHON,
52+
python_versions = [
53+
"3.12",
54+
"3.11",
55+
"3.10",
56+
"3.9",
57+
"3.8"
3558
],
3659
)
3760

61+
62+
load("@python//:pip.bzl", "multi_pip_parse")
63+
64+
multi_pip_parse(
65+
name = "pypi",
66+
default_version = DEFAULT_PYTHON,
67+
python_interpreter_target = {
68+
"3.12": "@python_3_12_host//:python",
69+
"3.11": "@python_3_11_host//:python",
70+
"3.10": "@python_3_10_host//:python",
71+
"3.9": "@python_3_9_host//:python",
72+
"3.8": "@python_3_8_host//:python",
73+
},
74+
requirements_lock = {
75+
"3.12": "//pybind11_protobuf/requirements:requirements_lock_3_12.txt",
76+
"3.11": "//pybind11_protobuf/requirements:requirements_lock_3_11.txt",
77+
"3.10": "//pybind11_protobuf/requirements:requirements_lock_3_10.txt",
78+
"3.9": "//pybind11_protobuf/requirements:requirements_lock_3_9.txt",
79+
"3.8": "//pybind11_protobuf/requirements:requirements_lock_3_8.txt",
80+
},
81+
)
82+
83+
load("@pypi//:requirements.bzl", "install_deps")
84+
85+
install_deps()
86+
3887
## `pybind11_bazel` (PINNED)
3988
# https://github.com/pybind/pybind11_bazel
4089
http_archive(
4190
name = "pybind11_bazel",
42-
strip_prefix = "pybind11_bazel-23926b00e2b2eb2fc46b17e587cf0c0cfd2f2c4b",
43-
sha256 = "f58c0d5bfd125b08075224c319a02a901c3bce11ff2cf8310c024d40f4af823e",
44-
urls = ["https://github.com/pybind/pybind11_bazel/archive/23926b00e2b2eb2fc46b17e587cf0c0cfd2f2c4b.tar.gz"],
91+
strip_prefix = "pybind11_bazel-2.11.1.bzl.2",
92+
sha256 = "e2ba5f81f3bf6a3fc0417448d49389cc7950bebe48c42c33dfeb4dd59859b9a4",
93+
urls = ["https://github.com/pybind/pybind11_bazel/releases/download/v2.11.1.bzl.2/pybind11_bazel-2.11.1.bzl.2.tar.gz"],
4594
)
4695

4796
## `pybind11` (FLOATING)
@@ -52,17 +101,14 @@ http_archive(
52101
urls = ["https://github.com/pybind/pybind11/archive/refs/heads/master.tar.gz"],
53102
)
54103

55-
load("@pybind11_bazel//:python_configure.bzl", "python_configure")
56-
python_configure(name = "local_config_python", python_version = "3")
57-
58104
# proto_library, cc_proto_library, and java_proto_library rules implicitly
59105
# depend on @com_google_protobuf for protoc and proto runtimes.
60106
# This statement defines the @com_google_protobuf repo.
61107
http_archive(
62108
name = "com_google_protobuf",
63-
sha256 = "4e176116949be52b0408dfd24f8925d1eb674a781ae242a75296b17a1c721395",
64-
strip_prefix = "protobuf-23.3",
65-
urls = ["https://github.com/protocolbuffers/protobuf/archive/refs/tags/v23.3.tar.gz"],
109+
sha256 = "d19643d265b978383352b3143f04c0641eea75a75235c111cc01a1350173180e",
110+
strip_prefix = "protobuf-25.3",
111+
urls = ["https://github.com/protocolbuffers/protobuf/releases/download/v25.3/protobuf-25.3.tar.gz"],
66112
)
67113

68114
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
@@ -73,15 +119,10 @@ protobuf_deps()
73119
# repositories, see b/189457935.
74120
http_archive(
75121
name = "com_github_grpc_grpc",
76-
sha256 = "9f387689b7fdf6c003fd90ef55853107f89a2121792146770df5486f0199f400",
77-
strip_prefix = "grpc-1.42.0",
78-
urls = ["https://github.com/grpc/grpc/archive/v1.42.0.zip"],
122+
sha256 = "84e31a77017911b2f1647ecadb0172671d96049ea9ad5109f02b4717c0f03702",
123+
strip_prefix = "grpc-1.56.3",
124+
urls = ["https://github.com/grpc/grpc/archive/refs/tags/v1.56.3.tar.gz"],
79125
)
80126

81127
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
82128
grpc_deps()
83-
84-
bind(
85-
name = "python_headers",
86-
actual = "@local_config_python//:python_headers",
87-
)

WORKSPACE.bzlmod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Empty file for cross-compatibility between MODULE.bazel and WORKSPACE
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package(
2+
default_visibility = ["//visibility:private"],
3+
)
4+
5+
load("@python//3.12:defs.bzl", compile_pip_requirements_3_12 = "compile_pip_requirements")
6+
load("@python//3.11:defs.bzl", compile_pip_requirements_3_11 = "compile_pip_requirements")
7+
load("@python//3.10:defs.bzl", compile_pip_requirements_3_10 = "compile_pip_requirements")
8+
load("@python//3.9:defs.bzl", compile_pip_requirements_3_9 = "compile_pip_requirements")
9+
load("@python//3.8:defs.bzl", compile_pip_requirements_3_8 = "compile_pip_requirements")
10+
compile_pip_requirements_3_12(
11+
name = "requirements_3_12",
12+
src = "requirements.in",
13+
requirements_txt = "requirements_lock_3_12.txt",
14+
)
15+
compile_pip_requirements_3_11(
16+
name = "requirements_3_11",
17+
src = "requirements.in",
18+
requirements_txt = "requirements_lock_3_11.txt",
19+
)
20+
compile_pip_requirements_3_10(
21+
name = "requirements_3_10",
22+
src = "requirements.in",
23+
requirements_txt = "requirements_lock_3_10.txt",
24+
)
25+
compile_pip_requirements_3_9(
26+
name = "requirements_3_9",
27+
src = "requirements.in",
28+
requirements_txt = "requirements_lock_3_9.txt",
29+
)
30+
compile_pip_requirements_3_8(
31+
name = "requirements_3_8",
32+
src = "requirements.in",
33+
requirements_txt = "requirements_lock_3_8.txt",
34+
)

requirements.txt renamed to pybind11_protobuf/requirements/requirements.in

File renamed without changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.10
3+
# by the following command:
4+
#
5+
# bazel run //pybind11_protobuf/requirements:requirements_3_10.update
6+
#
7+
absl-py==2.1.0 \
8+
--hash=sha256:526a04eadab8b4ee719ce68f204172ead1027549089702d99b9059f129ff1308 \
9+
--hash=sha256:7820790efbb316739cde8b4e19357243fc3608a152024288513dd968d7d959ff
10+
# via -r pybind11_protobuf/requirements/requirements.in
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.11
3+
# by the following command:
4+
#
5+
# bazel run //pybind11_protobuf/requirements:requirements_3_11.update
6+
#
7+
absl-py==2.1.0 \
8+
--hash=sha256:526a04eadab8b4ee719ce68f204172ead1027549089702d99b9059f129ff1308 \
9+
--hash=sha256:7820790efbb316739cde8b4e19357243fc3608a152024288513dd968d7d959ff
10+
# via -r pybind11_protobuf/requirements/requirements.in
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.12
3+
# by the following command:
4+
#
5+
# bazel run //pybind11_protobuf/requirements:requirements_3_12.update
6+
#
7+
absl-py==2.1.0 \
8+
--hash=sha256:526a04eadab8b4ee719ce68f204172ead1027549089702d99b9059f129ff1308 \
9+
--hash=sha256:7820790efbb316739cde8b4e19357243fc3608a152024288513dd968d7d959ff
10+
# via -r pybind11_protobuf/requirements/requirements.in
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.8
3+
# by the following command:
4+
#
5+
# bazel run //pybind11_protobuf/requirements:requirements_3_8.update
6+
#
7+
absl-py==2.1.0 \
8+
--hash=sha256:526a04eadab8b4ee719ce68f204172ead1027549089702d99b9059f129ff1308 \
9+
--hash=sha256:7820790efbb316739cde8b4e19357243fc3608a152024288513dd968d7d959ff
10+
# via -r pybind11_protobuf/requirements/requirements.in

0 commit comments

Comments
 (0)