Repository navigation
Expand file tree
/
Copy pathMODULE.bazel
More file actions
525 lines (483 loc) · 15.9 KB
/
Copy pathMODULE.bazel
File metadata and controls
525 lines (483 loc) · 15.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
module(
name = "rules_python",
version = "0.0.0",
compatibility_level = 1,
)
bazel_dep(name = "bazel_features", version = "1.21.0")
bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "package_metadata", version = "0.0.7")
bazel_dep(name = "platforms", version = "0.0.11")
bazel_dep(name = "rules_cc", version = "0.2.17")
bazel_dep(name = "toml.bzl", version = "0.4.1")
# Those are loaded only when using py_proto_library
# Use py_proto_library directly from protobuf repository
bazel_dep(name = "protobuf", version = "29.0-rc2", repo_name = "com_google_protobuf")
rules_python_config = use_extension("//python/extensions:config.bzl", "config")
use_repo(
rules_python_config,
"pypi__build",
"pypi__click",
"pypi__colorama",
"pypi__importlib_metadata",
"pypi__installer",
"pypi__more_itertools",
"pypi__packaging",
"pypi__pep517",
"pypi__pip",
"pypi__pip_tools",
"pypi__pyproject_hooks",
"pypi__setuptools",
"pypi__tomli",
"pypi__wheel",
"pypi__zipp",
"rules_python_internal",
)
# We need to do another use_extension call to expose the "pythons_hub"
# repo.
python = use_extension("//python/extensions:python.bzl", "python")
# The default toolchain to use if nobody configures a toolchain.
# NOTE: This is not a stable version. It is provided for convenience, but will
# change frequently to track the most recent Python version.
# NOTE: The root module can override this.
# NOTE: There must be a corresponding `python.toolchain()` call for the version
# specified here.
python.defaults(
python_version = "3.14",
)
python.toolchain(
python_version = "3.14",
)
use_repo(
python,
"python_3_14",
"pythons_hub",
python = "python_versions",
)
# This call registers the Python toolchains.
register_toolchains("@pythons_hub//:all")
#####################
# Install twine for our own runfiles wheel publishing and allow bzlmod users to use it.
pip = use_extension("//python/extensions:pip.bzl", "pip")
pip.parse(
hub_name = "rules_python_publish_deps",
python_version = "3.14",
requirements_by_platform = {
"//tools/publish:requirements_darwin.txt": "osx_*",
"//tools/publish:requirements_linux.txt": "linux_*",
"//tools/publish:requirements_windows.txt": "windows_*",
},
target_platforms = [
"linux_aarch64",
"linux_x86_64",
"osx_aarch64",
"osx_x86_64",
"windows_aarch64",
"windows_x86_64",
],
)
pip.dep(name = "pytest")
pip.dep(name = "pytest-bazel")
pip.dep(name = "pytest-randomly")
pip.dep(name = "pytest-shard")
use_repo(pip, "pypi", "rules_python_publish_deps")
# ===== DEV ONLY DEPS AND SETUP BELOW HERE =====
bazel_dep(name = "sphinxdocs", version = "0.0.0", dev_dependency = True)
local_path_override(
module_name = "sphinxdocs",
path = "sphinxdocs",
)
bazel_dep(name = "rules_bazel_integration_test", version = "0.27.0", dev_dependency = True)
bazel_dep(name = "rules_testing", version = "0.6.0", dev_dependency = True)
bazel_dep(name = "rules_shell", version = "0.3.0", dev_dependency = True)
bazel_dep(name = "rules_multirun", version = "0.9.0", dev_dependency = True)
bazel_dep(name = "bazel_ci_rules", version = "1.0.0", dev_dependency = True)
bazel_dep(name = "rules_pkg", version = "1.2.0", dev_dependency = True)
bazel_dep(name = "rules_rust", version = "0.73.0", dev_dependency = True)
rust_crates = use_extension(
"@rules_rust//crate_universe:extensions.bzl",
"crate",
dev_dependency = True,
)
rust_crates.spec(
package = "sha2",
version = "0.10.8",
)
# The crates must build for every platform in dev/platforms. Conditional
# dependencies are resolved for these triples; rules_rust matches them by CPU
# and OS, e.g. i686-unknown-linux-gnu also matches the i686-unknown-linux-musl
# platform.
rust_crates.from_specs(
supported_platform_triples = [
"aarch64-apple-darwin",
"aarch64-pc-windows-msvc",
"aarch64-unknown-linux-gnu",
"armv7-unknown-linux-gnueabi",
"i686-pc-windows-msvc",
"i686-unknown-linux-gnu",
"riscv64gc-unknown-linux-gnu",
"x86_64-apple-darwin",
"x86_64-pc-windows-msvc",
"x86_64-unknown-linux-gnu",
],
)
# rules_rust has no @rules_rust//rust/platform config_setting for Linux ppc64le,
# so don't mark the crates as incompatible with platforms that don't match one
# of the triples above. Such platforms get only the unconditional dependencies,
# which suffice for sha2.
rust_crates.render_config(
generate_target_compatible_with = False,
)
use_repo(rust_crates, "crates")
# Rust toolchains to cross-compile the release artifacts for other Linux CPUs
# from Linux x86_64; see dev/release_artifacts. They target musl, which Rust can
# link statically with its bundled rust-lld, so no C cross toolchain is needed.
rust = use_extension(
"@rules_rust//rust:extensions.bzl",
"rust",
dev_dependency = True,
)
rust.repository_set(
# rules_rust also registers an x86_64 to x86_64 toolchain from this set, in
# name order with its default ones, so the name must sort after
# rust_linux_x86_64 for the default x86_64 toolchain to take precedence.
name = "rust_release_linux",
# The default allocator library needs a C toolchain for the target platform,
# but there isn't one. This one is what rules_rust uses for e.g. Windows.
allocator_library = "@rules_rust//rust/private/cc:empty",
edition = "2021",
exec_triple = "x86_64-unknown-linux-gnu",
target_compatible_with = [
"@platforms//cpu:aarch64",
"@platforms//os:linux",
"//dev/platforms:musl",
],
target_triple = "aarch64-unknown-linux-musl",
# rules_rust 0.73.0's default version; update it with rules_rust. The
# default toolchain builds proc-macros, which rustc only loads if they were
# built by the same version.
versions = ["1.97.1"],
)
# Other targets for the same set; the first tag sets the shared attributes.
rust.repository_set(
name = "rust_release_linux",
target_compatible_with = [
"@platforms//cpu:armv7",
"@platforms//os:linux",
"//dev/platforms:musl",
],
target_triple = "armv7-unknown-linux-musleabihf",
)
rust.repository_set(
name = "rust_release_linux",
target_compatible_with = [
"@platforms//cpu:x86_32",
"@platforms//os:linux",
"//dev/platforms:musl",
],
target_triple = "i686-unknown-linux-musl",
)
rust.repository_set(
name = "rust_release_linux",
target_compatible_with = [
"@platforms//cpu:ppc64le",
"@platforms//os:linux",
"//dev/platforms:musl",
],
target_triple = "powerpc64le-unknown-linux-musl",
)
rust.repository_set(
name = "rust_release_linux",
target_compatible_with = [
"@platforms//cpu:riscv64",
"@platforms//os:linux",
"//dev/platforms:musl",
],
target_triple = "riscv64gc-unknown-linux-musl",
)
use_repo(
rust,
"rust_release_linux__aarch64-unknown-linux-musl__stable",
"rust_release_linux__armv7-unknown-linux-musleabihf__stable",
"rust_release_linux__i686-unknown-linux-musl__stable",
"rust_release_linux__powerpc64le-unknown-linux-musl__stable",
"rust_release_linux__riscv64gc-unknown-linux-musl__stable",
)
# Registered here so that they take precedence over rules_rust's default
# toolchains, e.g. its Linux x86_64 to aarch64 one also matches the aarch64
# musl platform.
register_toolchains(
"@rust_release_linux__aarch64-unknown-linux-musl__stable//:toolchain",
"@rust_release_linux__armv7-unknown-linux-musleabihf__stable//:toolchain",
"@rust_release_linux__i686-unknown-linux-musl__stable//:toolchain",
"@rust_release_linux__powerpc64le-unknown-linux-musl__stable//:toolchain",
"@rust_release_linux__riscv64gc-unknown-linux-musl__stable//:toolchain",
dev_dependency = True,
)
# A Rust toolchain to cross-compile the release artifacts for 32-bit Windows
# from Windows x86_64, with MSVC's x86 tools. Unlike the Linux ones, it isn't
# registered here: no default toolchain targets 32-bit Windows, and rules_rust
# registers it.
rust.repository_set(
# As above, its x86_64 toolchain's name must sort after the default one's.
# On Windows, rules_rust names toolchains after a hash of the full name:
# rw-1886791612 for this one, after rust_windows_x86_64's rw-1704990954.
name = "rust_release_windows",
edition = "2021",
exec_triple = "x86_64-pc-windows-msvc",
target_compatible_with = [
"@platforms//cpu:x86_32",
"@platforms//os:windows",
],
target_triple = "i686-pc-windows-msvc",
# See above.
versions = ["1.97.1"],
)
# Use the Rust-based build tools when developing rules_python itself.
register_toolchains(
"//dev/dev_only_toolchains:exe_zip_maker_toolchain",
dev_dependency = True,
)
bazel_dep(name = "other", version = "0", dev_dependency = True)
bazel_dep(name = "another_module", version = "0", dev_dependency = True)
# Extra gazelle plugin deps so that WORKSPACE.bzlmod can continue including it for e2e tests.
# We use `WORKSPACE.bzlmod` because it is impossible to have dev-only local overrides.
bazel_dep(name = "rules_go", version = "0.60.0", dev_dependency = True, repo_name = "io_bazel_rules_go")
bazel_dep(name = "gazelle", version = "0.40.0", dev_dependency = True, repo_name = "bazel_gazelle")
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.8.2", dev_dependency = True)
bazel_dep(name = "rules_pyrefly", version = "0.1.0", dev_dependency = True)
pyrefly = use_extension(
"@rules_pyrefly//pyrefly:extensions.bzl",
"pyrefly",
dev_dependency = True,
)
pyrefly.toolchain(version = "1.2.0")
use_repo(pyrefly, "pyrefly_toolchains")
register_toolchains(
"@pyrefly_toolchains//:all",
dev_dependency = True,
)
internal_dev_deps = use_extension(
"//python/private:internal_dev_deps.bzl",
"internal_dev_deps",
dev_dependency = True,
)
use_repo(
internal_dev_deps,
"buildkite_config",
"implicit_namespace_ns_sub1",
"implicit_namespace_ns_sub2",
"patch_whl_pkg",
"pkgutil_nspkg1",
"pkgutil_nspkg2",
"rules_python_runtime_env_tc_info",
"somepkg_with_build_files",
"whl_library_extras_direct_dep",
"whl_with_build_files",
"whl_with_data1",
"whl_with_data2",
)
dev_rules_python_config = use_extension(
"//python/extensions:config.bzl",
"config",
dev_dependency = True,
)
dev_rules_python_config.add_transition_setting(
# Intentionally add a setting already present for testing
setting = "//python/config_settings:python_version",
)
dev_rules_python_config.add_transition_setting(
setting = "//tests/multi_pypi:external_deps_name",
)
local_path_override(
module_name = "other",
path = "tests/modules/other",
)
local_path_override(
module_name = "another_module",
path = "tests/modules/another_module",
)
dev_python = use_extension(
"//python/extensions:python.bzl",
"python",
dev_dependency = True,
)
dev_python.override(
register_all_versions = True,
)
# For testing an arbitrary runtime triggered by a custom flag.
# See //tests/toolchains:custom_platform_toolchain_test
dev_python.single_version_platform_override(
platform = "linux-x86-install-only-stripped",
python_version = "3.13.1",
sha256 = "56817aa976e4886bec1677699c136cb01c1cdfe0495104c0d8ef546541864bbb",
target_compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
target_settings = [
"@@//tests/support:is_custom_runtime_linux-x86-install-only-stripped",
],
urls = ["https://github.com/astral-sh/python-build-standalone/releases/download/20250115/cpython-3.13.1+20250115-x86_64-unknown-linux-gnu-install_only_stripped.tar.gz"],
)
dev_pip = use_extension(
"//python/extensions:pip.bzl",
"pip",
dev_dependency = True,
)
[
dev_pip.parse(
download_only = True,
hub_name = "dev_pip",
parallel_download = False,
python_version = python_version,
# Ensure that we are setting up the following platforms
target_platforms = [
"{os}_{arch}",
"{os}_{arch}_freethreaded",
],
uv_lock = "//dev:uv.lock",
)
for python_version in [
"3.10",
"3.11",
"3.12",
"3.13",
"3.14",
]
]
dev_pip.parse(
download_only = True,
hub_name = "pypiserver",
python_version = "3.14",
requirements_lock = "//examples/wheel:requirements_server.txt",
)
dev_pip.parse(
hub_name = "pypi_alpha",
python_version = "3.14",
requirements_lock = "//tests/multi_pypi/alpha:requirements.txt",
)
dev_pip.parse(
hub_name = "pypi_beta",
python_version = "3.14",
requirements_lock = "//tests/multi_pypi/beta:requirements.txt",
)
use_repo(dev_pip, "dev_pip", "pypi_alpha", "pypi_beta", "pypiserver")
# Bazel integration test setup below
bazel_binaries = use_extension(
"@rules_bazel_integration_test//:extensions.bzl",
"bazel_binaries",
dev_dependency = True,
)
# Keep in sync with //:version.bzl
bazel_binaries.local(
name = "self",
path = "tests/integration/bazel_from_env",
)
bazel_binaries.download(version = "7.7.0")
bazel_binaries.download(version = "8.5.1")
bazel_binaries.download(version = "9.1.0")
use_repo(
bazel_binaries,
"bazel_binaries",
# These don't appear necessary, but are reported as direct dependencies
# that should be use_repo()'d, so we add them as requested
"bazel_binaries_bazelisk",
"build_bazel_bazel_7_7_0",
"build_bazel_bazel_8_5_1",
"build_bazel_bazel_9_1_0",
# "build_bazel_bazel_rolling",
"build_bazel_bazel_self",
)
# TODO @aignas 2025-01-27: should this be moved to `//python/extensions:uv.bzl` or should
# it stay as it is? I think I may prefer to move it.
uv = use_extension("//python/uv:uv.bzl", "uv")
# Here is how we can define platforms for the `uv` binaries - this will affect
# all of the downstream callers because we are using the extension without
# `dev_dependency = True`.
uv.default(
base_url = "https://github.com/astral-sh/uv/releases/download",
manifest_filename = "dist-manifest.json",
version = "0.11.2",
)
uv.default(
compatible_with = [
"@platforms//os:macos",
"@platforms//cpu:aarch64",
],
platform = "aarch64-apple-darwin",
)
uv.default(
compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:aarch64",
],
platform = "aarch64-unknown-linux-gnu",
)
uv.default(
compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:ppc64le",
],
platform = "powerpc64le-unknown-linux-gnu",
)
uv.default(
compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:s390x",
],
platform = "s390x-unknown-linux-gnu",
)
uv.default(
compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:riscv64",
],
platform = "riscv64-unknown-linux-gnu",
)
uv.default(
compatible_with = [
"@platforms//os:macos",
"@platforms//cpu:x86_64",
],
platform = "x86_64-apple-darwin",
)
uv.default(
compatible_with = [
"@platforms//os:windows",
"@platforms//cpu:x86_64",
],
platform = "x86_64-pc-windows-msvc",
)
uv.default(
compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
platform = "x86_64-unknown-linux-gnu",
)
use_repo(uv, "uv")
register_toolchains("@uv//:all")
uv_dev = use_extension(
"//python/uv:uv.bzl",
"uv",
dev_dependency = True,
)
uv_dev.configure(
version = "0.11.2",
)
flag_alias(
name = "build_python_zip",
starlark_flag = "//python/config_settings:build_python_zip",
)
flag_alias(
name = "incompatible_default_to_explicit_init_py",
starlark_flag = "//python/config_settings:incompatible_default_to_explicit_init_py",
)
flag_alias(
name = "python_path",
starlark_flag = "//python/config_settings:python_path",
)
flag_alias(
name = "experimental_python_import_all_repositories",
starlark_flag = "//python/config_settings:experimental_python_import_all_repositories",
)