Skip to content

Commit

Permalink
ci(fix): try to fix cross compilation workflow
Browse files Browse the repository at this point in the history
- removed Cross.toml
- add custom Dockerfile
- change workflow to build with custom Dockerfile
  • Loading branch information
255doesnotexist committed Oct 11, 2024
1 parent 44f005c commit 820c5c7
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 90 deletions.
65 changes: 27 additions & 38 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
name: Nightly Release
name: Cross Compilation

on:
schedule:
- cron: '0 0 * * *'
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
build-and-release:
build:
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -21,39 +23,30 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- name: Install cross
run: cargo install cross
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build for ${{ matrix.target }}
run: cross build --release --target ${{ matrix.target }}

- name: Get current date
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: false
load: true
tags: rust-cross-compile:latest

- name: Prepare artifact
- name: Cross compile
run: |
mkdir -p ./artifacts
if [[ "${{ matrix.target }}" == *"-windows-"* ]]; then
cp ./target/${{ matrix.target }}/release/lintestor.exe ./artifacts/lintestor-${{ matrix.target }}.exe
else
cp ./target/${{ matrix.target }}/release/lintestor ./artifacts/lintestor-${{ matrix.target }}
fi
docker run --rm -v ${{ github.workspace }}:/root/src rust-cross-compile:latest \
sh -c "cd /root/src && cargo build --release --target ${{ matrix.target }}"
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: lintestor-${{ matrix.target }}
path: ./artifacts/*
path: target/${{ matrix.target }}/release/lintestor

create-release:
needs: build-and-release
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -68,23 +61,19 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: nightly-${{ steps.date.outputs.date }}
release_name: Nightly Release ${{ steps.date.outputs.date }}
body: |
This is an automated multi-architecture nightly release of Lintestor.
**Note:** These builds may be unstable and are not recommended for production use.
tag_name: release-${{ steps.date.outputs.date }}
release_name: Release ${{ steps.date.outputs.date }}
draft: false
prerelease: true
prerelease: false

- name: Download all artifacts
uses: actions/download-artifact@v4
uses: actions/download-artifact@v2
with:
path: ./artifacts
path: artifacts

- name: Upload Release Assets
run: |
for artifact in ./artifacts/lintestor-*/lintestor-*; do
for artifact in artifacts/lintestor-*/*; do
asset_name=$(basename "$artifact")
echo "Uploading $asset_name"
curl -L \
Expand All @@ -94,4 +83,4 @@ jobs:
-H "Content-Type: application/octet-stream" \
"https://uploads.github.com/repos/${{ github.repository }}/releases/${{ steps.create_release.outputs.id }}/assets?name=${asset_name}" \
--data-binary "@$artifact"
done
done
52 changes: 0 additions & 52 deletions Cross.toml

This file was deleted.

68 changes: 68 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# 使用 ubuntu:latest 作为基础镜像
FROM ubuntu:latest

# 避免在构建过程中出现交互式提示
ENV DEBIAN_FRONTEND=noninteractive

# 安装必要的软件包和交叉编译工具链
RUN apt-get update && apt-get install -y \
software-properties-common \
&& add-apt-repository ppa:ubuntu-toolchain-r/test \
&& apt-get update && apt-get install -y \
build-essential \
curl \
git \
libssl-dev \
pkg-config \
cmake \
gcc-14 \
g++-14 \
gcc-14-aarch64-linux-gnu \
g++-14-aarch64-linux-gnu \
gcc-14-arm-linux-gnueabihf \
g++-14-arm-linux-gnueabihf \
gcc-14-riscv64-linux-gnu \
g++-14-riscv64-linux-gnu \
gcc-14-powerpc64-linux-gnu \
g++-14-powerpc64-linux-gnu \
gcc-14-i686-linux-gnu \
g++-14-i686-linux-gnu \
libc6-dev-i386 \
&& rm -rf /var/lib/apt/lists/*

# 设置 GCC 14 为默认版本
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 100 \
&& update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 100

WORKDIR /root

# 安装 Rust
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain nightly

# 将 Rust 二进制文件添加到 PATH
ENV PATH="/root/.cargo/bin:${PATH}"

# 添加所有目标架构
RUN rustup target add \
x86_64-unknown-linux-gnu \
i686-unknown-linux-gnu \
aarch64-unknown-linux-gnu \
armv7-unknown-linux-gnueabihf \
riscv64gc-unknown-linux-gnu \
powerpc64-unknown-linux-gnu

# 配置 Cargo 以使用正确的链接器
RUN mkdir -p ~/.cargo && echo '\
[target.aarch64-unknown-linux-gnu]\n\
linker = "aarch64-linux-gnu-gcc-14"\n\
[target.armv7-unknown-linux-gnueabihf]\n\
linker = "arm-linux-gnueabihf-gcc-14"\n\
[target.riscv64gc-unknown-linux-gnu]\n\
linker = "riscv64-linux-gnu-gcc-14"\n\
[target.powerpc64-unknown-linux-gnu]\n\
linker = "powerpc64-linux-gnu-gcc-14"\n\
[target.i686-unknown-linux-gnu]\n\
linker = "i686-linux-gnu-gcc-14"' > ~/.cargo/config.toml

# 设置默认命令
CMD ["/bin/bash"]

0 comments on commit 820c5c7

Please sign in to comment.