Skip to content

Commit 555680c

Browse files
authored
fix(docker): fall back to host arch for local builds (#1420)
(cherry picked from commit 392ab51f58fc18e03e721cdfa21f666091c67b80) Signed-off-by: Evan Lezar <elezar@nvidia.com>
1 parent b4c7bc4 commit 555680c

2 files changed

Lines changed: 38 additions & 6 deletions

File tree

architecture/build.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ Dockerfile compiles Rust — both copy a staged binary out of
3131

3232
Binary staging is driven by `tasks/scripts/stage-prebuilt-binaries.sh`, which
3333
runs `cargo build` natively on a matching host or `cargo zigbuild` when
34-
cross-compiling. CI invokes the same staging step via the
35-
`rust-native-build.yml` workflow (per-architecture, per-component) and uploads
36-
the result as an artifact that the image build job downloads back into the
37-
staging directory before running Buildx.
34+
cross-compiling. Local Docker image tasks infer the target architecture from
35+
`DOCKER_PLATFORM` when set, otherwise from the container engine host metadata
36+
with the kernel architecture as the fallback. CI invokes the same staging step
37+
via the `rust-native-build.yml` workflow (per-architecture, per-component) and
38+
uploads the result as an artifact that the image build job downloads back into
39+
the staging directory before running Buildx.
3840

3941
Runtime layout:
4042

tasks/scripts/container-engine.sh

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,47 @@ ce_build() {
167167
fi
168168
}
169169

170+
# ---------------------------------------------------------------------------
171+
# ce_normalize_arch — normalize common architecture names.
172+
#
173+
# Keeps container-engine helpers from silently drifting between Docker,
174+
# Podman, and kernel naming conventions.
175+
# ---------------------------------------------------------------------------
176+
ce_normalize_arch() {
177+
case "$1" in
178+
x86_64|amd64) echo "amd64" ;;
179+
aarch64|arm64) echo "arm64" ;;
180+
*) echo "$1" ;;
181+
esac
182+
}
183+
184+
# ---------------------------------------------------------------------------
185+
# ce_host_arch — kernel architecture normalized for Docker platform names.
186+
# ---------------------------------------------------------------------------
187+
ce_host_arch() {
188+
ce_normalize_arch "$(uname -m)"
189+
}
190+
170191
# ---------------------------------------------------------------------------
171192
# ce_info_arch — host architecture reported by the container engine.
172193
#
173194
# Docker: docker info --format '{{.Architecture}}'
174195
# Podman: podman info --format '{{.Host.Arch}}'
196+
# Falls back to the kernel architecture when the daemon query is unavailable so
197+
# local builds do not accidentally target amd64 on arm64 hosts.
175198
# ---------------------------------------------------------------------------
176199
ce_info_arch() {
200+
local arch=""
177201
if ce_is_docker; then
178-
"${_CE_BIN}" info --format '{{.Architecture}}' 2>/dev/null || echo "amd64"
202+
arch=$("${_CE_BIN}" info --format '{{.Architecture}}' 2>/dev/null || true)
203+
else
204+
arch=$("${_CE_BIN}" info --format '{{.Host.Arch}}' 2>/dev/null || true)
205+
fi
206+
207+
if [[ -n "${arch}" ]]; then
208+
ce_normalize_arch "${arch}"
179209
else
180-
"${_CE_BIN}" info --format '{{.Host.Arch}}' 2>/dev/null || echo "amd64"
210+
ce_host_arch
181211
fi
182212
}
183213

0 commit comments

Comments
 (0)