Skip to content

Commit

Permalink
Build native MinGW toolchain packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Blackhex committed Aug 26, 2024
1 parent a84e6b7 commit 1b18c3b
Show file tree
Hide file tree
Showing 16 changed files with 614 additions and 25 deletions.
20 changes: 13 additions & 7 deletions .github/scripts/build-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ ARGUMENTS="--syncdeps \
$([ "$CLEAN_BUILD" = 1 ] && echo "--cleanbuild" || echo "") \
$([ "$INSTALL_PACKAGE" = 1 ] && echo "--install" || echo "")"

ccache -svv || true
echo "::group::ccache reset"
ccache -z || true
echo "::endgroup::"

if [[ "$PACKAGE_REPOSITORY" == *MINGW* ]]; then
makepkg-mingw $ARGUMENTS
else
makepkg $ARGUMENTS
fi
echo "::group::Build package"
if [[ "$PACKAGE_REPOSITORY" == *MINGW* ]]; then
makepkg-mingw $ARGUMENTS
else
makepkg $ARGUMENTS
fi
echo "::endgroup::"

ccache -svv || true
echo "::group::ccache results"
ccache -svv || true
echo "::endgroup::"
10 changes: 6 additions & 4 deletions .github/scripts/download-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ set -x # echo on
set -o pipefail # fail of any command in pipeline is an error

RUN_ID=$1
NEEDS=`echo "$2" | /mingw64/bin/jq 'keys|join(" ")' | sed 's/"//g'`

for NEED in $NEEDS; do
echo "Downloading $NEED artifact."
/mingw64/bin/gh run download $RUN_ID -n $NEED
for ARG in "${@:2}"; do
NEEDS=`echo "$ARG" | /mingw64/bin/jq 'keys|join(" ")' | sed 's/"//g'`
for NEED in $NEEDS; do
echo "Downloading $NEED artifact."
/mingw64/bin/gh run download $RUN_ID -n $NEED
done
done
18 changes: 17 additions & 1 deletion .github/scripts/enable-ccache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ set -e # exit on error
set -x # echo on
set -o pipefail # fail of any command in pipeline is an error

CCACHE_DIR=$DIR/ccache

DIR="`dirname ${BASH_SOURCE[0]}`/../.."
DIR=`realpath $DIR`
if [[ -n "$GITHUB_WORKSPACE" ]]; then
echo "CCACHE_DIR=$DIR/ccache" >> "$GITHUB_ENV"
echo "CCACHE_DIR=$CCACHE_DIR" >> "$GITHUB_ENV"
echo timestamp=$(date -u --iso-8601=seconds) >> "$GITHUB_OUTPUT"
fi

mkdir -p $CCACHE_DIR

pushd /
echo "::group::/etc/makepkg.conf"
patch -p1 -b -i "$DIR/patches/ccache/0001-makepkg.patch"
Expand All @@ -22,3 +26,15 @@ pushd /
cat /etc/makepkg_mingw.conf
echo "::endgroup::"
popd

pacman -S --noconfirm ccache

pushd /usr/lib/ccache/bin
echo "::group::Add aarch64 toolchain to ccache"
export MSYS=winsymlinks
ln -sf /usr/bin/ccache aarch64-w64-mingw32-c++
ln -sf /usr/bin/ccache aarch64-w64-mingw32-g++
ln -sf /usr/bin/ccache aarch64-w64-mingw32-gcc
ls -al
echo "::endgroup::"
popd
36 changes: 36 additions & 0 deletions .github/scripts/pacman-workaround.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

set -e # exit on error
set -x # echo on
set -o pipefail # fail of any command in pipeline is an error

if [ -z "$GITHUB_WORKSPACE" ]; then
DIR=`pwd`
else
DIR=`cygpath "$GITHUB_WORKSPACE"`
fi

echo "::group::Pacman hang workaround"
while ! timeout -k 15s 10s pacman -U --noconfirm "$DIR/patches/pacman/pacman-6.1.0-4-x86_64.pkg.tar.zst"
do
echo "Command failed, retrying..."
done
echo "::endgroup::"

echo "::group::Install patch"
pacman -S --noconfirm patch
echo "::endgroup::"

pushd /
echo "::group::Pin pacman packages"
patch -p1 -b -i "$DIR/patches/pacman/0001-pin-pacman.patch"
echo "::endgroup::"

echo "::group::/etc/pacman.conf"
cat /etc/pacman.conf
echo "::endgroup::"
popd

echo "::group::Update packages"
pacman -Syuu --noconfirm
echo "::endgroup::"
36 changes: 36 additions & 0 deletions .github/scripts/setup-cross-compilation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

set -e # exit on error
set -x # echo on
set -o pipefail # fail of any command in pipeline is an error

if [ -z "$GITHUB_WORKSPACE" ]; then
DIR=`pwd`
else
DIR=`cygpath "$GITHUB_WORKSPACE"`
fi

echo "::group::Install patch"
pacman -S --noconfirm patch
echo "::endgroup::"

pushd /
echo "::group::Patch MSYS2 environment"
patch -p1 -b -i "$DIR/patches/makepkg/0001-cross-compilation.patch"
if [[ "$DEBUG" = "1" ]]; then
patch -p1 -b -i "$DIR/patches/makepkg/0002-enable-debug.patch"
fi
echo "::endgroup::"

echo "::group::/etc/makepkg_mingw.conf"
cat /etc/makepkg_mingw.conf
echo "::endgroup::"

echo "::group::/etc/profile"
cat /etc/profile
echo "::endgroup::"

