Skip to content

Commit

Permalink
Add partial support for cross-compiling on Linux ARM runners
Browse files Browse the repository at this point in the history
  • Loading branch information
autarch committed Feb 17, 2025
1 parent 601d02e commit 2b0dd44
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,32 @@ jobs:
expect-stripped: ""
can-execute: true

- platform_name: Linux-aarch64 with arm64 host
runs-on: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
cache-cross-binary: true
expect-file-re: "aarch64"
expect-cross: ""
expect-stripped: "--expect-stripped"
can-execute: true

# This fails because of some sort of weird bug in cross. See
# https://github.com/cross-rs/cross/issues/1628 for more details. Until that's fixed
# cross-compiling on Linux ARM won't work without a custom Docker image, which I don't
# want to do just for the sake of testing this.
#
# - platform_name: Linux-aarch64 with arm64 host compile to x86-64
# runs-on: ubuntu-24.04-arm
# target: x86_64-unknown-linux-gnu
# # Until cross produces arm64 binary releases we _have_ to set this when running on
# # arm64.
# cross-version: "c7dee4d"
# cache-cross-binary: true
# expect-file-re: "ELF.+x86-64"
# expect-cross: "--expect-cross"
# expect-stripped: ""
# can-execute: true

- platform_name: Linux-arm
runs-on: ubuntu-24.04
target: arm-unknown-linux-gnueabi
Expand Down
6 changes: 6 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.0.3

- Fixed a bug when running with an ARM Linux host where the action would use a cached `cross`
download for x86-64 Linux (or vice versa). Now the cache key for the `cross` binary includes both
the runner's architecture in addition to its OS.

## 1.0.2 - 2025-02-16

- Added a new `force-use-cross` input, which does what it says. It will force the use of `cross`
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ you can avoid this issue by structuring your workflow as follows:
When structured this way, it does not matter if the output of crate A is deleted in step 3.
## Cross-Compiling from Linux ARM Runners
In theory, this should work, and this action does implement some of the necessary work for this.
However, there are a couple issues with this:
1. As of 2025-02-17, the `cross` project does not publish Linux ARM binary releases. That means that
in order to use `cross` on a Linux ARM runner as part of this action, you must set
`cross-version` to a more recent commit from the `cross` repo.
2. There is
[a bug in `cross` that means you must use a custom Docker image](https://github.com/cross-rs/cross/issues/1628)
when cross-compiling from a Linux ARM runner. See
[this other `cross` issue](https://github.com/cross-rs/cross/issues/751) for more details.
## Linting and Tidying this Code
The code in this repo is linted and tidied with
Expand Down
11 changes: 10 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ runs:
targets: ${{ inputs.target }}
toolchain: ${{ inputs.toolchain }}

- name: Install qemu-user emulator binaries if cross-compiling on arm64 host
shell: bash
run: |
set -e
set -x
docker run --privileged --rm tonistiigi/binfmt --install all
if: steps.determine-cross-compile.outputs.needs-cross == 'true' && runner.os == 'Linux' && contains(runner.arch, 'ARM')

- name: Determine cross version
id: determine-cross-version
shell: bash
Expand All @@ -128,7 +137,7 @@ runs:
uses: actions/cache@v4
with:
path: ${{ steps.set-cross-dir.outputs.cross-dir }}/cross
key: ${{ runner.os }}-${{ steps.determine-cross-version.outputs.cross-version }}
key: ${{ runner.os }}-${{ runner.arch }}-${{ steps.determine-cross-version.outputs.cross-version }}
if: steps.determine-cross-compile.outputs.needs-cross == 'true' && inputs.cache-cross-binary == 'true'

- name: Install cross if cross-compiling (*nix)
Expand Down

0 comments on commit 2b0dd44

Please sign in to comment.