[英]Cargo build artifact produced by GitHub Action does not execute locally
我正在尝试构建一个简单的“Hello World”Rust 程序并使用构建过程的工件创建 GitHub 版本。 使用的工具链是stable-x86_64-unknown-linux-gnu
,在本地运行cargo build
或cargo run
时都没有问题。 可以在此处找到发布本身以及生成的二进制文件。 可以在此处找到 GitHub 操作日志。
该操作能够创建发布,但生成的二进制文件无法在我的系统上执行(Ubuntu 21.10 impish)。 在以下命令中,下载的二进制文件的名称是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
尝试使用chmod u+x x86_64-unknown-linux-gnu
添加权限后,上述命令不会产生 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
我找到了解决方案。 显然,UPX 以某种方式破坏了 Linux 可执行文件。 但是,当我尝试构建 Windows 可执行文件时,UPX 仍然可以正常工作。 为了修复我的 GitHub 操作工作流程,我进行了以下更改:
# 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"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.