cross: Cross building x86_64 and arm64 on a arm64 machine inside docker does not work

Checklist

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)

Commits related to this issue

Most upvoted comments

Hi guys, I’m using Mac OS 15.3.2 and I have the same errors today building with cross build --release --target aarch64-unknown-linux-gnu.

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 Options and enable Apple Virtualization framework, then switch to VirtioFS. 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/amd64 in case of cc from aarch64-darwin to x86_64-linux.

So to get it running initially, before running cross, you would run:

docker pull --platform linux/x86_64 ghcr.io/cross-rs/x86_64-unknown-linux-gnu 

When building a custom container, this isn’t possible though, but here’s an example invocation of where it had worked for me, manually:

$ /opt/homebrew/bin/docker build --label 'org.cross-rs.for-cross-target=x86_64-unknown-linux-gnu' --label 'org.cross-rs.workspace_root=/Users/willow/dev/syrillian' --tag cross-custom-syrillian:x86_64-unknown-linux-gnu-30da8-pre-build --build-arg 'CROSS_CMD=dpkg --add-architecture $CROSS_DEB_ARCH
apt-get update && apt-get --assume-yes install libssl-dev:$CROSS_DEB_ARCH' --build-arg 'CROSS_DEB_ARCH=amd64' --file /Users/willow/dev/syrillian/target/x86_64-unknown-linux-gnu/Dockerfile.x86_64-unknown-linux-gnu-custom --platform linux/amd64 /Users/willow/dev/syrillian
[+] Building 0.3s (4/5)                                                                                                                                                                                                                                                                       docker:desktop-linux
....
[+] Building 18.4s (6/6) FINISHED                                                                                                                                                                                                                                                             docker:desktop-linux
 => [internal] load build definition from Dockerfile.x86_64-unknown-linux-gnu-custom                                                                                                                                                                                                                          0.0s
 => => transferring dockerfile: 246B                                                                                                                                                                                                                                                                          0.0s
 => [internal] load metadata for ghcr.io/cross-rs/x86_64-unknown-linux-gnu:0.2.5                                                                                                                                                                                                                              0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                                                                                             0.0s
 => => transferring context: 2B                                                                                                                                                                                                                                                                               0.0s 
 => [1/2] FROM ghcr.io/cross-rs/x86_64-unknown-linux-gnu:0.2.5@sha256:9e5b39c09874bc1816c675ed11afca2c2ed6cee0c4ed2b3c1d5763c346c9ae3f                                                                                                                                                                        0.1s 
 => => resolve ghcr.io/cross-rs/x86_64-unknown-linux-gnu:0.2.5@sha256:9e5b39c09874bc1816c675ed11afca2c2ed6cee0c4ed2b3c1d5763c346c9ae3f                                                                                                                                                                        0.0s 
 => [2/2] RUN eval "dpkg --add-architecture $CROSS_DEB_ARCHCROSS_DEB_ARCH"                                                                                                                                                                       17.7s                                                        0.5s 
apt-get update && apt-get --assume-yes install libssl-dev:$CROSS_DEB_ARCH"                                                                                                                                                                       17.7s                                                        0.5s 
 => exporting to image                                                                                                                                                                                                                                                                                        0.6s 
 => => exporting layers                                                                                                                                                                                                                                                                                       0.5s
 => => exporting manifest sha256:d1f471f158ecdf2f9fbad777e3002df98dc50fcae90650fecfa5418863e38c92                                                                                                                                                                                                             0.0s
 => => exporting config sha256:e38872730dedc2471a9ca57d5e907a8455411c8c4687fa5e040f3e8161c755c2                                                                                                                                                                                                               0.0s
 => => exporting attestation manifest sha256:daca114aca26f38c58b5ffb1671c6b8ec0fffc4ba2fc864996e3e5592e0a9b7f                                                                                                                                                                                                 0.0s
 => => exporting manifest list sha256:c7def12580767981c5344f89447a8716054b2ecdc146d66432919cfe7d865482                                                                                                                                                                                                        0.0s
 => => naming to docker.io/library/cross-custom-syrillian:x86_64-unknown-linux-gnu-30da8-pre-build

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:

Run /home/runner/work/_temp/cross +stable test --target aarch64-unknown-linux-musl --locked --release --features=mimalloc
/home/runner/work/_temp/8afe309c-c719-42af-9f2d-90968f16aeef.sh: line 1: /home/runner/work/_temp/cross: cannot execute binary file: Exec format error

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