name: Rust CI
on:
workflow_dispatch:
jobs:
build-1:
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64_i686-pc-installer
- os: windows-latest
target: x86_64-pc-windows-msvc
- os: windows-latest
target: i686-pc-windows-msvc
max-parallel: 3
runs-on: ${{ matrix.os }}
outputs:
version: ${{ steps.read.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Read Cargo.toml Version
id: read
shell: bash
run: |
VERSION=$(awk -F ' *= *' '/^version/ {gsub(/"/, "", $2); print $2; exit}' Cargo.toml)
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Setup Rust
if: matrix.os == 'windows-latest'
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Cache Rust dependencies
if: matrix.os == 'windows-latest'
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-rust-${{ matrix.target }}-${{ hashFiles('Cargo.lock') }}
restore-keys: |
${{ runner.os }}-rust-${{ matrix.target }}-
- name: Build
if: matrix.os == 'windows-latest'
shell: bash
run: |
cargo build --release --target ${{ matrix.target }}
mkdir -p artifacts
cp target/${{ matrix.target }}/release/openjlc.exe artifacts/openjlc-${{ matrix.target }}.exe
- name: Setup Go for Installer
if: matrix.target == 'x86_64_i686-pc-installer'
uses: actions/setup-go@v5
with:
go-version: 'stable'
- name: Cache Go modules
if: matrix.target == 'x86_64_i686-pc-installer'
uses: actions/cache@v4
with:
path: |
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('installer/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install Go dependencies and Mingw-w64
if: matrix.target == 'x86_64_i686-pc-installer'
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y mingw-w64
go mod tidy
working-directory: installer/
- name: Build Go Installer for Windows
if: matrix.target == 'x86_64_i686-pc-installer'
shell: bash
run: |
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc go build -x -ldflags="-H=windowsgui" -o openjlc-x86_64-i686-pc-installer.exe
mkdir -p ../artifacts
mv openjlc-x86_64-i686-pc-installer.exe ../artifacts/openjlc-x86_64-i686-pc-installer.exe
working-directory: installer/
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: "${{ matrix.target == 'x86_64_i686-pc-installer' && 'openjlc-x86_64-i686-pc-installer' || format('openjlc-{0}', matrix.target) }}"
path: artifacts/
build-2:
needs: build-1
strategy:
matrix:
include:
- os: macos-latest
target: x86_64-apple-darwin
- os: macos-latest
target: aarch64-apple-darwin
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
max-parallel: 3
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Cache Rust dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-rust-${{ matrix.target }}-${{ hashFiles('Cargo.lock') }}
restore-keys: |
${{ runner.os }}-rust-${{ matrix.target }}-
- name: Build
shell: bash
run: |
cargo build --release --target ${{ matrix.target }}
mkdir -p artifacts
if [ "$RUNNER_OS" == "Windows" ]; then
cp target/${{ matrix.target }}/release/openjlc.exe artifacts/openjlc-${{ matrix.target }}.exe
else
cp target/${{ matrix.target }}/release/openjlc artifacts/openjlc-${{ matrix.target }}
fi
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: openjlc-${{ matrix.target }}
path: artifacts/
release:
needs: [build-1, build-2]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
path: artifacts
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.build-1.outputs.version }}
name: v${{ needs.build-1.outputs.version }}
files: |
artifacts/openjlc-x86_64-i686-pc-installer/openjlc-x86_64-i686-pc-installer.exe
artifacts/openjlc-x86_64-unknown-linux-gnu/openjlc-x86_64-unknown-linux-gnu
artifacts/openjlc-x86_64-pc-windows-msvc/openjlc-x86_64-pc-windows-msvc.exe
artifacts/openjlc-i686-pc-windows-msvc/openjlc-i686-pc-windows-msvc.exe
artifacts/openjlc-x86_64-apple-darwin/openjlc-x86_64-apple-darwin
artifacts/openjlc-aarch64-apple-darwin/openjlc-aarch64-apple-darwin