Skip to content

Commit ca62068

Browse files
author
Matt Mackay
authored
feat: drop rattler_installs_packages for uv crates (#412)
Drops the dependency on `rattler_installs_packages` in favour of the uv crates. Note that while this works, the creates of uv do not officially support depending directly on the crates, however there is little overhead here, and is pinned to a fixed SHA. Closes #307 Closes #344 Closes #345 Due to compilation issues under llvm, this diff also switches to musl for the toolchain binaries. We need to keep llvm for proc macros, unfortunately. --- ### Changes are visible to end-users: yes - Searched for relevant documentation and updated as needed: yes - Breaking change (forces users to change their own code or config): no - Suggested release notes appear below: yes Drop dependency on `rattler_installs_packages` in favour of the uv crates. Produce statically linked toolchain binaries via musl. ### Test plan - New test cases added
1 parent 284162a commit ca62068

File tree

28 files changed

+13312
-7417
lines changed

28 files changed

+13312
-7417
lines changed

Cargo.Bazel.lock

Lines changed: 11202 additions & 6207 deletions
Large diffs are not rendered by default.

Cargo.lock

Lines changed: 1719 additions & 1008 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,22 @@ readme = "README.md"
1717
rust-version = "1.81.0"
1818

1919
[workspace.dependencies]
20+
clap = { version = "4.5.20", features = ["derive"] }
21+
itertools = "0.13.0"
2022
miette = { version = "7.2", features = ["fancy"] }
23+
tempfile = "3.13.0"
24+
thiserror = "1.0.64"
25+
uv-cache = { git = "https://github.com/astral-sh/uv", rev = "855c1917e1e0e2b48c38de71bebc845af016afae" }
26+
uv-distribution-filename = { git = "https://github.com/astral-sh/uv.git", rev = "855c1917e1e0e2b48c38de71bebc845af016afae" }
27+
uv-extract = { git = "https://github.com/astral-sh/uv.git", rev = "855c1917e1e0e2b48c38de71bebc845af016afae" }
28+
uv-install-wheel = { git = "https://github.com/astral-sh/uv", rev = "855c1917e1e0e2b48c38de71bebc845af016afae" }
29+
uv-pypi-types = { git = "https://github.com/astral-sh/uv.git", rev = "855c1917e1e0e2b48c38de71bebc845af016afae" }
30+
uv-python = { git = "https://github.com/astral-sh/uv", rev = "855c1917e1e0e2b48c38de71bebc845af016afae" }
31+
uv-virtualenv = { git = "https://github.com/astral-sh/uv", rev = "855c1917e1e0e2b48c38de71bebc845af016afae" }
32+
33+
[patch.crates-io]
34+
reqwest-middleware = { git = "https://github.com/astral-sh/reqwest-middleware", rev = "5e3eaf254b5bd481c75d2710eed055f95b756913", features = ["multipart"] }
35+
reqwest-retry = { git = "https://github.com/astral-sh/reqwest-middleware", rev = "5e3eaf254b5bd481c75d2710eed055f95b756913" }
2136

2237
[profile.release]
2338
strip = true

WORKSPACE

Lines changed: 111 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ load("@aspect_bazel_lib//lib:repositories.bzl", "register_coreutils_toolchains")
4949

5050
register_coreutils_toolchains()
5151

52+
load("@musl_toolchains//:repositories.bzl", "load_musl_toolchains")
53+
54+
load_musl_toolchains(extra_target_compatible_with = ["@//tools/linkers:musl"])
55+
56+
load("@musl_toolchains//:toolchains.bzl", "register_musl_toolchains")
57+
58+
register_musl_toolchains()
59+
5260
############################################
5361
## CC toolchain using llvm
5462
load("@toolchains_llvm//toolchain:deps.bzl", "bazel_toolchain_dependencies")
@@ -156,34 +164,123 @@ RUST_EDITION = "2021"
156164

157165
RUST_VERSION = "1.81.0"
158166

159-
rust_register_toolchains(
167+
# Declare cross-compilation toolchains
168+
rust_repository_set(
169+
name = "apple_darwin_aarch64",
160170
edition = RUST_EDITION,
161-
extra_target_triples = [
162-
"x86_64-apple-darwin",
163-
],
171+
exec_triple = "aarch64-apple-darwin",
172+
# and cross-compile to these platforms:
173+
extra_target_triples = {
174+
"aarch64-apple-darwin": [
175+
"@platforms//cpu:arm64",
176+
"@platforms//os:macos",
177+
],
178+
"aarch64-unknown-linux-musl": [
179+
"@platforms//cpu:arm64",
180+
"@platforms//os:linux",
181+
"@//tools/linkers:musl",
182+
],
183+
"x86_64-apple-darwin": [
184+
"@platforms//cpu:x86_64",
185+
"@platforms//os:macos",
186+
],
187+
"x86_64-unknown-linux-musl": [
188+
"@platforms//cpu:x86_64",
189+
"@platforms//os:linux",
190+
"@//tools/linkers:musl",
191+
],
192+
},
164193
versions = [RUST_VERSION],
165194
)
166195

167-
# Declare cross-compilation toolchains
168196
rust_repository_set(
169-
name = "apple_darwin_86_64",
197+
name = "apple_darwin_x86_64",
170198
edition = RUST_EDITION,
171199
exec_triple = "x86_64-apple-darwin",
172200
# and cross-compile to these platforms:
173-
extra_target_triples = [
174-
"aarch64-apple-darwin",
175-
],
201+
extra_target_triples = {
202+
"aarch64-apple-darwin": [
203+
"@platforms//cpu:arm64",
204+
"@platforms//os:macos",
205+
],
206+
"aarch64-unknown-linux-musl": [
207+
"@platforms//cpu:arm64",
208+
"@platforms//os:linux",
209+
"@//tools/linkers:musl",
210+
],
211+
"x86_64-apple-darwin": [
212+
"@platforms//cpu:x86_64",
213+
"@platforms//os:macos",
214+
],
215+
"x86_64-unknown-linux-musl": [
216+
"@platforms//cpu:x86_64",
217+
"@platforms//os:linux",
218+
"@//tools/linkers:musl",
219+
],
220+
},
176221
versions = [RUST_VERSION],
177222
)
178223

179224
rust_repository_set(
180-
name = "linux_x86_64",
225+
name = "rust_linux_x86_64",
181226
edition = RUST_EDITION,
182227
exec_triple = "x86_64-unknown-linux-gnu",
183-
# and cross-compile to these platforms:
184-
extra_target_triples = [
185-
"aarch64-unknown-linux-gnu",
186-
],
228+
extra_target_triples = {
229+
"aarch64-unknown-linux-gnu": [
230+
"@platforms//cpu:arm64",
231+
"@platforms//os:linux",
232+
"@//tools/linkers:unknown",
233+
],
234+
"aarch64-unknown-linux-musl": [
235+
"@platforms//cpu:arm64",
236+
"@platforms//os:linux",
237+
"@//tools/linkers:musl",
238+
],
239+
"x86_64-unknown-linux-gnu": [
240+
"@platforms//cpu:x86_64",
241+
"@platforms//os:linux",
242+
"@//tools/linkers:unknown",
243+
],
244+
"x86_64-unknown-linux-musl": [
245+
"@platforms//cpu:x86_64",
246+
"@platforms//os:linux",
247+
"@//tools/linkers:musl",
248+
],
249+
},
250+
versions = [RUST_VERSION],
251+
)
252+
253+
rust_repository_set(
254+
name = "rust_linux_aarch64",
255+
edition = RUST_EDITION,
256+
exec_triple = "aarch64-unknown-linux-gnu",
257+
extra_target_triples = {
258+
"aarch64-unknown-linux-gnu": [
259+
"@platforms//cpu:arm64",
260+
"@platforms//os:linux",
261+
"@//tools/linkers:unknown",
262+
],
263+
"aarch64-unknown-linux-musl": [
264+
"@platforms//cpu:arm64",
265+
"@platforms//os:linux",
266+
"@//tools/linkers:musl",
267+
],
268+
"x86_64-unknown-linux-gnu": [
269+
"@platforms//cpu:x86_64",
270+
"@platforms//os:linux",
271+
"@//tools/linkers:unknown",
272+
],
273+
"x86_64-unknown-linux-musl": [
274+
"@platforms//cpu:x86_64",
275+
"@platforms//os:linux",
276+
"@//tools/linkers:musl",
277+
],
278+
},
279+
versions = [RUST_VERSION],
280+
)
281+
282+
rust_register_toolchains(
283+
edition = RUST_EDITION,
187284
versions = [RUST_VERSION],
188285
)
189286

py/private/py_binary.bzl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ def _py_binary_rule_impl(ctx):
7373
"{{ARG_COLLISION_STRATEGY}}": ctx.attr.package_collisions,
7474
"{{ARG_PYTHON}}": to_rlocation_path(ctx, py_toolchain.python) if py_toolchain.runfiles_interpreter else py_toolchain.python.path,
7575
"{{ARG_VENV_NAME}}": ".{}.venv".format(ctx.attr.name),
76-
"{{ARG_VENV_PYTHON_VERSION}}": "{}.{}.{}".format(
77-
py_toolchain.interpreter_version_info.major,
78-
py_toolchain.interpreter_version_info.minor,
79-
py_toolchain.interpreter_version_info.micro,
80-
),
8176
"{{ARG_PTH_FILE}}": to_rlocation_path(ctx, site_packages_pth_file),
8277
"{{ENTRYPOINT}}": to_rlocation_path(ctx, ctx.file.main),
8378
"{{PYTHON_ENV}}": "\n".join(_dict_to_exports(env)).strip(),

py/private/py_unpacked_wheel.bzl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,12 @@ def _py_unpacked_wheel_impl(ctx):
1818
unpack_directory.path,
1919
"--wheel",
2020
ctx.file.src.path,
21-
"--python",
22-
py_toolchain.python,
2321
"--python-version",
2422
"{}.{}.{}".format(
2523
py_toolchain.interpreter_version_info.major,
2624
py_toolchain.interpreter_version_info.minor,
2725
py_toolchain.interpreter_version_info.micro,
2826
),
29-
"--package-name",
30-
ctx.attr.py_package_name,
3127
])
3228

