Skip to content
Merged
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
7 changes: 7 additions & 0 deletions docs/uv-patching.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ uv.override_package(
convey them.
- Generated pure-Python builds reject `toolchains` and `env`; those attributes
augment the native build toolchain and environment.
- Native build `env` values can use `$(EXECROOT)/` to anchor paths supplied by
a toolchain, for example `CPPFLAGS = "-I$(EXECROOT)/$(DEP_INC)"` and
`LDFLAGS = "$(EXECROOT)/$(DEP_LIB_A)"`. The anchor remains valid after the
PEP 517 backend changes into the unpacked source tree.
- Native builds select the configured C++ compiler, archiver, linker, and strip
tools by default. Explicit `CC`, `CXX`, `AR`, `LD`, and `STRIP` values in
`env` override those selections.
- Post-install patches to prebuilt wheels must preserve every original path
used for collision and regular-package merge planning, including its
file-or-directory kind and package classification. Ordinary added paths are
Expand Down
218 changes: 217 additions & 1 deletion e2e/cases/pep517-frontend-exec-group/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@ load("@aspect_rules_py//uv/private/pep517_whl:rule.bzl", "pep517_native_whl")
load("@bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@rules_cc//cc/toolchains:cc_toolchain.bzl", legacy_cc_toolchain = "cc_toolchain")
load("@rules_cc//cc/toolchains:tool.bzl", "cc_tool")
load("@rules_cc//cc/toolchains:tool_map.bzl", "cc_tool_map")
load("@rules_cc//cc/toolchains:toolchain.bzl", "cc_toolchain")
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
load(":toolchain.bzl", "fake_cc_toolchain")
load(":toolchain.bzl", "fake_cc_toolchain", "legacy_cc_toolchain_config")

_CC_TOOLCHAIN = "//pep517-frontend-exec-group:cc_toolchain"

_CONFIGURED_CC_TOOLCHAIN = "//pep517-frontend-exec-group:configured_cc_toolchain"

_LEGACY_CC_TOOLCHAIN = "//pep517-frontend-exec-group:legacy_cc_toolchain"

# Keep the host first so the default exec group selects it. The native wheel's
# `target` exec group requires the transitioned target constraints and selects
# the second platform instead. Platform flags are applied in the configuration
Expand Down Expand Up @@ -38,6 +46,32 @@ platform(
],
)

platform(
name = "linux_configured",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
],
flags = [
"--@aspect_rules_py//uv/private/constraints/platform:platform_libc=glibc",
"--extra_execution_platforms=@platforms//host,//pep517-frontend-exec-group:linux_configured",
"--extra_toolchains=" + _CONFIGURED_CC_TOOLCHAIN,
],
)

platform(
name = "linux_legacy",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
],
flags = [
"--@aspect_rules_py//uv/private/constraints/platform:platform_libc=glibc",
"--extra_execution_platforms=@platforms//host,//pep517-frontend-exec-group:linux_legacy",
"--extra_toolchains=" + _LEGACY_CC_TOOLCHAIN,
],
)

config_setting(
name = "linux_aarch64_config",
constraint_values = [
Expand Down Expand Up @@ -92,6 +126,90 @@ toolchain(
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

write_file(
name = "unusual_c_driver",
out = "unusual_c_driver.sh",
content = [
"#!/usr/bin/env bash",
"printf '%s\\n' c-action",
],
is_executable = True,
)

write_file(
name = "unusual_cxx_driver",
out = "unusual_cxx_driver.sh",
content = [
"#!/usr/bin/env bash",
"printf '%s\\n' cxx-action",
],
is_executable = True,
)

cc_tool(
name = "configured_c_tool",
src = ":unusual_c_driver",
)

cc_tool(
name = "configured_cxx_tool",
src = ":unusual_cxx_driver",
)

cc_tool_map(
name = "configured_tool_map",
tools = {
"@rules_cc//cc/toolchains/actions:c_compile": ":configured_c_tool",
"@rules_cc//cc/toolchains/actions:cpp_compile_actions": ":configured_cxx_tool",
"@rules_cc//cc/toolchains/actions:link_actions": ":configured_c_tool",
"@rules_cc//cc/toolchains/actions:strip": ":configured_c_tool",
"@rules_cc//cc/toolchains/actions:ar_actions": ":configured_c_tool",
},
)

cc_toolchain(
name = "configured_cc",
tool_map = ":configured_tool_map",
)

toolchain(
name = "configured_cc_toolchain",
toolchain = ":configured_cc",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

filegroup(
name = "legacy_tools",
srcs = [
"legacy_archiver.sh",
"legacy_compiler.sh",
],
)

legacy_cc_toolchain_config(
name = "legacy_cc_config",
archiver = "legacy_archiver.sh",
compiler = "legacy_compiler.sh",
)

legacy_cc_toolchain(
name = "legacy_cc",
all_files = ":legacy_tools",
ar_files = ":legacy_tools",
compiler_files = ":legacy_tools",
dwp_files = ":legacy_tools",
linker_files = ":legacy_tools",
objcopy_files = ":legacy_tools",
strip_files = ":legacy_tools",
toolchain_config = ":legacy_cc_config",
)

toolchain(
name = "legacy_cc_toolchain",
toolchain = ":legacy_cc",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

write_file(
name = "frontend_script",
out = "frontend.sh",
Expand Down Expand Up @@ -124,6 +242,66 @@ sh_binary(
srcs = [":frontend_script"],
)

write_file(
name = "configured_frontend_script",
out = "configured_frontend.sh",
content = [
"#!/usr/bin/env bash",
"set -euo pipefail",
"c_actual=\"$(\"${CC}\")\"",
"cxx_actual=\"$(\"${CXX}\")\"",
"if [[ \"${c_actual}\" != c-action || \"${cxx_actual}\" != cxx-action ]]; then",
" echo \"configured tools reported ${c_actual} and ${cxx_actual}\" >&2",
" exit 1",
"fi",
"wheel_dir=\"${!#}\"",
"mkdir -p \"${wheel_dir}\"",
],
is_executable = True,
)

sh_binary(
name = "configured_frontend",
srcs = [":configured_frontend_script"],
)

write_file(
name = "legacy_frontend_script",
out = "legacy_frontend.sh",
content = [
"#!/usr/bin/env bash",
"set -euo pipefail",
"execroot=\"${PWD}\"",
"if [[ \"${AR-unset}\" != */legacy_archiver.sh || \"${CC-unset}\" != */legacy_compiler.sh || \"${CXX-unset}\" != */legacy_compiler.sh || \"${LD-unset}\" != */legacy_compiler.sh || \"${STRIP-unset}\" != */legacy_compiler.sh ]]; then",
" echo \"legacy tools were not selected: AR=${AR-unset} CC=${CC-unset} CXX=${CXX-unset} LD=${LD-unset} STRIP=${STRIP-unset}\" >&2",
" exit 1",
"fi",
"wheel_dir=\"${!#}\"",
"wheel_dir=\"${execroot}/${wheel_dir}\"",
"work_dir=\"${wheel_dir}.tmp\"",
"/bin/mkdir -p \"${wheel_dir}\" \"${work_dir}/poison\"",
"for tool in cc c++ ar ld strip; do",
" printf '%s\\n' '#!/bin/sh' 'echo ambient tool selected >&2' 'exit 97' > \"${work_dir}/poison/${tool}\"",
" /bin/chmod +x \"${work_dir}/poison/${tool}\"",
"done",
"export PATH=\"${work_dir}/poison:/usr/bin:/bin\"",
"cd \"${work_dir}\"",
"printf '%s\\n' 'int c_value(void) { return 42; }' > dep.c",
"printf '%s\\n' 'extern \"C\" int c_value(void);' 'int main() { return c_value() == 42 ? 0 : 1; }' > main.cc",
"\"${execroot}/${CC}\" -c dep.c -o dep.o",
"\"${execroot}/${AR}\" rcs libdep.a dep.o",
"\"${execroot}/${CXX}\" -c main.cc -o main.o",
"\"${execroot}/${CXX}\" main.o libdep.a -o native",
"./native",
],
is_executable = True,
)

sh_binary(
name = "legacy_frontend",
srcs = [":legacy_frontend_script"],
)

write_file(
name = "stub_sdist",
out = "stub.tar.gz",
Expand All @@ -142,6 +320,22 @@ pep517_native_whl(
version = "0.0.0",
)

pep517_native_whl(
name = "configured_wheel",
src = ":stub_sdist",
tags = ["manual"],
tool = ":configured_frontend",
version = "0.0.0",
)

pep517_native_whl(
name = "legacy_wheel",
src = ":stub_sdist",
tags = ["manual"],
tool = ":legacy_frontend",
version = "0.0.0",
)

platform_transition_filegroup(
name = "wheel_linux_aarch64",
srcs = [":wheel"],
Expand All @@ -154,10 +348,32 @@ platform_transition_filegroup(
target_platform = ":linux_x86_64",
)

platform_transition_filegroup(
name = "wheel_linux_configured",
srcs = [":configured_wheel"],
target_platform = ":linux_configured",
)

platform_transition_filegroup(
name = "wheel_linux_legacy",
srcs = [":legacy_wheel"],
target_platform = ":linux_legacy",
)

build_test(
name = "frontend_exec_platform_test",
targets = [
":wheel_linux_aarch64",
":wheel_linux_x86_64",
],
)

build_test(
name = "configured_compiler_tools_test",
targets = [":wheel_linux_configured"],
)

build_test(
name = "legacy_toolchain_test",
targets = [":wheel_linux_legacy"],
)
3 changes: 3 additions & 0 deletions e2e/cases/pep517-frontend-exec-group/legacy_archiver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
export PATH=/usr/bin:/bin
exec /usr/bin/ar "$@"
3 changes: 3 additions & 0 deletions e2e/cases/pep517-frontend-exec-group/legacy_compiler.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
export PATH=/usr/bin:/bin
exec /usr/bin/cc "$@"
40 changes: 40 additions & 0 deletions e2e/cases/pep517-frontend-exec-group/toolchain.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
"""Synthetic C++ toolchains for the PEP 517 execution-group test."""

load("@rules_cc//cc:cc_toolchain_config_lib.bzl", "feature", "tool_path") # buildifier: disable=deprecated-function
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
load("@rules_cc//cc/toolchains:cc_toolchain_config_info.bzl", "CcToolchainConfigInfo")

def _fake_cc_toolchain_impl(ctx):
compiler = ctx.file.compiler
return [
Expand All @@ -18,3 +22,39 @@ fake_cc_toolchain = rule(
),
},
)

def _legacy_cc_toolchain_config_impl(ctx):
compiler = ctx.file.compiler.basename
return cc_common.create_cc_toolchain_config_info(
ctx = ctx,
toolchain_identifier = "legacy-no-action-configs",
host_system_name = "local",
target_system_name = "local",
target_cpu = "x86_64",
target_libc = "unknown",
compiler = "legacy",
abi_version = "unknown",
abi_libc_version = "unknown",
features = [feature(name = "no_legacy_features", enabled = True)],
tool_paths = [
tool_path(name = "ar", path = ctx.file.archiver.basename),
tool_path(name = "cpp", path = compiler),
tool_path(name = "dwp", path = compiler),
tool_path(name = "gcc", path = compiler),
tool_path(name = "gcov", path = compiler),
tool_path(name = "ld", path = compiler),
tool_path(name = "nm", path = compiler),
tool_path(name = "objcopy", path = compiler),
tool_path(name = "objdump", path = compiler),
tool_path(name = "strip", path = compiler),
],
)

legacy_cc_toolchain_config = rule(
implementation = _legacy_cc_toolchain_config_impl,
attrs = {
"archiver": attr.label(allow_single_file = True, mandatory = True),
"compiler": attr.label(allow_single_file = True, mandatory = True),
},
provides = [CcToolchainConfigInfo],
)

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.

Loading
Loading