gpt4 book ai didi

ubuntu - GitHub Action 生成的 Cargo 构建工件不在本地执行

转载 作者:行者123 更新时间:2023-12-04 19:26:16 25 4
gpt4 key购买 nike

我正在尝试构建一个简单的“Hello World”Rust 程序并使用构建过程的工件创建一个 GitHub 版本。正在使用的工具链是 stable-x86_64-unknown-linux-gnu ,运行时没有问题cargo buildcargo run本地。可以在 here 中找到发布本身以及生成的二进制文件。 .可以找到 GitHub 操作日志 here .
该操作能够创建发布,但生成的二进制文件无法在我的系统上执行(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 添加权限后,上面的命令不产生任何输出。
$ 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 Action 工作流程,我进行了以下更改:

# 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"

关于ubuntu - GitHub Action 生成的 Cargo 构建工件不在本地执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70634532/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com