3329
ctx.actions.run(
@@ -72,9 +68,6 @@ _attrs = {
7268
allow_single_file = [".whl"],
7369
mandatory = True,
7470
),
75-
"py_package_name": attr.string(
76-
mandatory = True,
77-
),
7871
# NB: this is read by _resolve_toolchain in py_semantics.
7972
"_interpreter_version_flag": attr.label(
8073
default = "//py:interpreter_version",

py/private/py_venv.bzl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@ def _py_venv_rule_imp(ctx):
5454
"{{ARG_PYTHON}}": to_rlocation_path(ctx, py_toolchain.python) if py_toolchain.runfiles_interpreter else py_toolchain.python.path,
5555
"{{ARG_COLLISION_STRATEGY}}": ctx.attr.package_collisions,
5656
"{{ARG_VENV_LOCATION}}": paths.join(ctx.attr.location, ctx.attr.venv_name),
57-
"{{ARG_VENV_PYTHON_VERSION}}": "{}.{}.{}".format(
58-
py_toolchain.interpreter_version_info.major,
59-
py_toolchain.interpreter_version_info.minor,
60-
py_toolchain.interpreter_version_info.micro,
61-
),
57+
"{{ARG_VENV_NAME}}": ".{}.venv".format(ctx.attr.name),
6258
"{{ARG_PTH_FILE}}": to_rlocation_path(ctx, site_packages_pth_file),
6359
"{{EXEC_PYTHON_BIN}}": "python{}".format(
6460
py_toolchain.interpreter_version_info.major,

py/private/run.tmpl.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ export VIRTUAL_ENV
4141
"${VENV_TOOL}" \
4242
--location "${VIRTUAL_ENV}" \
4343
--python "$(python_location)" \
44-
--python-version "{{ARG_VENV_PYTHON_VERSION}}" \
4544
--pth-file "$(rlocation {{ARG_PTH_FILE}})" \
46-
--collision-strategy "{{ARG_COLLISION_STRATEGY}}"
45+
--collision-strategy "{{ARG_COLLISION_STRATEGY}}" \
46+
--venv-name "{{ARG_VENV_NAME}}"
4747

4848
PATH="${VIRTUAL_ENV}/bin:${PATH}"
4949
export PATH

py/private/toolchain/tools.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ TOOLCHAIN_PLATFORMS = {
3030
),
3131
"linux_amd64": struct(
3232
arch = "x86_64",
33-
vendor_os_abi = "unknown-linux-gnu",
33+
vendor_os_abi = "unknown-linux-musl",
3434
compatible_with = [
3535
"@platforms//os:linux",
3636
"@platforms//cpu:x86_64",
3737
],
3838
),
3939
"linux_arm64": struct(
4040
arch = "aarch64",
41-
vendor_os_abi = "unknown-linux-gnu",
41+
vendor_os_abi = "unknown-linux-musl",
4242
compatible_with = [
4343
"@platforms//os:linux",
4444
"@platforms//cpu:aarch64",

py/private/venv.tmpl.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ VIRTUAL_ENV="$(alocation "${VENV_ROOT}/{{ARG_VENV_LOCATION}}")"
2727
"${VENV_TOOL}" \
2828
--location "${VIRTUAL_ENV}" \
2929
--python "$(alocation $(rlocation {{ARG_PYTHON}}))" \
30-
--python-version "{{ARG_VENV_PYTHON_VERSION}}" \
3130
--pth-file "$(rlocation {{ARG_PTH_FILE}})" \
3231
--pth-entry-prefix "${RUNFILES_DIR}" \
33-
--collision-strategy "{{ARG_COLLISION_STRATEGY}}"
32+
--collision-strategy "{{ARG_COLLISION_STRATEGY}}" \
33+
--venv-name "{{ARG_VENV_NAME}}"
3434

3535
echo "Created virtualenv in ${VIRTUAL_ENV}"

0 commit comments

Comments
 (0)