echo "::group::/usr/share/makepkg/tidy/strip.sh"
cat /usr/share/makepkg/tidy/strip.sh
echo "::endgroup::"
popd
62 changes: 54 additions & 8 deletions .github/workflows/build-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,71 @@ defaults:

env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CLEAN_BUILD: 1

jobs:
build:
name: Build ${{ inputs.package_name }}
runs-on: windows-latest
runs-on: ${{ fromJson(contains(inputs.packages_repository, 'MINGW') && '["Windows", "ARM64", "Blackhex"]' || '["windows-latest"]') }}

steps:
- name: Kill hanging processes
shell: powershell
run: |
tasklist
taskkill /t /f /im conftest.exe
taskkill /t /f /im expect.exe
taskkill /t /f /im cc1.exe
taskkill /t /f /im pacman.exe
taskkill /t /f /im make.exe
taskkill /t /f /im wc.exe
taskkill /t /f /im gpg.exe
taskkill /t /f /im gpg-agent.exe
taskkill /t /f /im bash.exe
taskkill /t /f /im sh.exe
Set-Location "${{ github.workspace }}"
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue -Path packages
tasklist
exit 0
- name: Fix Git long paths
shell: powershell
run: |
git config --global core.longpaths true
- name: Fix $PATH
shell: powershell
run: |
Write-Output "GITHUB_PATH: $env:GITHUB_PATH"
Write-Output "C:\Program Files\Git\usr\bin\" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- uses: msys2/setup-msys2@v2
timeout-minutes: 10
with:
msystem: ${{ contains(inputs.packages_repository, 'MINGW') && 'MINGW64' || 'MSYS' }}
update: false
cache: false

- name: Checkout repository
uses: actions/checkout@v4

- name: Pacman hang workaround
run: |
`cygpath "${{ github.workspace }}"`/.github/scripts/pacman-workaround.sh
- name: Setup packages repository
run: |
`cygpath "${{ github.workspace }}"`/.github/scripts/setup-repository.sh
- name: Install dependencies
run: |
pacman -S --noconfirm \
git \
mingw-w64-x86_64-github-cli \
mingw-w64-x86_64-jq \
base-devel \
${{ contains(inputs.packages_repository, 'MINGW') && 'mingw-w64-cross-gcc mingw-w64-x86_64-ccache' || ' ccache' }} \
${{ contains(inputs.packages_repository, 'MINGW') &&
'mingw-w64-cross-gcc mingw-w64-cross-windows-default-manifest mingw-w64-x86_64-gcc-libs' || '' }} \
${{ inputs.dependencies }}
- name: Download artifacts
Expand All @@ -75,6 +118,11 @@ jobs:
sparse-checkout: ${{ inputs.package_name }}
path: ${{ github.workspace }}/packages

- name: Setup cross-compilation environment
if: ${{ contains(inputs.packages_repository, 'MINGW') }}
run: |
`cygpath "${{ github.workspace }}"`/.github/scripts/setup-cross-compilation.sh
- name: Enable Ccache
id: enable-ccache
run: |
Expand All @@ -84,22 +132,20 @@ jobs:
uses: actions/cache/restore@v4
with:
path: ${{ github.workspace }}/ccache
key: main-ccache-${{ steps.enable-ccache.outputs.timestamp }}
restore-keys: main-ccache-
key: ${{ inputs.package_name }}-ccache-${{ steps.enable-ccache.outputs.timestamp }}
restore-keys: ${{ inputs.package_name }}-ccache

- name: Build ${{ inputs.package_name }}
working-directory: ${{ github.workspace }}/packages/${{ inputs.package_name }}
run: |
ccache -svv || true
`cygpath "${{ github.workspace }}"`/.github/scripts/build-package.sh ${{ inputs.packages_repository }}
ccache -svv || true
- name: Save Ccache
if: always()
uses: actions/cache/save@v4
uses: actions/cache/save@v4
with:
path: ${{ github.workspace }}/ccache
key: main-ccache-${{ steps.enable-ccache.outputs.timestamp }}
key: ${{ inputs.package_name }}-ccache-${{ steps.enable-ccache.outputs.timestamp }}

- name: Upload ${{ inputs.package_name }}
uses: actions/upload-artifact@v4
Expand Down
22 changes: 19 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ on:
type: string
required: false
default: "woarm64"
mingw_packages_branch:
description: "MINGW-packages branch to build"
type: string
required: false
default: "woarm64"

jobs:
mingw-cross-toolchain:
Expand All @@ -20,9 +25,18 @@ jobs:
with:
msys2_packages_branch: ${{ inputs.msys2_packages_branch || 'woarm64' }}

mingw-native-toolchain:
name: MinGW native toolchain
uses: ./.github/workflows/mingw-native-toolchain.yml
with:
mingw_packages_branch: ${{ inputs.mingw_packages_branch || 'woarm64' }}

repository:
name: Create MSYS2 repository
needs: mingw-cross-toolchain
needs: [
mingw-cross-toolchain,
mingw-native-toolchain
]
runs-on: windows-latest

defaults:
Expand Down Expand Up @@ -50,8 +64,10 @@ jobs:
- name: Download artifacts
run: |
`cygpath "${{ github.workspace }}"`/.github/scripts/download-artifacts.sh ${{ github.run_id }} \
'${{ needs.mingw-cross-toolchain.outputs.artifacts }}'
`cygpath "${{ github.workspace }}"`/.github/scripts/download-artifacts.sh \
${{ github.run_id }} \
'${{ needs.mingw-cross-toolchain.outputs.artifacts }}' \
'${{ needs.mingw-native-toolchain.outputs.artifacts }}'
- name: Setup MSYS2 packages repository
run: |
Expand Down
Loading

0 comments on commit 1b18c3b

Please sign in to comment.