Skip to content

Commit dfb81fe

Browse files
pybind11_abseil authorscopybara-github
authored andcommitted
Added support for Bzlmod, indicated that WORKSPACE is deprecated and will be removed at a later date. Moved Python dependency support for Bazel from virtualenv to rules_python.
PiperOrigin-RevId: 607438140
1 parent bc4b562 commit dfb81fe

17 files changed

+462
-73
lines changed

MODULE.bazel

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
module(
2+
name = "pybind11_abseil",
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 = "20240116.0",
14+
repo_name = "com_google_absl",
15+
)
16+
17+
bazel_dep(
18+
name = "rules_cc",
19+
version = "0.0.9",
20+
)
21+
22+
bazel_dep(
23+
name = "rules_python",
24+
version = "0.31.0",
25+
)
26+
27+
bazel_dep(
28+
name = "platforms",
29+
version = "0.0.8"
30+
)
31+
32+
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
33+
34+
http_archive(
35+
name = "pybind11_bazel",
36+
strip_prefix = "pybind11_bazel-master",
37+
urls = ["https://github.com/pybind/pybind11_bazel/archive/refs/heads/master.tar.gz"],
38+
)
39+
40+
http_archive(
41+
name = "pybind11",
42+
build_file = "@pybind11_bazel//:pybind11.BUILD",
43+
strip_prefix = "pybind11-master",
44+
urls = ["https://github.com/pybind/pybind11/archive/refs/heads/master.tar.gz"],
45+
)
46+
47+
#### DEV ONLY DEPENDENCIES BELOW HERE ####
48+
49+
SUPPORTED_PYTHON_VERSIONS = [
50+
"3.12",
51+
"3.11",
52+
"3.10",
53+
"3.9",
54+
"3.8"
55+
]
56+
57+
DEFAULT_PYTHON = "3.11"
58+
59+
python = use_extension("@rules_python//python/extensions:python.bzl", "python", dev_dependency=True)
60+
[
61+
python.toolchain(
62+
python_version = version,
63+
is_default = version == DEFAULT_PYTHON,
64+
)
65+
for version in SUPPORTED_PYTHON_VERSIONS
66+
]
67+
68+
use_repo(
69+
python,
70+
python = "python_versions",
71+
)
72+
73+
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip", dev_dependency=True)
74+
[
75+
pip.parse(
76+
hub_name = "pypi",
77+
python_version = version,
78+
requirements_lock = "//pybind11_abseil/requirements:requirements_lock_" + version.replace('.','_') + ".txt",
79+
)
80+
for version in SUPPORTED_PYTHON_VERSIONS
81+
82+
]
83+
84+
use_repo(pip, "pypi")

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ pybind11_abseil can be built with Bazel or CMake. Instructions for both are belo
2323

2424
### Bazel
2525

