Skip to content

Commit 0888721

Browse files
committed
check so arch in e2e
1 parent f3a2889 commit 0888721

2 files changed

Lines changed: 90 additions & 0 deletions

File tree

e2e/cases/uv-deps-650/crossbuild/BUILD.bazel

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,56 @@ platform_transition_filegroup(
185185
srcs = [":geohash_bin"],
186186
target_platform = ":arm64_linux",
187187
)
188+
189+
# ── Verify .so architecture ──
190+
191+
py_image_layer(
192+
name = "geohash_layers",
193+
binary = ":geohash_bin",
194+
)
195+
196+
platform_transition_filegroup(
197+
name = "geohash_amd64_layers",
198+
srcs = [":geohash_layers"],
199+
target_platform = ":amd64_linux",
200+
)
201+
202+
platform_transition_filegroup(
203+
name = "geohash_arm64_layers",
204+
srcs = [":geohash_layers"],
205+
target_platform = ":arm64_linux",
206+
)
207+
208+
genrule(
209+
name = "_geohash_amd64_so_arch_check",
210+
srcs = [":geohash_amd64_layers"],
211+
outs = ["_geohash_amd64_so_arch.ok"],
212+
cmd = """
213+
tar_file=$$(echo $(SRCS) | tr ' ' '\\n' | grep 'geohash_layers.*\\.tar' | head -1)
214+
$(location check_so_arch.sh) $$tar_file 3e00
215+
touch $@
216+
""",
217+
tools = [":check_so_arch.sh"],
218+
)
219+
220+
genrule(
221+
name = "_geohash_arm64_so_arch_check",
222+
srcs = [":geohash_arm64_layers"],
223+
outs = ["_geohash_arm64_so_arch.ok"],
224+
cmd = """
225+
tar_file=$$(echo $(SRCS) | tr ' ' '\\n' | grep 'geohash_layers.*\\.tar' | head -1)
226+
$(location check_so_arch.sh) $$tar_file b700
227+
touch $@
228+
""",
229+
tools = [":check_so_arch.sh"],
230+
)
231+
232+
build_test(
233+
name = "geohash_so_arch_amd64_test",
234+
targets = [":_geohash_amd64_so_arch_check"],
235+
)
236+
237+
build_test(
238+
name = "geohash_so_arch_arm64_test",
239+
targets = [":_geohash_arm64_so_arch_check"],
240+
)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
# Check that _geohash.so inside a py_image_layer tar is ELF for the expected arch.
3+
#
4+
# Uses only POSIX utilities (tar, od, find) — no Python dependency.
5+
#
6+
# Usage: check_so_arch.sh <tar_file> <expected_machine_le_hex>
7+
# expected_machine_le_hex: ELF e_machine as little-endian hex bytes
8+
# x86_64 (EM_X86_64 = 62 = 0x3e) → "3e00"
9+
# aarch64 (EM_AARCH64 = 183 = 0xb7) → "b700"
10+
set -euo pipefail
11+
12+
tar_file="${1:?usage: check_so_arch.sh <tar_file> <expected_machine_le_hex>}"
13+
expected="${2:?expected ELF machine as little-endian hex}"
14+
15+
tmp="$(mktemp -d)"
16+
trap 'rm -rf "$tmp"' EXIT
17+
tar xf "$tar_file" -C "$tmp" 2>/dev/null || true
18+
19+
so="$(find "$tmp" -name '_geohash*.so' -type f | head -1)"
20+
if [ -z "$so" ]; then
21+
echo "FAIL: no _geohash*.so found in $tar_file"
22+
exit 1
23+
fi
24+
25+
magic="$(od -A n -t x1 -N 4 "$so" | tr -d ' ')"
26+
if [ "$magic" != "7f454c46" ]; then
27+
echo "FAIL: $(basename "$so") is not ELF (magic=0x${magic})"
28+
exit 1
29+
fi
30+
31+
machine="$(od -A n -t x1 -j 18 -N 2 "$so" | tr -d ' ')"
32+
if [ "$machine" != "$expected" ]; then
33+
echo "FAIL: $(basename "$so") ELF machine=0x${machine} expected=0x${expected}"
34+
exit 1
35+
fi
36+
37+
echo "PASS: $(basename "$so") is ELF machine=0x${machine}"

0 commit comments

Comments
 (0)