Skip to content

Commit 5eb234d

Browse files
committed
feat(uv): Create a UV driver
1 parent 2dadcf0 commit 5eb234d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+11508
-146
lines changed

.bcr/patches/remove_dev_deps.patch

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
--- a/MODULE.bazel 2025-11-04 23:45:40.547616185 +0000
2-
+++ b/MODULE.bazel 2025-11-04 23:45:40.547616185 +0000
3-
@@ -24,554 +24,3 @@
4-
"@aspect_rules_py//py/private/toolchain/shim/...",
5-
)
1+
--- a/MODULE.bazel 2025-11-05 12:16:36.670092448 -0700
2+
+++ b/MODULE.bazel 2025-11-05 12:16:36.670200199 -0700
3+
@@ -46,548 +46,5 @@
4+
# HACK: In prod the includer's patch inserts the use_repo for multitool. This
5+
# solves the problem of needing a use_repo here in prod and below in dev.
66

77
-################################################################################
88
-# Dev deps
@@ -29,7 +29,7 @@
2929
-# include("//bazel/include:release.MODULE.bazel")
3030
-# include("//bazel/include:multitool.MODULE.bazel")
3131
-# include("//bazel/include:tools.MODULE.bazel")
32-
-
32+
3333
-################################################################################
3434
-# Begin included content
3535
-
@@ -169,14 +169,7 @@
169169
-# from bazel/include/rust.MODULE.bazel
170170
-# Rust configuration
171171
-
172-
-bazel_dep(name = "rules_rust", version = "0.66.0")
173-
-single_version_override(
174-
- module_name = "rules_rust",
175-
- patch_strip = 1,
176-
- patches = [
177-
- "//bazel/patches:rules_rust.patch",
178-
- ],
179-
-)
172+
-bazel_dep(name = "rules_rust", version = "0.67.0")
180173
-
181174
-bazel_dep(name = "openssl", version = "3.3.1.bcr.6")
182175
-
@@ -543,11 +536,12 @@
543536
-# from bazel/include/multitool.MODULE.bazel
544537
-# Multitool configuration
545538
-
546-
-bazel_dep(name = "rules_multitool", version = "1.9.0")
539+
-# Multitool is a prod dep (for now) so we don't need this
540+
-# bazel_dep(name = "rules_multitool", version = "1.9.0")
541+
-# multitool = use_extension("@rules_multitool//multitool:extension.bzl", "multitool")
547542
-
548-
-multitool = use_extension("@rules_multitool//multitool:extension.bzl", "multitool")
549543
-multitool.hub(lockfile = "//tools:tools.lock.json")
550-
-use_repo(multitool, "multitool")
544+
use_repo(multitool, "multitool")
551545
-
552546
-########################################
553547
-# from bazel/include/tools.MODULE.bazel

MODULE.bazel

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ bazel_dep(name = "bazel_skylib", version = "1.4.2")
1212
bazel_dep(name = "platforms", version = "1.0.0")
1313
bazel_dep(name = "rules_python", version = "1.0.0")
1414

15+
# FIXME: We're using this to pull in multitool for source builds. Could use an
16+
# internal tool instead.
17+
bazel_dep(name = "rules_multitool", version = "1.9.0")
18+
1519
tools = use_extension("//py:extensions.bzl", "py_tools")
1620
tools.rules_py_tools()
1721
use_repo(tools, "rules_py_tools")
@@ -24,6 +28,24 @@ register_toolchains(
2428
"@aspect_rules_py//py/private/toolchain/shim/...",
2529
)
2630

