Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Verify all release targets build (no packaging). Run on push to main and on pull_request.
name: Build (all targets)

on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

env:
BINARY_NAME: proxy-convert
RUST_BACKTRACE: 1

jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.runner || matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
- os: macos-14
target: x86_64-apple-darwin
- os: macos-14
target: aarch64-apple-darwin
- os: windows-latest
target: x86_64-pc-windows-msvc
- os: windows-latest
target: aarch64-pc-windows-msvc
runner: windows-11-arm

steps:
- uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
targets: ${{ matrix.target }}

- name: Cache cargo
uses: Swatinem/rust-cache@v2.8.2
with:
key: ${{ matrix.target }}

- name: Install Linux deps (glibc cross)
if: matrix.os == 'ubuntu-latest' && matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libc6-dev-arm64-cross binutils-aarch64-linux-gnu

- name: Set env for Linux aarch64 cross
if: matrix.os == 'ubuntu-latest' && matrix.target == 'aarch64-unknown-linux-gnu'
run: |
echo "CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
echo "CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++" >> $GITHUB_ENV
echo "AR_aarch64_unknown_linux_gnu=aarch64-linux-gnu-ar" >> $GITHUB_ENV
echo "RANLIB_aarch64_unknown_linux_gnu=aarch64-linux-gnu-ranlib" >> $GITHUB_ENV
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV

- name: Install musl (x86_64)
if: matrix.os == 'ubuntu-latest' && matrix.target == 'x86_64-unknown-linux-musl'
run: sudo apt-get update && sudo apt-get install -y musl-tools

- name: Set env for musl (x86_64)
if: matrix.os == 'ubuntu-latest' && matrix.target == 'x86_64-unknown-linux-musl'
run: echo "CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=musl-gcc" >> $GITHUB_ENV

- name: Build
run: cargo build --release --target ${{ matrix.target }} --verbose

- name: Test binary
shell: bash
run: |
if [ "${{ matrix.os }}" = "windows-latest" ]; then
exe="target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}.exe"
else
exe="target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}"
fi
if [ ! -f "$exe" ]; then
echo "Binary not found: $exe"
exit 1
fi
# Only run binary on native target (cross-compiled binaries cannot run on host)
if [ "${{ matrix.os }}" = "ubuntu-latest" ] && [ "${{ matrix.target }}" = "x86_64-unknown-linux-gnu" ]; then
"$exe" --version
elif [ "${{ matrix.os }}" = "windows-latest" ] && { [ "${{ matrix.target }}" = "x86_64-pc-windows-msvc" ] || [ "${{ matrix.target }}" = "aarch64-pc-windows-msvc" ]; }; then
"$exe" --version
elif [ "${{ matrix.os }}" = "macos-14" ] && [ "${{ matrix.target }}" = "aarch64-apple-darwin" ]; then
"$exe" --version
else
echo "Skipping execution (cross-compiled target)."
fi
141 changes: 80 additions & 61 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,105 +5,125 @@ on:
tags:
- 'v*'

env:
BINARY_NAME: proxy-convert
RUST_BACKTRACE: 1

jobs:
build:
name: Build on ${{ matrix.os }} - ${{ matrix.target }}
runs-on: ${{ matrix.os }}
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.runner || matrix.os }}
strategy:
fail-fast: false
matrix:
include:
# Linux glibc + musl static
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
# - os: ubuntu-latest
# target: aarch64-unknown-linux-gnu
- os: macos-latest
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
# macOS
- os: macos-14
target: x86_64-apple-darwin
- os: macos-latest
- os: macos-14
target: aarch64-apple-darwin
# Windows (aarch64 使用 windows-11-arm runner,os 名称仍为 windows-latest)
- os: windows-latest
target: x86_64-pc-windows-msvc
- os: windows-latest
target: aarch64-pc-windows-msvc
runner: windows-11-arm

steps:
- name: Checkout code
- name: Checkout
uses: actions/checkout@v4

- name: Install system dependencies (Ubuntu only)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y build-essential
sudo apt-get install -y libssl-dev
if [ "${{ matrix.target }}" == "aarch64-unknown-linux-gnu" ]; then
sudo apt-get install -y gcc-aarch64-linux-gnu
sudo apt-get install -y g++-aarch64-linux-gnu
sudo apt-get install -y libc6-dev-arm64-cross
fi
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
targets: ${{ matrix.target }}

- name: Cache cargo
uses: Swatinem/rust-cache@v2.8.2
with:
key: ${{ matrix.target }}
shared-key: release

- name: Set up Rust
- name: Install Linux deps (glibc cross)
if: matrix.os == 'ubuntu-latest' && matrix.target == 'aarch64-unknown-linux-gnu'
run: |
rustup update stable
rustup target add ${{ matrix.target }}
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libc6-dev-arm64-cross binutils-aarch64-linux-gnu

