|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Verifies that UNPACK_TOOLCHAIN always resolves the exec-platform binary, |
| 3 | +# even when the target platform is arm64. |
| 4 | +# |
| 5 | +# The whl_install rule uses ctx.toolchains[UNPACK_TOOLCHAIN] directly (no |
| 6 | +# resolved_unpack_toolchain workaround) because UNPACK_TOOLCHAIN is registered |
| 7 | +# with exec_compatible_with, so Bazel always selects the exec-platform binary. |
| 8 | +# |
| 9 | +# This test confirms that: when we transition to an arm64 target platform on |
| 10 | +# an amd64 exec host, the resolved unpack binary path still refers to the amd64 |
| 11 | +# binary (not an arm64 binary that would fail with "Exec format error"). |
| 12 | +set -euo pipefail |
| 13 | + |
| 14 | +DIR="${TEST_SRCDIR}/_main/cases/uv-deps-650/crossbuild" |
| 15 | + |
| 16 | +native_path_file="$DIR/unpack_path.txt" |
| 17 | +arm64_path_file="$DIR/unpack_path_for_arm64.txt" |
| 18 | + |
| 19 | +if [[ ! -f "$native_path_file" ]]; then |
| 20 | + echo "FAIL: $native_path_file not found" |
| 21 | + exit 1 |
| 22 | +fi |
| 23 | + |
| 24 | +if [[ ! -f "$arm64_path_file" ]]; then |
| 25 | + echo "FAIL: $arm64_path_file not found" |
| 26 | + exit 1 |
| 27 | +fi |
| 28 | + |
| 29 | +native_path=$(cat "$native_path_file") |
| 30 | +arm64_path=$(cat "$arm64_path_file") |
| 31 | + |
| 32 | +echo "Native unpack path: $native_path" |
| 33 | +echo "Arm64-target unpack path: $arm64_path" |
| 34 | + |
| 35 | +# Both paths must refer to the same exec-platform binary. If the arm64 |
| 36 | +# transition incorrectly resolved a target-platform binary, the paths would |
| 37 | +# differ and the arm64 binary would fail with "Exec format error" at runtime. |
| 38 | +if [[ "$native_path" != "$arm64_path" ]]; then |
| 39 | + echo "FAIL: arm64-target transition resolved a different unpack binary." |
| 40 | + echo " Expected exec-platform binary: $native_path" |
| 41 | + echo " Got: $arm64_path" |
| 42 | + echo " This indicates toolchain resolution is using the target platform" |
| 43 | + echo " instead of the exec platform for the unpack binary." |
| 44 | + exit 1 |
| 45 | +fi |
| 46 | + |
| 47 | +# Additionally, the path must not reference an arm64/aarch64 binary. |
| 48 | +if [[ "$arm64_path" == *"arm64"* ]] || [[ "$arm64_path" == *"aarch64"* ]]; then |
| 49 | + echo "FAIL: unpack binary path contains arm64/aarch64 — exec platform not honoured." |
| 50 | + echo " Path: $arm64_path" |
| 51 | + exit 1 |
| 52 | +fi |
| 53 | + |
| 54 | +echo "PASS: UNPACK_TOOLCHAIN resolved exec-platform binary for arm64 target ($(uname -m) host)" |
0 commit comments