Skip to content

refactor(whl_install): remove resolved_unpack_toolchain workaround#905

Merged
gregmagolan merged 1 commit into
mainfrom
fix/whl-install-unpack-toolchain
Apr 5, 2026
Merged

refactor(whl_install): remove resolved_unpack_toolchain workaround#905
gregmagolan merged 1 commit into
mainfrom
fix/whl-install-unpack-toolchain

Conversation

@gregmagolan
Copy link
Copy Markdown
Member

@gregmagolan gregmagolan commented Apr 4, 2026

Summary

  • UNPACK_TOOLCHAIN is registered with exec_compatible_with (via cfg="exec" in TOOL_CFGS), so ctx.toolchains[UNPACK_TOOLCHAIN] already resolves the exec-platform binary — no indirection needed.
  • Remove resolved_unpack_toolchain rule from tools.bzl and BUILD.bazel.
  • Replace the cfg="exec" _unpack attr + ctx.attr._unpack[ToolchainInfo].bin.bin pattern in whl_install/rule.bzl with a direct ctx.toolchains[UNPACK_TOOLCHAIN].bin.bin lookup.
  • Add exec_toolchain_resolution_test to the uv-deps-650/crossbuild e2e case: writes the resolved unpack binary path for both a native target and an arm64-transitioned target, then asserts the paths are identical (proving exec-platform resolution is preserved across target-platform transitions).

This is a follow-on cleanup to #903, which removed the analogous resolved_py_toolchain workaround.

Test plan

  • Existing e2e suite passes (crossbuild_compile_pyc_test still green)
  • New exec_toolchain_resolution_test passes on Linux CI (arm64 and amd64 transitions resolve the same exec-platform binary)
  • No references to resolved_unpack_toolchain remain

@aspect-workflows
Copy link
Copy Markdown

aspect-workflows Bot commented Apr 4, 2026

Bazel 8 (Test)

All tests were cache hits

111 tests (100.0%) were fully cached saving 43s.


Bazel 9 (Test)

All tests were cache hits

111 tests (100.0%) were fully cached saving 40s.


Bazel 8 (Test)

e2e

1 test target passed

Targets
//cases/uv-deps-650/crossbuild:exec_toolchain_resolution_test [k8-fastbuild]71ms

Total test execution time was 71ms. 50 tests (98.0%) were fully cached saving 55s.


Bazel 9 (Test)

e2e

1 test target passed

Targets
//cases/uv-deps-650/crossbuild:exec_toolchain_resolution_test [k8-fastbuild]115ms

Total test execution time was 115ms. 50 tests (98.0%) were fully cached saving 43s.


Bazel 8 (Test)

examples/uv_pip_compile

All tests were cache hits

1 test (100.0%) was fully cached saving 444ms.

@gregmagolan gregmagolan force-pushed the fix/whl-install-unpack-toolchain branch from 5274347 to 28f5615 Compare April 4, 2026 21:12
@gregmagolan gregmagolan force-pushed the fix/whl-install-unpack-toolchain branch 4 times, most recently from 09e3dd3 to 5957450 Compare April 5, 2026 00:35
UNPACK_TOOLCHAIN is registered in repo.bzl with exec_compatible_with
(via the cfg="exec" TOOL_CFGS entry), so ctx.toolchains[UNPACK_TOOLCHAIN]
already resolves the exec-platform binary without any indirection.
The resolved_unpack_toolchain rule and its cfg="exec" _unpack attr in
whl_install were an unnecessary workaround, analogous to resolved_py_toolchain
which was removed in #903.

Remove resolved_unpack_toolchain from tools.bzl and BUILD.bazel, and replace
the ctx.attr._unpack indirection in rule.bzl with a direct toolchain lookup.

Add an analysis-time regression test (exec_toolchain_resolution_test) that
confirms UNPACK_TOOLCHAIN resolves the exec-platform binary even when the
target platform is arm64. The test writes the resolved binary path to a file
for both native and arm64-transitioned targets and asserts they are identical,
proving exec-platform resolution is honoured throughout platform transitions.
@gregmagolan gregmagolan force-pushed the fix/whl-install-unpack-toolchain branch from c8eb976 to 4dbc2f2 Compare April 5, 2026 00:39
@gregmagolan gregmagolan merged commit a984e2b into main Apr 5, 2026
4 checks passed
@gregmagolan gregmagolan deleted the fix/whl-install-unpack-toolchain branch April 5, 2026 00:54
gregmagolan added a commit that referenced this pull request Apr 5, 2026
…macOS failure (#910)

## Problem

After #905 removed `resolved_unpack_toolchain`, macOS builds fail when
the dependency graph contains a `platform_transition_filegroup`
targeting Linux (e.g. OCI crossbuild tests):

```
bazel-out/darwin_arm64-opt-ST-.../bin/py/tools/unpack_bin/unpack: cannot execute binary file
```

The `unpack` binary is ELF (Linux x86-64) instead of Mach-O
(darwin-arm64).

## Root cause

Bazel analyzes toolchain targets **in the same configuration as the
requesting rule**. When a `platform_transition_filegroup` transitions to
a Linux target platform, `whl_install` is analyzed in that
Linux-targeted configuration. With no `cfg` on the `bin` attribute of
`py_tool_toolchain`, the `unpack` binary inherits that Linux target
config and is compiled as ELF — which cannot execute on the macOS exec
host.

`resolved_unpack_toolchain` worked around this by being a regular `dep`
with `cfg = "exec"`, explicitly pulling the binary into exec config. The
goal of #905 was to remove that workaround, but doing so exposed the
underlying issue.

## Fix

Introduce two source-toolchain rule variants with explicit `cfg` on
their `bin` attribute:

- `source_target_py_tool_toolchain` — `cfg = "target"` (venv, shim:
target-side tools placed in runfiles)
- `source_exec_py_tool_toolchain` — `cfg = "exec"` (unpack: runs on the
exec host during the build)

`TOOL_CFGS` is already the source of truth for which tools are exec-side
(`cfg = "exec"`) vs target-side. The `source_toolchain` macro now looks
up the `cfg` from `TOOL_CFGS` by name and selects the appropriate rule
variant automatically — no per-call parameter needed.

Note: these `source_*` rules are only active when `IS_PRERELEASE = True`
(i.e. in this repo during development). Consumers get pre-built binaries
via `prebuilt_tool_repo`, which uses `exec_compatible_with` on the
`toolchain()` declaration for correct host selection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants