I am using GitHub Actions to cross-compile my Rust program. The action completes successfully, and files are created in the target directory, but there is no binary. This is my workflow file:
name: Compile and save program
on:
push:
branches: [main]
paths-ignore: ["samples/**", "**.md"]
workflow_dispatch:
jobs:
build:
strategy:
fail-fast: false
matrix:
target:
- aarch64-unknown-linux-gnu
- i686-pc-windows-gnu
- i686-unknown-linux-gnu
- x86_64-pc-windows-gnu
- x86_64-unknown-linux-gnu
name: Build executable
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Install dependencies
run: |
rustup target add ${{ matrix.target }}
- name: Build
uses: actions-rs/cargo@v1
with:
use-cross: true
command: build
args: --target ${{ matrix.target }} --release --all-features --target-dir=/tmp
- name: Debug missing files
run: |
echo "target dir:"
ls -a /tmp/release
echo "deps:"
ls -a /tmp/release/deps
- name: Archive production artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.target }}
path: |
/tmp/release
And this is the layout of the created directory when targeting Windows x86_64 (the only difference when targeting other platforms is the names of the directories within .fingerprint
and build
):
.
├── .cargo-lock
├── .fingerprint/
│ ├── libc-d2565b572b77baea/
│ ├── winapi-619d3257e8f28792/
│ └── winapi-x86_64-pc-windows-gnu-7e7040207fbb5417/
├── build/
│ ├── libc-d2565b572b77baea/
│ ├── winapi-619d3257e8f28792/
│ └── winapi-x86_64-pc-windows-gnu-7e7040207fbb5417/
├── deps/
│ └── <empty>
├── examples/
│ └── <empty>
└── incremental/
└── <empty>
As you can see, there is no binary, and this is reflected in the uploaded artifact.
What is causing this?
EDIT 1
The program builds fine on my local device. My .cargo/config.toml
is below.
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
And this is my Cargo.toml
:
[package]
name = "brainfuck"
version = "0.4.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
console = "0.15.2"
either = "1.8.0"
EDIT 2
While messing around in a test repo, I discovered that this issue only arises when specifying the target. If I don’t specify a target and just use the default system target, I get a binary as expected.
It turns out I didn’t read the cargo docs properly. The build cache docs mention that the results of a build with a specified target are stored in target/<triple>/debug/
, and that is indeed where they were.