cross: Cross building x86_64 and arm64 on a arm64 machine inside docker does not work
Checklist
- I’ve looked through the issues and pull requests for similar reports
Describe your issue
Hey,
I’m running Gitea + Gitea runner on a arm64 VM hosted on Oracle Cloud.
I’m getting this error:
info: downloading component 'rust-src'
info: installing component 'rust-src'
exec /usr/bin/sh: exec format error
What target(s) are you cross-compiling for?
No response
Which operating system is the host (e.g computer cross is on) running?
- macOS
- Windows
- Linux / BSD
- other OS (specify in description)
What architecture is the host?
- x86_64 / AMD64
- arm32
- arm64 (including Mac M1)
What container engine is cross using?
- docker
- podman
- other container engine (specify in description)
cross version
0.2.5
Example
name: Rust CI
on:
push:
branches:
- release-next
- main
env:
CARGO_TERM_COLOR: always
jobs:
rust-ci:
runs-on: ubuntu-latest
strategy:
matrix:
target:
- aarch64-unknown-linux-gnu
- x86_64-unknown-linux-gnu
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: clippy, rustfmt
target: ${{ matrix.target }}
- name: Install cross
run: cargo install cross --git https://github.com/cross-rs/cross.git
shell: bash
- name: Cross version
run: cross --version
shell: bash
- name: Check cargo fmt
run: cargo fmt --all -- --check
shell: bash
- name: Build
run: cross build --target ${{ matrix.target }}
shell: bash
- name: Run Tests
run: cross test --target ${{ matrix.target }}
shell: bash
- name: Run Clippy
run: cross clippy --target ${{ matrix.target }} -- -D warnings
shell: bash
Additional information / notes
cross 0.2.5 (c7dee4d 2025-02-12)
info: syncing channel updates for ‘stable-x86_64-unknown-linux-gnu’
info: latest update on 2025-01-30, rust version 1.84.1 (e71f9a9a9 2025-01-27)
info: downloading component ‘cargo’
info: downloading component ‘rust-std’
info: downloading component ‘rustc’
info: installing component ‘cargo’
info: installing component ‘rust-std’
info: installing component ‘rustc’
stable-x86_64-unknown-linux-gnu installed - (error reading rustc version)
info: checking for self-update
info: downloading component ‘rust-std’ for ‘aarch64-unknown-linux-gnu’
info: installing component ‘rust-std’ for ‘aarch64-unknown-linux-gnu’
[cross] note: Falling back to cargo on the host.
cargo 1.84.1 (66221abde 2024-11-19)
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 3
- Comments: 39 (16 by maintainers)
Same.
#1630 will not solve this issue immediately, it does not include building and pushing the images. And it also doesnt explain why theres suddenly issues with using our x86_64 images on aarch64 docker.
Did anyone try to go into the Docker settings under
General > Virtual Machine Optionsand enableApple Virtualization framework, then switch toVirtioFS. If this configuration is already selected, switch to QEMU, Restart, and switch back -> Then restart Docker again.That has fixed the Segmentation fault errors for me.
The fix for missing the docker container because no manifest was found for the current arch is to specify to docker that you specifically want to pull a platform bound image by adding
--platform linux/amd64in case of cc fromaarch64-darwintox86_64-linux.So to get it running initially, before running cross, you would run:
When building a custom container, this isn’t possible though, but here’s an example invocation of where it had worked for me, manually:
The
--platform <Target Arch>should be set to the cross target architecture by cross on every Docker buildx call, I think. That works for me at least.Edit: Adding
CROSS_BUILD_OPTS="--platform linux/x86_64"fixed the custom container build and produced a x86_64-linux binary from aarch64-darwin M4.Running cross on host aarch64-unknown-linux-gnu with target aarch64-unknown-linux-gnu or aarch64-unknown-linux-musl (in order to lower glibc version) also crashes, might be related:
Using via https://github.com/houseabsolute/actions-rust-cross/issues/39
Yeah, im not sure how to fix this. Somethibg is seriously messed up it seems with emulation. The problem is that we need to emulate x86_64 because the images are all currently x86_64 only. You could craft your own image that has aarch64 support but its not super simple. See https://github.com/cross-rs/cross/issues/751