Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions docs/uv.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ configurations, such as going from a Darwin macbook to a Linux container image
using only the normal Bazel `platforms` machinery.

**Correct source builds** - Because uv performs package source builds as a
normal part of your build, it's able to use hermetic or even source built Python
toolchains in addition to Bazel-defined dependencies and C compilers. Future
support for sysroots is planned. Due to its phasing, `pip.parse` is stuck doing
all this non-hermetically.
normal part of your build, it can use hermetic or even source-built Python
toolchains in addition to Bazel-defined dependencies. Native builds select the
C and C++ tools from Bazel's configured compile actions, but do not reuse their
action flags or environment because PEP 517 backends own the compile and link
commands. Tools that require target, sysroot, resource, wrapper, or environment
configuration must provide a backend-compatible command through the package
`env`; generic C++ toolchain projection is not supported. Due to its phasing,
`pip.parse` is stuck doing all this non-hermetically.

**Editable requirements** - Uv provides an `uv.override_requirement()` tag which
allows locked requirements to be replaced with 1stparty Bazel `py_library`
Expand Down
13 changes: 8 additions & 5 deletions e2e/cases/uv-sdist-native-build/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
# Regression test: python-geohash (sdist-only, C++ extension) must be buildable
# when native_build_toolchain_type is registered via @rules_py_tools//:all.
# with native_build_toolchain_type registered via @rules_py_tools//:all.
#
# The pep517_native_whl rule requires the native_build_toolchain_type to resolve,
# asserting that the exec and target platforms match. This test verifies that the
# per-platform toolchain entries generated into @rules_py_tools are reachable.
# asserting that the exec and target platforms match. The source patch also
# introduces a C++ standard-library dependency, so linking fails if the helper
# invokes the configured compiler in C rather than C++ driver mode.

load("@aspect_rules_py//py:defs.bzl", "py_test")

exports_files(["require_cxx_driver.patch"])

py_test(
name = "test",
srcs = ["test_geohash.py"],
dep_group = "uv-sdist-native-build",
main = "test_geohash.py",
target_compatible_with = ["@platforms//os:linux"],
deps = ["@pypi_uv_sdist_native_build//python_geohash"],
)

py_test(
name = "venv_test",
srcs = ["test_geohash.py"],
dep_group = "uv-sdist-native-build",
expose_venv = True,
isolated = False,
main = "test_geohash.py",
target_compatible_with = ["@platforms//os:linux"],
deps = ["@pypi_uv_sdist_native_build//python_geohash"],
)
2 changes: 2 additions & 0 deletions e2e/cases/uv-sdist-native-build/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ name = "uv-sdist-native-build"
version = "0.0.0"
requires-python = ">=3.11"
dependencies = [
"build==1.4.0",
"python-geohash",
"setuptools==75.8.2",
]
30 changes: 30 additions & 0 deletions e2e/cases/uv-sdist-native-build/require_cxx_driver.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -9,0 +10 @@ c1=Extension('_geohash',
+c1.sources.append('src/native_probe.c')
diff --git a/src/geohash.cpp b/src/geohash.cpp
--- a/src/geohash.cpp
+++ b/src/geohash.cpp
@@ -19,0 +20,4 @@
+#include <string>
+
+extern "C" int native_c_probe(void);
+
@@ -725,0 +731,6 @@
+
+static PyObject *py_native_probe(PyObject *, PyObject *) {
+ std::string suffix = "++";
+ return PyLong_FromLong(native_c_probe() + suffix.size());
+}
+
@@ -732,0 +745 @@
+ {"native_probe", py_native_probe, METH_NOARGS, "exercise C and C++ compilation and linkage"},
diff --git a/src/native_probe.c b/src/native_probe.c
new file mode 100644
--- /dev/null
+++ b/src/native_probe.c
@@ -0,0 +1,3 @@
+int native_c_probe(void) {
+ return 40;
+}
2 changes: 2 additions & 0 deletions e2e/cases/uv-sdist-native-build/setup.MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ uv.project(
uv.override_package(
name = "python-geohash",
lock = "//cases/uv-sdist-native-build:uv.lock",
pre_build_patch_strip = 1,
pre_build_patches = ["//cases/uv-sdist-native-build:require_cxx_driver.patch"],
resource_set = "mem_4g",
)

Expand Down
2 changes: 2 additions & 0 deletions e2e/cases/uv-sdist-native-build/test_geohash.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Verify that python-geohash (built from sdist via pep517_native_whl) is importable."""

import geohash
import _geohash


def test_encode_decode():
assert _geohash.native_probe() == 42
lat, lon = 37.7749, -122.4194
encoded = geohash.encode(lat, lon)
assert encoded, "geohash.encode should return a non-empty string"
Expand Down
20 changes: 13 additions & 7 deletions e2e/cases/uv-sdist-native-build/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions uv/private/extension/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,9 @@ def _parse_projects(module_ctx, hub_specs):
pre_build_patches = [str(p) for p in pkg_override.pre_build_patches]
pre_build_patch_strip = pkg_override.pre_build_patch_strip

# `toolchains` / `env` on `uv.override_package` augment
# the defaults baked into sdist_build's BUILD template
# they don't replace them. Empty == no augmentation.
# `toolchains` on `uv.override_package` extends the
# defaults baked into sdist_build's BUILD template. `env`
# is merged over those defaults, replacing named values.
extra_toolchains = []
extra_env = {}
resource_set = "default"
Expand Down Expand Up @@ -782,7 +782,7 @@ _override_package_tag = tag_class(
),
"env": attr.string_dict(
default = {},
doc = "Extra environment variables merged into the build action's `env` dict. Values may reference $(VAR) make-variables sourced from the default CC toolchain or any extra `toolchains` listed above.",
doc = "Environment variables merged over the native-build defaults. Values may reference $(VAR) make-variables sourced from the default CC toolchain or any extra `toolchains` listed above.",
),

# Pre-build patches: applied to extracted sdist source before wheel build.
Expand Down
Loading
Loading