26+
#### Bzlmod
27+
28+
You can depend on the Bazel module and dependencies via a single command in your MODULE.bazel:
29+
30+
```
31+
bazel_dep(
32+
name = "pybind11_abseil",
33+
version = "selected_version",
34+
)
35+
```
36+
37+
#### WORKSPACE
38+
39+
Bazel workspace support is deprecated and will be removed at a later date.
40+
2641
You will need to depend on `pybind11`, `pybind11_bazel`(see
2742
[doc](https://github.com/pybind/pybind11_bazel#installation), and on
2843
`pybind11_abseil`, e.g.

WORKSPACE

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
88
# On Mac, run curl -L https://github.com/<...>.tar.gz | shasum -a 256
99
# and update the sha256 with the result.
1010

11+
################################################################################
12+
#
13+
# WORKSPACE is being deprecated in favor of the new Bazelmod dependency system
14+
# It will be removed at some point in the future.
15+
#
16+
################################################################################
17+
1118
## `bazel_skylib` (PINNED)
1219
http_archive(
1320
name = "bazel_skylib", # 2023-05-31T19:24:07Z
@@ -27,6 +34,61 @@ http_archive(
2734
],
2835
)
2936

37+
http_archive(
38+
name = "rules_python",
39+
sha256 = "c68bdc4fbec25de5b5493b8819cfc877c4ea299c0dcb15c244c5a00208cde311",
40+
strip_prefix = "rules_python-0.31.0",
41+
url = "https://github.com/bazelbuild/rules_python/releases/download/0.31.0/rules_python-0.31.0.tar.gz",
42+
)
43+
44+
load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_multi_toolchains")
45+
46+
py_repositories()
47+
48+
load("@rules_python//python/pip_install:repositories.bzl", "pip_install_dependencies")
49+
50+
pip_install_dependencies()
51+
52+
DEFAULT_PYTHON = "3.11"
53+
54+
python_register_multi_toolchains(
55+
name = "python",
56+
default_version = DEFAULT_PYTHON,
57+
python_versions = [
58+
"3.12",
59+
"3.11",
60+
"3.10",
61+
"3.9",
62+
"3.8"
63+
],
64+
)
65+
66+
load("@python//:pip.bzl", "multi_pip_parse")
67+
68+
multi_pip_parse(
69+
name = "pypi",
70+
default_version = DEFAULT_PYTHON,
71+
python_interpreter_target = {
72+
"3.12": "@python_3_12_host//:python",
73+
"3.11": "@python_3_11_host//:python",
74+
"3.10": "@python_3_10_host//:python",
75+
"3.9": "@python_3_9_host//:python",
76+
"3.8": "@python_3_8_host//:python",
77+
},
78+
requirements_lock = {
79+
"3.12": "//pybind11_abseil/requirements:requirements_lock_3_12.txt",
80+
"3.11": "//pybind11_abseil/requirements:requirements_lock_3_11.txt",
81+
"3.10": "//pybind11_abseil/requirements:requirements_lock_3_10.txt",
82+
"3.9": "//pybind11_abseil/requirements:requirements_lock_3_9.txt",
83+
"3.8": "//pybind11_abseil/requirements:requirements_lock_3_8.txt",
84+
},
85+
)
86+
87+
load("@pypi//:requirements.bzl", "install_deps")
88+
89+
install_deps()
90+
91+
3092
## `pybind11_bazel` (FLOATING)
3193
# https://github.com/pybind/pybind11_bazel
3294
http_archive(
@@ -52,6 +114,3 @@ http_archive(
52114
# sha256 = "832e2f309c57da9c1e6d4542dedd34b24e4192ecb4d62f6f4866a737454c9970",
53115
# urls = ["https://github.com/pybind/pybind11/archive/refs/tags/v2.10.4.tar.gz"],
54116
)
55-
56-
load("@pybind11_bazel//:python_configure.bzl", "python_configure")
57-
python_configure(name = "local_config_python")

WORKSPACE.bzlmod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Present for cross-compatibility between MODULE.bazel and WORKSPACE

pybind11_abseil/BUILD

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ cc_library(
3232
visibility = ["//visibility:public"],
3333
deps = [
3434
"@com_google_absl//absl/status",
35-
"@local_config_python//:python_headers", # buildcleaner: keep
35+
"@rules_python//python/cc:current_py_cc_headers", # buildcleaner: keep
3636
],
3737
)
3838

@@ -42,7 +42,7 @@ cc_library(
4242
visibility = ["//visibility:private"],
4343
deps = [
4444
":ok_status_singleton_lib",
45-
"@local_config_python//:python_headers", # buildcleaner: keep
45+
"@rules_python//python/cc:current_py_cc_headers", # buildcleaner: keep
4646
],
4747
)
4848

@@ -52,7 +52,7 @@ cc_binary(
5252
linkshared = 1,
5353
deps = [
5454
":ok_status_singleton_pyinit_google3",
55-
"@local_config_python//:python_headers", # buildcleaner: keep
55+
"@rules_python//python/cc:current_py_cc_headers", # buildcleaner: keep
5656
],
5757
)
5858

@@ -155,7 +155,7 @@ cc_binary(
155155
linkshared = 1,
156156
deps = [
157157
":status_pyinit_google3",
158-
"@local_config_python//:python_headers", # buildcleaner: keep
158+
"@rules_python//python/cc:current_py_cc_headers", # buildcleaner: keep
159159
],
160160
)
161161

pybind11_abseil/compat/BUILD

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ cc_library(
1313
"@com_google_absl//absl/log:absl_check",
1414
"@com_google_absl//absl/log:absl_log",
1515
"@com_google_absl//absl/strings",
16-
"@local_config_python//:python_headers", # buildcleaner: keep
16+
"@rules_python//python/cc:current_py_cc_headers", # buildcleaner: keep
1717
],
1818
)
1919

@@ -26,7 +26,7 @@ cc_library(
2626
":py_base_utilities",
2727
"@com_google_absl//absl/container:flat_hash_map",
2828
"@com_google_absl//absl/status",
29-
"@local_config_python//:python_headers", # buildcleaner: keep
29+
"@rules_python//python/cc:current_py_cc_headers", # buildcleaner: keep
3030
],
3131
)
3232

@@ -42,6 +42,6 @@ cc_library(
4242
"@com_google_absl//absl/log:absl_check",
4343
"@com_google_absl//absl/log:absl_log",
4444
"@com_google_absl//absl/status",
45-
"@local_config_python//:python_headers", # buildcleaner: keep
45+
"@rules_python//python/cc:current_py_cc_headers", # buildcleaner: keep
4646
],
4747
)

