A minimal build backend for uv: uv_build (#11446)

uv itself is a large package with many dependencies and lots of
features. To build a package using the uv build backend, you shouldn't
have to download and install the entirety of uv. For platform where we
don't provide wheels, it should be possible and fast to compile the uv
build backend. To that end, we're introducing a python package that
contains a trimmed down version of uv that only contains the build
backend, with a minimal dependency tree in rust.

The `uv_build` package is publish from CI just like uv itself. It is
part of the workspace, but has much less dependencies for its own
binary. We're using cargo deny to enforce that the network stack is not
part of the dependencies. A new build profile ensure we're getting the
minimum possible binary size for a rust binary.

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
This commit is contained in:
konsti
2025-03-06 20:27:20 +01:00
committed by GitHub
parent d4a805544f
commit bf4c7afe8b
26 changed files with 842 additions and 96 deletions
+6 -30
View File
@@ -1,33 +1,8 @@
from __future__ import annotations
import os
if os.environ.get("UV_PREVIEW"):
from ._build_backend import *
from ._find_uv import find_uv_bin
if os.environ.get("UV_PREVIEW"):
__all__ = [
"find_uv_bin",
# PEP 517 hook `build_sdist`.
"build_sdist",
# PEP 517 hook `build_wheel`.
"build_wheel",
# PEP 660 hook `build_editable`.
"build_editable",
# PEP 517 hook `get_requires_for_build_sdist`.
"get_requires_for_build_sdist",
# PEP 517 hook `get_requires_for_build_wheel`.
"get_requires_for_build_wheel",
# PEP 517 hook `prepare_metadata_for_build_wheel`.
"prepare_metadata_for_build_wheel",
# PEP 660 hook `get_requires_for_build_editable`.
"get_requires_for_build_editable",
# PEP 660 hook `prepare_metadata_for_build_editable`.
"prepare_metadata_for_build_editable",
]
else:
__all__ = ["find_uv_bin"]
__all__ = ["find_uv_bin"]
def __getattr__(attr_name: str) -> object:
@@ -41,8 +16,9 @@ def __getattr__(attr_name: str) -> object:
"get_requires_for_build_editable",
"prepare_metadata_for_build_editable",
}:
err = f"Using `uv.{attr_name}` is not allowed. The uv build backend requires preview mode to be enabled, e.g., via the `UV_PREVIEW=1` environment variable."
err = (
f"Using `uv.{attr_name}` is not allowed; build backend functionality is in the `uv_build` package. "
f"Did you mean to use `uv_build` as your build system?"
)
raise AttributeError(err)
err = f"module 'uv' has no attribute '{attr_name}'"
raise AttributeError(err)
raise AttributeError(f"module `{__name__}` has no attribute `{attr_name}`")