- name: Set environment variables for ARM cross-compilation (Ubuntu only)
- name: Set env for Linux aarch64 cross (glibc)
if: matrix.os == 'ubuntu-latest' && matrix.target == 'aarch64-unknown-linux-gnu'
run: |
echo "CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
echo "CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++" >> $GITHUB_ENV
echo "AR_aarch64_unknown_linux_gnu=aarch64-linux-gnu-ar" >> $GITHUB_ENV
echo "RANLIB_aarch64_unknown_linux_gnu=aarch64-linux-gnu-ranlib" >> $GITHUB_ENV
echo "PKG_CONFIG_ALLOW_CROSS=1" >> $GITHUB_ENV
echo "PKG_CONFIG_SYSROOT_DIR=/usr/aarch64-linux-gnu" >> $GITHUB_ENV
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV

- name: Build project
- name: Install musl (Linux static, x86_64 only)
if: matrix.os == 'ubuntu-latest' && matrix.target == 'x86_64-unknown-linux-musl'
run: sudo apt-get update && sudo apt-get install -y musl-tools

- name: Set env for musl (x86_64)
if: matrix.os == 'ubuntu-latest' && matrix.target == 'x86_64-unknown-linux-musl'
run: echo "CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=musl-gcc" >> $GITHUB_ENV

- name: Build
run: cargo build --release --target ${{ matrix.target }} --verbose

- name: Test binary
shell: bash
run: |
if [ "${{ matrix.os }}" == "windows-latest" ]; then
binary_path=$(find target/${{ matrix.target }}/release -maxdepth 1 -type f -name "*.exe" | head -n 1)
if [ "${{ matrix.os }}" = "windows-latest" ]; then
exe="target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}.exe"
else
binary_path=$(find target/${{ matrix.target }}/release -maxdepth 1 -type f \( -perm -u=x -o -perm -g=x -o -perm -o=x \) | head -n 1)
exe="target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}"
fi
if [ -n "$binary_path" ]; then
$binary_path --version
else
echo "No executable binary found."
if [ ! -f "$exe" ]; then
echo "Binary not found: $exe"
exit 1
fi
shell: bash
env:
RUST_BACKTRACE: 1
# Only run binary on native target (cross-compiled binaries cannot run on host)
if [ "${{ matrix.os }}" = "ubuntu-latest" ] && [ "${{ matrix.target }}" = "x86_64-unknown-linux-gnu" ]; then
"$exe" --version
elif [ "${{ matrix.os }}" = "windows-latest" ] && { [ "${{ matrix.target }}" = "x86_64-pc-windows-msvc" ] || [ "${{ matrix.target }}" = "aarch64-pc-windows-msvc" ]; }; then
"$exe" --version
elif [ "${{ matrix.os }}" = "macos-14" ] && [ "${{ matrix.target }}" = "aarch64-apple-darwin" ]; then
"$exe" --version
else
echo "Skipping execution (cross-compiled target)."
fi

- name: Package binary
- name: Package
shell: bash
run: |
if [ "${{ matrix.os }}" == "windows-latest" ]; then
binary_path=$(find target/${{ matrix.target }}/release -maxdepth 1 -type f -name "*.exe" | head -n 1)
binary_name=$(basename "$binary_path")
if [ "${{ matrix.os }}" = "windows-latest" ]; then
exe="target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}.exe"
out="${{ env.BINARY_NAME }}-${{ matrix.target }}.zip"
mkdir -p release
cp "$exe" release/
(cd release && 7z a "$out" "${{ env.BINARY_NAME }}.exe")
else
binary_path=$(find target/${{ matrix.target }}/release -maxdepth 1 -type f \( -perm -u=x -o -perm -g=x -o -perm -o=x \) | head -n 1)
binary_name=$(basename "$binary_path")
exe="target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}"
out="${{ env.BINARY_NAME }}-${{ matrix.target }}.tar.gz"
mkdir -p release
cp "$exe" release/
(cd release && tar czvf "$out" "${{ env.BINARY_NAME }}")
fi
mkdir -p ./release
cp "$binary_path" release/"$binary_name"
cd release
if [ "${{ matrix.os }}" == "windows-latest" ]; then
7z a "$binary_name-${{ matrix.target }}.zip" "$binary_name"
echo "Packaged file: ./release/$binary_name-${{ matrix.target }}.zip"
else
tar czvf "$binary_name-${{ matrix.target }}.tar.gz" "$binary_name"
echo "Packaged file: ./release/$binary_name-${{ matrix.target }}.tar.gz"
fi
cd ..

echo "PACKAGE_PATH=release/$out" >> $GITHUB_ENV

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
path: |
release/*.zip
release/*.tar.gz
if-no-files-found: error
path: ${{ env.PACKAGE_PATH }}

release:
name: Create Release
Expand All @@ -113,13 +133,12 @@ jobs:
contents: write

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

- name: Create Release
id: create_release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -129,5 +148,5 @@ jobs:
draft: false
prerelease: false
files: |
artifacts/**/*.zip
artifacts/**/*.tar.gz
artifacts/*/*.tar.gz
artifacts/*/*.zip
Loading