pybind11_abseil/cpp_capsule_tools/BUILD

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ cc_library(
1313
"@com_google_absl//absl/status",
1414
"@com_google_absl//absl/status:statusor",
1515
"@com_google_absl//absl/strings",
16-
"@local_config_python//:python_headers", # buildcleaner: keep
16+
"@rules_python//python/cc:current_py_cc_headers", # buildcleaner: keep
1717
],
1818
)
1919

@@ -24,7 +24,7 @@ cc_library(
2424
deps = [
2525
":void_ptr_from_capsule",
2626
"@com_google_absl//absl/status:statusor",
27-
"@local_config_python//:python_headers", # buildcleaner: keep
27+
"@rules_python//python/cc:current_py_cc_headers", # buildcleaner: keep
2828
],
2929
)
3030

@@ -33,7 +33,7 @@ cc_library(
3333
hdrs = ["make_shared_ptr_capsule.h"],
3434
visibility = ["//visibility:public"],
3535
deps = [
36-
"@local_config_python//:python_headers", # buildcleaner: keep
36+
"@rules_python//python/cc:current_py_cc_headers", # buildcleaner: keep
3737
],
3838
)
3939

@@ -44,6 +44,6 @@ cc_library(
4444
deps = [
4545
":void_ptr_from_capsule",
4646
"@com_google_absl//absl/status:statusor",
47-
"@local_config_python//:python_headers", # buildcleaner: keep
47+
"@rules_python//python/cc:current_py_cc_headers", # buildcleaner: keep
4848
],
4949
)

