我正在嘗試構建一個簡單的“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,上述命令不產生任何輸出。
$ 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
uj5u.com熱心網友回復:
我找到了解決方案。顯然,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"
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/407807.html
標籤:
上一篇:如果名稱重復,如何洗掉最小的檔案
