Skip to content

Build

Build #234

Workflow file for this run

name: Build
# Complete packaging in the future
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
workflow_dispatch:
permissions: write-all
jobs:
build:
name: Build ${{ matrix.rid }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
rid: [linux-x64, win-x64, macos-arm64]
include:
- rid: linux-x64
rust_target: x86_64-unknown-linux-gnu
os: ubuntu-24.04
qt_arch: gcc_64
- rid: win-x64
msvc_arch: x64
rust_target: x86_64-pc-windows-msvc
vcpkg_target_triplet: 'x64-windows-static-md'
os: windows-latest
- rid: macos-arm64
osx_arch: arm64
rust_target: aarch64-apple-darwin
vcpkg_target_triplet: 'arm64-osx'
os: macos-latest
- rid: macos-x64
osx_arch: x86_64
rust_target: x86_64-apple-darwin
vcpkg_target_triplet: 'x64-osx'
os: macos-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
# Fetch all history for version generation
fetch-depth: 0
fetch-tags: true
- name: Set up GCC
if: startsWith(matrix.rid, 'linux-')
uses: egor-tensin/[email protected]
with:
version: 14
platform: x64
- name: Setup toolchains for building Qt
if: ${{ !matrix.qt_arch }}
shell: pwsh
run: |
if (Get-Command apt-get -ErrorAction SilentlyContinue) {
$deps = 'autoconf', 'automake', 'autoconf-archive', '^libxcb.*-dev',
'libx11-xcb-dev', 'libxrender-dev', 'libxi-dev',
'libxkbcommon-dev', 'libxkbcommon-x11-dev',
'libglu1-mesa-dev', 'libegl1-mesa-dev'
sudo apt-get update
sudo apt-get install -y @deps
} elseif (Get-Command brew -ErrorAction SilentlyContinue) {
$deps = 'autoconf', 'automake', 'autoconf-archive', 'libtool'
brew install @deps
}
- name: Setup libraries for building Slint
if: startsWith(matrix.rid, 'linux-')
run: |
sudo apt-get update
sudo apt-get install -y libfontconfig-dev libfreetype-dev
- name: Install Qt
uses: jurplel/install-qt-action@v4
if: matrix.qt_arch
with:
version: '6.6.3'
arch: ${{ matrix.qt_arch }}
cache: true
- name: Setup Rust toolchain
uses: moonrepo/setup-rust@v1
with:
channel: stable
targets: ${{ matrix.rust_target }}
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Cache corrosion
uses: actions/cache@v4
with:
path: |
${{ github.workspace }}/build/_deps
${{ github.workspace }}/build/*/cargo/build
!${{ github.workspace }}/build/*/cargo/build/**/incremental
${{ github.workspace }}/build/corrosion/**/target
!${{ github.workspace }}/build/corrosion/**/target/**/incremental
key: corrosion-${{ matrix.rid }}
- name: Setup CMake
uses: lukka/get-cmake@latest
- name: Setup vcpkg
uses: lukka/run-vcpkg@v11
with:
vcpkgConfigurationJsonGlob: 'vcpkg-configuration.json'
vcpkgJsonGlob: 'vcpkg.json'
- name: Build
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$rid = '${{ matrix.rid }}'
$vcpkgTargetTriplet = '${{ matrix.vcpkg_target_triplet }}'
$qtArch = '${{ matrix.qt_arch }}'
$osxArch = '${{ matrix.osx_arch }}'
$additionalConfigureArgs = @()
if ($rid.StartsWith('win-')) {
$vsPath = &(Join-Path ${env:ProgramFiles(x86)} "\Microsoft Visual Studio\Installer\vswhere.exe") -property installationpath
Import-Module (Join-Path $vsPath "Common7\Tools\Microsoft.VisualStudio.DevShell.dll")
Enter-VsDevShell -VsInstallPath $vsPath -SkipAutomaticLocation -DevCmdArguments '-arch=${{ matrix.msvc_arch }} -host_arch=x64'
$additionalConfigureArgs += '-DPKG_CONFIG_EXECUTABLE:FILEPATH=./build/vcpkg_installed/x64-windows/tools/pkgconf/pkgconf.exe'
}
if ($osxArch) {
$additionalConfigureArgs += "-DCMAKE_OSX_ARCHITECTURES=$osxArch"
# For https://github.com/rust-skia/rust-skia
$env:CLANGCC = "clang -arch $osxArch"
$env:CLANGCXX = "clang++ -arch $osxArch"
}
if ($vcpkgTargetTriplet) {
$additionalConfigureArgs += "-DVCPKG_TARGET_TRIPLET:STRING=$vcpkgTargetTriplet"
}
if (-not $qtArch) {
$additionalConfigureArgs += "-DVCPKG_MANIFEST_FEATURES=qt-from-vcpkg"
}
$additionalConfigureArgs += "-DRust_CARGO_TARGET=${{ matrix.rust_target }}"
# Install as portable software
$additionalConfigureArgs += '-DCMAKE_INSTALL_LIBDIR=.'
$additionalConfigureArgs += '-DCMAKE_INSTALL_BINDIR=.'
if ($rid.StartsWith('linux-')) {
$additionalConfigureArgs += '-DCMAKE_INSTALL_RPATH=$ORIGIN'
}
if ($rid.StartsWith('macos-')) {
$additionalConfigureArgs += '-DCMAKE_INSTALL_RPATH=@loader_path'
}
cmake --preset native @additionalConfigureArgs
cmake --build --preset native-release
- name: Archive files
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
# Install the built files
cmake --install ./build --prefix ./installed
# Hack: fix install name for `libslint_cpp.so` on macOS
if ('${{ matrix.rid }}'.StartsWith('macos-')) {
# Slint did not set the install dir to `@rpath` when used via FetchContent.
# Do some hack to fix it when packaging.
# https://github.com/slint-ui/slint/blob/461632717a3ffdd1f9e75cfb7cbfce0763dc0129/api/cpp/CMakeLists.txt#L145
$loadCmdsForLibSlint = otool -l ./installed/libslint_cpp.dylib
$idPattern = '\s*cmd\s+LC_ID_DYLIB\s*cmdsize\s+\d+\s*name\s+([^\(\r\n]*?)\s+\(offset \d+\)'
$idMatched = [regex]::Matches($loadCmdsForLibSlint, $idPattern)[0]
if ($idMatched) {
$oldId = $idMatched.Groups[1].Value
echo "Old LC_ID_DYLIB for libslint_cpp.dylib is '$oldId'"
echo "Fixing it to '@rpath/libslint_cpp.dylib'"
install_name_tool -id '@rpath/libslint_cpp.dylib' ./installed/libslint_cpp.dylib
install_name_tool -change $oldId '@rpath/libslint_cpp.dylib' ./installed/sast-evento
}
}
# Remove unnecessary files
Set-Location ./installed
Remove-Item -Force -Recurse ./lib
Remove-Item -Force -Recurse ./include
Remove-Item -Force slint-compiler*
Remove-Item -Force *.lib
Remove-Item -Force *.a
Set-Location ..
# Archive the files
if ('${{ runner.os }}' -eq 'Windows') {
Compress-Archive -Path ./installed/* -DestinationPath ./files.zip
} else {
tar -czf ./files.tar.gz -C ./installed .
}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: files-${{ matrix.rid }}
path: ${{ runner.os != 'Windows' && './files.tar.gz' || './files.zip' }}
package-win:
name: Package ${{ matrix.rid }} (Inno Setup)
runs-on: windows-latest
needs: build
strategy:
fail-fast: false
matrix:
rid: [win-x64]
include:
- rid: win-x64
msvc_arch: x64
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: false
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: files-${{ matrix.rid }}
- name: Extract files
id: extract
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
Expand-Archive -Path ./files.zip -DestinationPath ./files
$version = Get-Content -Path ./files/sast-evento-version.txt
Write-Output "version=$version" >> $Env:GITHUB_OUTPUT
- name: Copy VC Redist
shell: pwsh
run: |
$msvcArch = '${{ matrix.msvc_arch }}'
$vsPath = &(Join-Path ${env:ProgramFiles(x86)} "\Microsoft Visual Studio\Installer\vswhere.exe") -property installationpath
Import-Module (Join-Path $vsPath "Common7\Tools\Microsoft.VisualStudio.DevShell.dll")
Enter-VsDevShell -VsInstallPath $vsPath -SkipAutomaticLocation -DevCmdArguments "-arch=$msvcArch -host_arch=x64"
Copy-Item -Path $env:VCToolsRedistDir\vc_redist.$msvcArch.exe -Destination ./deploy/vcredist.exe
- name: Inno Setup
uses: Minionguyjpro/[email protected]
with:
path: ./deploy/win-installer.iss
options: /O+ /dMyAppVersion=${{ steps.extract.outputs.version }}
- name: Upload installer
uses: actions/upload-artifact@v4
with:
name: installer-${{ matrix.rid }}
path: ./deploy/installer.exe
package-deb:
name: Package ${{ matrix.rid }} (deb)
runs-on: ubuntu-24.04
needs: build
strategy:
fail-fast: false
matrix:
rid: [linux-x64]
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: false
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: files-${{ matrix.rid }}
- name: Extract files
shell: bash
run: |
mkdir -p ./files
tar -xzf ./files.tar.gz -C ./files
- name: Package
shell: bash
run: |
bash ./deploy/create-deb.sh ./files
- name: Upload package
uses: actions/upload-artifact@v4
with:
name: deb-${{ matrix.rid }}
path: ./sast-evento.deb
package-pacman:
name: Package ${{ matrix.rid }} (pacman)
runs-on: ubuntu-24.04
needs: build
strategy:
fail-fast: false
matrix:
rid: [linux-x64]
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: false
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: files-${{ matrix.rid }}
- name: Package
shell: bash
run: |
mv ./files.tar.gz ./deploy/pacman/files.tar.gz
cp ./ui/assets/image/icon/evento.svg ./deploy/pacman/icon.svg
cp ./deploy/sast-evento.desktop ./deploy/pacman/sast-evento.desktop
cat | docker run -i --rm -v $(pwd)/deploy/pacman:/pkg -w /pkg archlinux/archlinux:base-devel /bin/bash -e << EOF
useradd build -m
passwd -d build
printf 'build ALL=(ALL) ALL\n' | tee -a /etc/sudoers
chown -R build:build .
sudo -u build makepkg -f --nodeps --noconfirm
EOF
sudo rm ./deploy/pacman/*-debug-*.pkg.tar.zst
- name: Upload package
uses: actions/upload-artifact@v4
with:
name: pacman-${{ matrix.rid }}
path: ./deploy/pacman/*.pkg.tar.zst
package-macos:
name: Package ${{ matrix.rid }} (dmg)
runs-on: macos-latest
needs: build
strategy:
fail-fast: false
matrix:
rid: [macos-arm64, macos-x64]
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: false
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: files-${{ matrix.rid }}
- name: Extract files
shell: bash
run: |
mkdir -p ./files
tar -xzf ./files.tar.gz -C ./files
- name: Construct macOS app bundle
shell: bash
run: |
bash ./deploy/create-mac-app.sh ./files './sast-evento.app'
- name: Package
uses: L-Super/create-dmg-actions@v1
with:
dmg_name: 'sast-evento'
src_dir: './sast-evento.app'
- name: Upload package
uses: actions/upload-artifact@v4
with:
name: dmg-${{ matrix.rid }}
path: ./sast-evento.dmg
publish-release:
name: Publish release
runs-on: ubuntu-latest
needs:
- package-win
- package-deb
- package-pacman
- package-macos
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
- name: Organize artifacts
shell: bash
run: |
cd "${GITHUB_WORKSPACE}/artifacts" || exit 1
version="unknown"
if [[ -f ./files-linux-x64/files.tar.gz ]]; then
# 解压版本文件
tar -xzf ./files-linux-x64/files.tar.gz ./sast-evento-version.txt
if [[ -f ./sast-evento-version.txt ]]; then
# 设置版本号
version=$(cat ./sast-evento-version.txt)
rm -f ./sast-evento-version.txt
fi
fi
echo "SAST Evento Version: $version"
rm -rf ./files-*
# 处理文件
for dir in */; do
echo "Processing $dir"
new_name="sast-evento-$version-${dir%/}"
mv "$dir" "$new_name"
# Change to the new directory name
items=("$new_name"/*)
if [[ ${#items[@]} -eq 1 && -f ${items[0]} ]]; then
single_file=${items[0]}
if [[ $single_file =~ \.pkg\.tar\.zst$ ]]; then
new_file_path="$new_name.pkg.tar.zst"
else
new_file_path="$new_name.${single_file##*.}"
fi
mv "$single_file" "$new_file_path"
else
zip_path="$new_name.zip"
zip -r "$zip_path" "$new_name"
fi
rm -rf "$new_name"
done
# Generate SHA256 hash and save it to a file
sha256sum * > sha256sums.txt
echo "Artifacts are ready"
ls -lh
- name: Release (GitHub)
uses: ncipollo/release-action@v1
if: github.event_name == 'push' && github.ref_type == 'tag'
with:
artifacts: ./artifacts/*
allowUpdates: true
draft: false
omitBody: true