pybind11_abseil/requirements/BUILD

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
11+
compile_pip_requirements_3_12(
12+
name = "requirements_3_12",
13+
src = "requirements.in",
14+
requirements_txt = "requirements_lock_3_12.txt",
15+
)
16+
17+
compile_pip_requirements_3_11(
18+
name = "requirements_3_11",
19+
src = "requirements.in",
20+
requirements_txt = "requirements_lock_3_11.txt",
21+
)
22+
23+
compile_pip_requirements_3_10(
24+
name = "requirements_3_10",
25+
src = "requirements.in",
26+
requirements_txt = "requirements_lock_3_10.txt",
27+
)
28+
29+
compile_pip_requirements_3_9(
30+
name = "requirements_3_9",
31+
src = "requirements.in",
32+
requirements_txt = "requirements_lock_3_9.txt",
33+
)
34+
35+
compile_pip_requirements_3_8(
36+
name = "requirements_3_8",
37+
src = "requirements.in",
38+
requirements_txt = "requirements_lock_3_8.txt",
39+
)
File renamed without changes.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.10
3+
# by the following command:
4+
#
5+
# bazel run //pybind11_abseil/requirements:requirements_3_10.update
6+
#
7+
absl-py==2.1.0 \
8+
--hash=sha256:526a04eadab8b4ee719ce68f204172ead1027549089702d99b9059f129ff1308 \
9+
--hash=sha256:7820790efbb316739cde8b4e19357243fc3608a152024288513dd968d7d959ff
10+
# via -r pybind11_abseil/requirements/requirements.in
11+
numpy==1.26.4 \
12+
--hash=sha256:03a8c78d01d9781b28a6989f6fa1bb2c4f2d51201cf99d3dd875df6fbd96b23b \
13+
--hash=sha256:08beddf13648eb95f8d867350f6a018a4be2e5ad54c8d8caed89ebca558b2818 \
14+
--hash=sha256:1af303d6b2210eb850fcf03064d364652b7120803a0b872f5211f5234b399f20 \
15+
--hash=sha256:1dda2e7b4ec9dd512f84935c5f126c8bd8b9f2fc001e9f54af255e8c5f16b0e0 \
16+
--hash=sha256:2a02aba9ed12e4ac4eb3ea9421c420301a0c6460d9830d74a9df87efa4912010 \
17+
--hash=sha256:2e4ee3380d6de9c9ec04745830fd9e2eccb3e6cf790d39d7b98ffd19b0dd754a \
18+
--hash=sha256:3373d5d70a5fe74a2c1bb6d2cfd9609ecf686d47a2d7b1d37a8f3b6bf6003aea \
19+
--hash=sha256:47711010ad8555514b434df65f7d7b076bb8261df1ca9bb78f53d3b2db02e95c \
20+
--hash=sha256:4c66707fabe114439db9068ee468c26bbdf909cac0fb58686a42a24de1760c71 \
21+
--hash=sha256:50193e430acfc1346175fcbdaa28ffec49947a06918b7b92130744e81e640110 \
22+
--hash=sha256:52b8b60467cd7dd1e9ed082188b4e6bb35aa5cdd01777621a1658910745b90be \
23+
--hash=sha256:60dedbb91afcbfdc9bc0b1f3f402804070deed7392c23eb7a7f07fa857868e8a \
24+
--hash=sha256:62b8e4b1e28009ef2846b4c7852046736bab361f7aeadeb6a5b89ebec3c7055a \
25+
--hash=sha256:666dbfb6ec68962c033a450943ded891bed2d54e6755e35e5835d63f4f6931d5 \
26+
--hash=sha256:675d61ffbfa78604709862923189bad94014bef562cc35cf61d3a07bba02a7ed \
27+
--hash=sha256:679b0076f67ecc0138fd2ede3a8fd196dddc2ad3254069bcb9faf9a79b1cebcd \
28+
--hash=sha256:7349ab0fa0c429c82442a27a9673fc802ffdb7c7775fad780226cb234965e53c \
29+
--hash=sha256:7ab55401287bfec946ced39700c053796e7cc0e3acbef09993a9ad2adba6ca6e \
30+
--hash=sha256:7e50d0a0cc3189f9cb0aeb3a6a6af18c16f59f004b866cd2be1c14b36134a4a0 \
31+
--hash=sha256:95a7476c59002f2f6c590b9b7b998306fba6a5aa646b1e22ddfeaf8f78c3a29c \
32+
--hash=sha256:96ff0b2ad353d8f990b63294c8986f1ec3cb19d749234014f4e7eb0112ceba5a \
33+
--hash=sha256:9fad7dcb1aac3c7f0584a5a8133e3a43eeb2fe127f47e3632d43d677c66c102b \
34+
--hash=sha256:9ff0f4f29c51e2803569d7a51c2304de5554655a60c5d776e35b4a41413830d0 \
35+
--hash=sha256:a354325ee03388678242a4d7ebcd08b5c727033fcff3b2f536aea978e15ee9e6 \
36+
--hash=sha256:a4abb4f9001ad2858e7ac189089c42178fcce737e4169dc61321660f1a96c7d2 \
37+
--hash=sha256:ab47dbe5cc8210f55aa58e4805fe224dac469cde56b9f731a4c098b91917159a \
38+
--hash=sha256:afedb719a9dcfc7eaf2287b839d8198e06dcd4cb5d276a3df279231138e83d30 \
39+
--hash=sha256:b3ce300f3644fb06443ee2222c2201dd3a89ea6040541412b8fa189341847218 \
40+
--hash=sha256:b97fe8060236edf3662adfc2c633f56a08ae30560c56310562cb4f95500022d5 \
41+
--hash=sha256:bfe25acf8b437eb2a8b2d49d443800a5f18508cd811fea3181723922a8a82b07 \
42+
--hash=sha256:cd25bcecc4974d09257ffcd1f098ee778f7834c3ad767fe5db785be9a4aa9cb2 \
43+
--hash=sha256:d209d8969599b27ad20994c8e41936ee0964e6da07478d6c35016bc386b66ad4 \
44+
--hash=sha256:d5241e0a80d808d70546c697135da2c613f30e28251ff8307eb72ba696945764 \
45+
--hash=sha256:edd8b5fe47dab091176d21bb6de568acdd906d1887a4584a15a9a96a1dca06ef \
46+
--hash=sha256:f870204a840a60da0b12273ef34f7051e98c3b5961b61b0c2c1be6dfd64fbcd3 \
47+
--hash=sha256:ffa75af20b44f8dba823498024771d5ac50620e6915abac414251bd971b4529f
48+
# via -r pybind11_abseil/requirements/requirements.in

0 commit comments

Comments
 (0)