Skip to content

Commit

Permalink
fix: build bin for different arch
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed Oct 21, 2024
1 parent 6f83e4b commit e64a3eb
Show file tree
Hide file tree
Showing 7 changed files with 707 additions and 50 deletions.
11 changes: 10 additions & 1 deletion .github/actions/install-tools/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ runs:
node-version: 20

- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: rustfmt, clippy
targets: |
x86_64-unknown-linux-gnu
aarch64-unknown-linux-gnu
x86_64-apple-darwin
aarch64-apple-darwin
x86_64-pc-windows-msvc
- name: Install pnpm
uses: pnpm/action-setup@v4
Expand Down
105 changes: 102 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,102 @@ on:
workflow_dispatch:

jobs:
build-binaries:
name: Build Binaries
runs-on: ${{ matrix.platform }}

strategy:
matrix:
platform: [ubuntu-latest, windows-latest, macos-latest]
arch:
- x64
- arm64
exclude:
- platform: windows-latest
arch: arm64

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install Tools
uses: ./.github/actions/install-tools

- name: Set up MSVC Environment
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{ matrix.arch }}

- name: Fix Path to Avoid Wrong link.exe
if: runner.os == 'Windows'
run: |
echo "PATH before: $env:Path"
$env:Path = [System.String]::Join(';', ($env:Path -split ';' | Where-Object {$_ -notmatch 'C:\\Program Files\\Git\\usr\\bin'}))
echo "PATH after: $env:Path"
- name: Install Cross
if: runner.os != 'Windows'
run: cargo install cross --locked

- name: Build Binaries
run: |
echo "Building for ${{ matrix.platform }} on architecture ${{ matrix.arch }}"
if [[ "${{ matrix.platform }}" == "ubuntu-latest" ]]; then
if [[ "${{ matrix.arch }}" == "x64" ]]; then
cross build --release --target x86_64-unknown-linux-gnu
elif [[ "${{ matrix.arch }}" == "arm64" ]]; then
cross build --release --target aarch64-unknown-linux-gnu
fi
elif [[ "${{ matrix.platform }}" == "macos-latest" ]]; then
if [[ "${{ matrix.arch }}" == "x64" ]]; then
cross build --release --target x86_64-apple-darwin
elif [[ "${{ matrix.arch }}" == "arm64" ]]; then
cross build --release --target aarch64-apple-darwin
fi
elif [[ "${{ matrix.platform }}" == "windows-latest" ]]; then
if [[ "${{ matrix.arch }}" == "x64" ]]; then
cargo build --release --target x86_64-pc-windows-msvc
fi
fi
shell: bash

- name: Move Binaries to Bin Folder
run: |
if [[ "${{ matrix.platform }}" == "windows-latest" ]]; then
mkdir -p ./bin/windows/x64
cp target/x86_64-pc-windows-msvc/release/todoctor.exe ./bin/windows/x64/todoctor.exe
elif [[ "${{ matrix.platform }}" == "ubuntu-latest" ]]; then
if [[ "${{ matrix.arch }}" == "x64" ]]; then
mkdir -p ./bin/linux/x64
cp target/x86_64-unknown-linux-gnu/release/todoctor ./bin/linux/x64/todoctor
elif [[ "${{ matrix.arch }}" == "arm64" ]]; then
mkdir -p ./bin/linux/arm64
cp target/aarch64-unknown-linux-gnu/release/todoctor ./bin/linux/arm64/todoctor
fi
elif [[ "${{ matrix.platform }}" == "macos-latest" ]]; then
if [[ "${{ matrix.arch }}" == "x64" ]]; then
mkdir -p ./bin/macos/x64
cp target/x86_64-apple-darwin/release/todoctor ./bin/macos/x64/todoctor
elif [[ "${{ matrix.arch }}" == "arm64" ]]; then
mkdir -p ./bin/macos/arm64
cp target/aarch64-apple-darwin/release/todoctor ./bin/macos/arm64/todoctor
fi
fi
shell: bash

- name: Upload Binaries
uses: actions/upload-artifact@v4
with:
name: todoctor-${{ matrix.platform }}-${{ matrix.arch }}
path: ./bin/${{ matrix.platform }}/${{ matrix.arch }}/

release:
name: Release
runs-on: ubuntu-latest
needs: build-binaries

steps:
- name: Checkout
Expand All @@ -21,10 +114,16 @@ jobs:
uses: ./.github/actions/install-tools

- name: Install Dependencies
uses: ./.github/actions/install-dependencies
run: pnpm install

- name: Build Package
run: pnpm run build
- name: Build Static Assets
run: pnpm run build:preview

- name: Download Binaries
uses: actions/download-artifact@v4
with:
name: 'todoctor-*'
path: .

- name: Create GitHub Release
run: pnpm run ci:changelog
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ target/
# Build
dist/
bin/
!bin/install.js

# Editor
.vscode/
Expand Down
Loading

0 comments on commit e64a3eb

Please sign in to comment.