I am trying to build a simple "Hello World" Rust program and create a GitHub release using an artifact of the build process. The toolchain being used is stable-x86_64-unknown-linux-gnu
, which has no problems when running cargo build
or cargo run
locally. The release itself, along with the produced binary, can be found here. The GitHub Action logs can be found here.
The action is able to create the release, but the produced binary does not execute on my system (Ubuntu 21.10 impish). In the following commands, the name of the downloaded binary is x86_64-unknown-linux-gnu
.
$ bash x86_64-unknown-linux-gnu
x86_64-unknown-linux-gnu: x86_64-unknown-linux-gnu: cannot execute binary file
$ ./x86_64-unknown-linux-gnu
bash: ./x86_64-unknown-linux-gnu: Permission denied
After trying to add permissions using chmod u x x86_64-unknown-linux-gnu
, the above command produces no output.
$ file x86_64-unknown-linux-gnu
x86_64-unknown-linux-gnu: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=cb612cdcb3dfb4866238c50e96b9799037e427a2, for GNU/Linux 3.2.0, with debug_info, not stripped
$ file /lib/systemd/systemd
/lib/systemd/systemd: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=055a1b9666c7d1677a2942d46ca47e59fe75dae5, for GNU/Linux 3.2.0, stripped
$ uname -m
x86_64
src/main.rs:
fn main() {
println!("Hello, world!");
}
.github/workflows/release.yml:
name: Release
on:
push:
branches:
- main
env:
ACTIONS_STEP_DEBUG: true
PROJECT_NAME: color_difference
jobs:
linux:
strategy:
matrix:
os: [ubuntu-latest]
rust:
- stable
runs-on: ${{ matrix.os }}
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
profile: minimal
- name: Set up cache
uses: actions/cache@v2
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Build sources
uses: actions-rs/cargo@v1
with:
command: build
args: --release
- name: Run UPX
uses: crazy-max/ghaction-upx@v1
with:
version: latest
files: target/release/${{ env.PROJECT_NAME }}
args: --brute
- name: Rename file
run: cp target/release/${{ env.PROJECT_NAME }} x86_64-unknown-linux-gnu
- name: Release with artifacts
uses: ncipollo/release-action@v1
with:
name: Release
tag: latest
token: ${{ secrets.GITHUB_TOKEN }}
commit: ${{ github.sha }}
artifacts: x86_64-unknown-linux-gnu
CodePudding user response:
I found a solution. Apparently, UPX somehow breaks the Linux executable. However, when I tried to build a Windows executable, UPX still worked fine. In order to fix my GitHub Action workflow, I made the following changes:
# old
- name: Run UPX
uses: crazy-max/ghaction-upx@v1
with:
version: latest
files: target/release/${{ env.PROJECT_NAME }}
args: --brute
# new
- name: Strip artifact
run: strip target/release/${{ env.PROJECT_NAME }}
- name: Run UPX
run: echo "Not supported on linux platform"