31+
toml = use_extension("//uv/private/tomltool:extension.bzl", "tomltool")
32+
use_repo(
33+
toml,
34+
"toml2json_aarch64_linux_gnu",
35+
"toml2json_aarch64_osx_libsystem",
36+
"toml2json_x86_64_linux_gnu",
37+
"toml2json_x86_64_osx_libsystem",
38+
)
39+
40+
host = use_extension("//uv/private/host:extension.bzl", "host_platform")
41+
use_repo(host, "aspect_rules_py_uv_host")
42+
43+
multitool = use_extension("@rules_multitool//multitool:extension.bzl", "multitool")
44+
multitool.hub(lockfile = "//uv/private/uv:uv.lock.json")
45+
46+
# HACK: In prod the includer's patch inserts the use_repo for multitool. This
47+
# solves the problem of needing a use_repo here in prod and below in dev.
48+
2749
################################################################################
2850
# Dev deps
2951
#
@@ -189,14 +211,7 @@ platforms = [
189211
# from bazel/include/rust.MODULE.bazel
190212
# Rust configuration
191213

192-
bazel_dep(name = "rules_rust", version = "0.66.0")
193-
single_version_override(
194-
module_name = "rules_rust",
195-
patch_strip = 1,
196-
patches = [
197-
"//bazel/patches:rules_rust.patch",
198-
],
199-
)
214+
bazel_dep(name = "rules_rust", version = "0.67.0")
200215

201216
bazel_dep(name = "openssl", version = "3.3.1.bcr.6")
202217

@@ -563,9 +578,10 @@ bazel_dep(name = "rules_pkg", version = "1.1.0")
563578
# from bazel/include/multitool.MODULE.bazel
564579
# Multitool configuration
565580

566-
bazel_dep(name = "rules_multitool", version = "1.9.0")
581+
# Multitool is a prod dep (for now) so we don't need this
582+
# bazel_dep(name = "rules_multitool", version = "1.9.0")
583+
# multitool = use_extension("@rules_multitool//multitool:extension.bzl", "multitool")
567584

568-
multitool = use_extension("@rules_multitool//multitool:extension.bzl", "multitool")
569585
multitool.hub(lockfile = "//tools:tools.lock.json")
570586
use_repo(multitool, "multitool")
571587

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Multitool configuration
22

3-
bazel_dep(name = "rules_multitool", version = "1.9.0")
3+
# Multitool is a prod dep (for now) so we don't need this
4+
# bazel_dep(name = "rules_multitool", version = "1.9.0")
5+
# multitool = use_extension("@rules_multitool//multitool:extension.bzl", "multitool")
46

5-
multitool = use_extension("@rules_multitool//multitool:extension.bzl", "multitool")
67
multitool.hub(lockfile = "//tools:tools.lock.json")
78
use_repo(multitool, "multitool")

bazel/include/rust.MODULE.bazel

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
# Rust configuration
22

3-
bazel_dep(name = "rules_rust", version = "0.66.0")
4-
single_version_override(
5-
module_name = "rules_rust",
6-
patch_strip = 1,
7-
patches = [
8-
"//bazel/patches:rules_rust.patch",
9-
],
10-
)
3+
bazel_dep(name = "rules_rust", version = "0.67.0")
114

125
bazel_dep(name = "openssl", version = "3.3.1.bcr.6")
136

bazel/patches/rules_rust.patch

Lines changed: 0 additions & 17 deletions
This file was deleted.

e2e/MODULE.bazel

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"Bazel dependencies"
22

33
include("//bazel/include:e2e.MODULE.bazel")
4+
include("//bazel/include:oci.MODULE.bazel")
45

56
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
67
python.toolchain(
@@ -68,3 +69,40 @@ local_repository(
6869
# For cases/repository-rule-deps-299
6970
importer = use_extension("//cases/repository-rule-deps-299/rules:import.bzl", "importer")
7071
use_repo(importer, "myrepo")
72+
73+
# For cases/uv-deps-650
74+
uv = use_extension("@aspect_rules_py//uv:extension.bzl", "uv")
75+
uv.declare_hub(hub_name = "pypi")
76+
uv.declare_venv(
77+
hub_name = "pypi",
78+
venv_name = "default",
79+
)
80+
uv.lockfile(
81+
hub_name = "pypi",
82+
lockfile = "//cases/uv-deps-650:uv-default.lock",
83+
venv_name = "default",
84+
)
85+
uv.declare_venv(
86+
hub_name = "pypi",
87+
venv_name = "airflow",
88+
)
89+
uv.lockfile(
90+
hub_name = "pypi",
91+
lockfile = "//cases/uv-deps-650:uv-airflow.lock",
92+
venv_name = "airflow",
93+
)
94+
uv.declare_venv(
95+
hub_name = "pypi",
96+
venv_name = "psql",
97+
)
98+
uv.lockfile(
99+
hub_name = "pypi",
100+
lockfile = "//cases/uv-deps-650:uv-psql.lock",
101+
venv_name = "psql",
102+
)
103+
104+
# Ask uv to make entrypoints for setuptools
105+
uv.discover_entrypoints(
106+
requirement = "setuptools",
107+
)
108+
use_repo(uv, "pypi")

e2e/cases/uv-deps-650/BUILD.bazel

Whitespace-only changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
load("@aspect_rules_py//py/unstable:defs.bzl", "py_venv_test")
2+
3+
py_venv_test(
4+
name = "airflow",
5+
srcs = [
6+
"__test__.py",
7+
],
8+
main = "__test__.py",
9+
python_version = "3.13",
10+
venv = "airflow",
11+
deps = [
12+
"@pypi//apache_airflow",
13+
],
14+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env python3
2+
3+
# TODO: Deprecated API, need an alternative
4+
import pkgutil
5+
assert "cases/uv-deps-650/airflow/.airflow/" in pkgutil.get_loader("airflow").get_filename()
6+
7+
import sys
8+
assert sys.version_info.major == 3
9+
assert sys.version_info.minor == 13
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")
2+
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load", "oci_image_index")
3+
load("@aspect_rules_py//py:defs.bzl", "py_image_layer")
4+
load("@aspect_rules_py//py/unstable:defs.bzl", "py_venv_binary")
5+
load("@container_structure_test//:defs.bzl", "container_structure_test")
6+
load("@aspect_rules_py//py/tests/py_image_layer:asserts.bzl", "assert_tar_listing")
7+
8+
platform(
9+
name = "arm64_linux",
10+
constraint_values = [
11+
"@platforms//os:linux",
12+
"@platforms//cpu:aarch64",
13+
],
14+
flags = [
15+
"--@aspect_rules_py//uv/private/constraints/platform:platform_libc=glibc",
16+
"--@aspect_rules_py//uv/private/constraints/platform:platform_version=2.39",
17+
"--@rules_rust//:extra_rustc_flag=-Cstrip=debuginfo",
18+
"--@rules_rust//rust/settings:lto=fat",
19+
"--stripopt=--strip-all",
20+
],
21+
)
22+
23+
platform(
24+
name = "amd64_linux",
25+
constraint_values = [
26+
"@platforms//os:linux",
27+
"@platforms//cpu:x86_64",
28+
],
29+
flags = [
30+
"--@aspect_rules_py//uv/private/constraints/platform:platform_libc=glibc",
31+
"--@aspect_rules_py//uv/private/constraints/platform:platform_version=2.39",
32+
"--@rules_rust//:extra_rustc_flag=-Cstrip=debuginfo",
33+
"--@rules_rust//rust/settings:lto=fat",
34+
"--stripopt=--strip-all",
35+
],
36+
)
37+
38+
py_venv_binary(
39+
name = "app_bin",
40+
srcs = ["__main__.py"],
41+
main = "__main__.py",
42+
deps = [
43+
"@pypi//psycopg2_binary",
44+
],
45+
python_version = "3.12",
46+
venv = "psql",
47+
)
48+
49+
py_image_layer(
50+
name = "app_layers",
51+
binary = ":app_bin",
52+
)
53+
54+
platform_transition_filegroup(
55+
name = "amd64_layers",
56+
srcs = [":app_layers"],
57+
target_platform = ":amd64_linux",
58+
)
59+
60+
assert_tar_listing(
61+
name = "app_amd64_layers",
62+
actual = [":amd64_layers"],
63+
expected = ":app_amd64_layers_listing.yaml",
64+
)
65+
66+
platform_transition_filegroup(
67+
name = "arm64_layers",
68+
srcs = [":app_layers"],
69+
target_platform = ":arm64_linux",
70+
)
71+
72+
assert_tar_listing(
73+
name = "app_arm64_layers",
74+
actual = [":arm64_layers"],
75+
expected = ":app_arm64_layers_listing.yaml",
76+
)
77+
78+
oci_image(
79+
name = "image",
80+
# This is defined by an oci.pull() call in /MODULE.bazel
81+
base = "@ubuntu",
82+
entrypoint = ["/{}/app_bin".format(package_name())],
83+
tars = [":app_layers"],
84+
)
85+
86+
platform_transition_filegroup(
87+
name = "amd64_image",
88+
srcs = [":image"],
89+
target_platform = ":amd64_linux",
90+
)
91+
92+
platform_transition_filegroup(
93+
name = "arm64_image",
94+
srcs = [":image"],
95+
target_platform = ":arm64_linux",
96+
)
97+
98+
oci_image_index(
99+
name = "image_index",
100+
images = [
101+
":arm64_image",
102+
":amd64_image",
103+
],
104+
)

0 commit comments

Comments
 (0)