Skip to content

Commit c3fab98

Browse files
committed
Build native MinGW toolchain packages
1 parent 83f80ed commit c3fab98

21 files changed

+853
-155
lines changed

.github/scripts/build-package.sh

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,18 @@ ARGUMENTS="--syncdeps \
2121
$([ "$CLEAN_BUILD" = 1 ] && echo "--cleanbuild" || echo "") \
2222
$([ "$INSTALL_PACKAGE" = 1 ] && echo "--install" || echo "")"
2323

24-
ccache -svv || true
24+
echo "::group::Ccache statistics before build"
25+
ccache -svv || true
26+
echo "::endgroup::"
2527

26-
if [[ "$PACKAGE_REPOSITORY" == *MINGW* ]]; then
27-
makepkg-mingw $ARGUMENTS
28-
else
29-
makepkg $ARGUMENTS
30-
fi
28+
echo "::group::Build package"
29+
if [[ "$PACKAGE_REPOSITORY" == *MINGW* ]]; then
30+
makepkg-mingw $ARGUMENTS
31+
else
32+
makepkg $ARGUMENTS
33+
fi
34+
echo "::endgroup::"
3135

32-
ccache -svv || true
36+
echo "::group::Ccache statistics after build"
37+
ccache -svv || true
38+
echo "::endgroup::"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
set -e # exit on error
4+
set -x # echo on
5+
set -o pipefail # fail of any command in pipeline is an error
6+
7+
echo "::group::Create MSYS2 packages repository"
8+
mkdir -p repository/x86_64
9+
mv -f mingw-w64-cross-*.pkg.* repository/x86_64/
10+
pushd repository/x86_64
11+
repo-add woarm64.db.tar.gz *.pkg.*
12+
popd
13+
14+
mkdir -p repository/aarch64
15+
mv -f mingw-w64-aarch64-*.pkg.* repository/aarch64/
16+
pushd repository/aarch64
17+
repo-add woarm64-native.db.tar.gz *.pkg.*
18+
popd
19+
echo "::endgroup::"

.github/scripts/download-artifacts.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ set -x # echo on
55
set -o pipefail # fail of any command in pipeline is an error
66

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

10-
for NEED in $NEEDS; do
11-
echo "Downloading $NEED artifact."
12-
/mingw64/bin/gh run download $RUN_ID -n $NEED
9+
for ARG in "${@:2}"; do
10+
NEEDS=`echo "$ARG" | /mingw64/bin/jq 'keys|join(" ")' | sed 's/"//g'`
11+
for NEED in $NEEDS; do
12+
echo "Downloading $NEED artifact."
13+
/mingw64/bin/gh run download $RUN_ID -n $NEED
14+
done
1315
done

.github/scripts/enable-ccache.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ set -o pipefail # fail of any command in pipeline is an error
66

77
DIR="`dirname ${BASH_SOURCE[0]}`/../.."
88
DIR=`realpath $DIR`
9+
CCACHE_DIR=$DIR/ccache
910
if [[ -n "$GITHUB_WORKSPACE" ]]; then
10-
echo "CCACHE_DIR=$DIR/ccache" >> "$GITHUB_ENV"
11+
echo "CCACHE_DIR=$CCACHE_DIR" >> "$GITHUB_ENV"
1112
echo timestamp=$(date -u --iso-8601=seconds) >> "$GITHUB_OUTPUT"
1213
fi
1314

15+
mkdir -p $CCACHE_DIR
16+
1417
pushd /
1518
echo "::group::/etc/makepkg.conf"
1619
patch -p1 -b -i "$DIR/patches/ccache/0001-makepkg.patch"
@@ -22,3 +25,15 @@ pushd /
2225
cat /etc/makepkg_mingw.conf
2326
echo "::endgroup::"
2427
popd
28+
29+
pacman -S --noconfirm ccache
30+
31+
pushd /usr/lib/ccache/bin
32+
echo "::group::Add aarch64 toolchain to ccache"
33+
export MSYS=winsymlinks
34+
ln -sf /usr/bin/ccache aarch64-w64-mingw32-c++
35+
ln -sf /usr/bin/ccache aarch64-w64-mingw32-g++
36+
ln -sf /usr/bin/ccache aarch64-w64-mingw32-gcc
37+
ln -sf /usr/bin/true makeinfo
38+
echo "::endgroup::"
39+
popd
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
set -e # exit on error
4+
set -x # echo on
5+
set -o pipefail # fail of any command in pipeline is an error
6+
7+
if [ -z "$GITHUB_WORKSPACE" ]; then
8+
DIR=`pwd`
9+
else
10+
DIR=`cygpath "$GITHUB_WORKSPACE"`
11+
fi
12+
13+
echo "::group::Install patch"
14+
pacman -S --noconfirm patch
15+
echo "::endgroup::"
16+
17+
pushd /
18+
echo "::group::Patch MSYS2 environment"
19+
patch -p1 -b -i "$DIR/patches/makepkg/0001-mingwarm64.patch"
20+
if [[ "$CROSS_BUILD" = "1" ]]; then
21+
patch -p1 -b -i "$DIR/patches/makepkg/0002-mingwarm64-cross-build.patch"
22+
fi
23+
if [[ "$DEBUG_BUILD" = "1" ]]; then
24+
patch -p1 -b -i "$DIR/patches/makepkg/0003-enable-debug.patch"
25+
fi
26+
echo "::endgroup::"
27+
28+
echo "::group::/etc/makepkg_mingw.conf"
29+
cat /etc/makepkg_mingw.conf
30+
echo "::endgroup::"
31+
32+
echo "::group::/etc/profile"
33+
cat /etc/profile
34+
echo "::endgroup::"
35+
36+
echo "::group::/usr/share/makepkg/tidy/strip.sh"
37+
cat /usr/share/makepkg/tidy/strip.sh
38+
echo "::endgroup::"
39+
popd

.github/scripts/setup-repository.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pushd /
1313
echo "::endgroup::"
1414

1515
echo "::group::Add WoArm64 repository"
16-
patch -p1 -b -i "$DIR/patches/pacman/0001-add-woarm64-repository.patch"
16+
patch -p1 -b -i "$DIR/patches/pacman/0001-add-woarm64-repositories.patch"
1717
echo "::endgroup::"
1818

1919
echo "::group::Update packages database"

.github/workflows/build-package.yml

Lines changed: 73 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@ on:
66
package_name:
77
description: "Package name to build"
88
type: string
9-
needs:
10-
description: "Parent workflow job dependencies"
11-
type: string
12-
dependencies:
13-
description: "Install additional dependencies"
14-
type: string
15-
default: ""
169
packages_repository:
1710
description: "MSYS2 packages repository to build from"
1811
type: string
@@ -21,37 +14,96 @@ on:
2114
description: "MSYS2 packages branch to build from"
2215
type: string
2316
default: "woarm64"
17+
runner_arch:
18+
description: "Architecture to build on"
19+
type: string
20+
default: "x86_64"
21+
needs:
22+
description: "Parent workflow job dependencies"
23+
type: string
24+
dependencies:
25+
description: "Install additional dependencies"
26+
type: string
27+
default: ""
2428

2529
defaults:
2630
run:
2731
shell: msys2 {0}
2832

2933
env:
3034
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
CROSS_BUILD: ${{ inputs.runner_arch == 'aarch64' && '1' || '0' }}
36+
CLEAN_BUILD: 1
3137

3238
jobs:
3339
build:
3440
name: Build ${{ inputs.package_name }}
35-
runs-on: windows-latest
41+
runs-on: >-
42+
${{ fromJson(inputs.runner_arch == 'aarch64'
43+
&& '["Windows", "ARM64", "MSYS2"]'
44+
|| '["windows-latest"]') }}
3645
3746
steps:
38-
- uses: msys2/setup-msys2@v2
47+
- name: Kill hanging processes
48+
if: ${{ inputs.runner_arch == 'aarch64' }}
49+
shell: powershell
50+
run: |
51+
tasklist
52+
taskkill /F /FI 'MODULES eq msys-2.0.dll'
53+
tasklist
54+
Set-Location "${{ github.workspace }}"
55+
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue -Path packages
56+
exit 0
57+
58+
- name: Fix Git long paths
59+
if: ${{ inputs.runner_arch == 'aarch64' }}
60+
shell: powershell
61+
run: |
62+
git config --global core.longpaths true
63+
64+
- name: Fix $PATH
65+
if: ${{ inputs.runner_arch == 'aarch64' }}
66+
shell: powershell
67+
run: |
68+
Write-Output "GITHUB_PATH: $env:GITHUB_PATH"
69+
Write-Output "C:\Program Files\Git\usr\bin\" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
70+
71+
- uses: Windows-on-ARM-Experiments/setup-msys2@main
72+
timeout-minutes: 10
3973
with:
40-
msystem: ${{ contains(inputs.packages_repository, 'MINGW') && 'MINGW64' || 'MSYS' }}
74+
msystem: >-
75+
${{ contains(inputs.packages_repository, 'MINGW')
76+
&& ((inputs.runner_arch == 'aarch64') && 'MINGWARM64' || 'MINGW64')
77+
|| 'MSYS' }}
4178
update: true
4279
cache: true
4380

4481
- name: Checkout repository
4582
uses: actions/checkout@v4
4683

47-
- name: Install dependencies
84+
- name: Checkout ${{ inputs.packages_repository }} repository
85+
uses: actions/checkout@v4
86+
with:
87+
repository: ${{ inputs.packages_repository }}
88+
ref: ${{ inputs.packages_branch }}
89+
sparse-checkout: ${{ inputs.package_name }}
90+
path: ${{ github.workspace }}/packages
91+
92+
- name: Setup packages repository
93+
if: ${{ inputs.runner_arch == 'aarch64' }}
4894
run: |
95+
`cygpath "${{ github.workspace }}"`/.github/scripts/setup-repository.sh
96+
97+
- name: Install dependencies
98+
run: >-
4999
pacman -S --noconfirm \
50100
git \
51101
mingw-w64-x86_64-github-cli \
52102
mingw-w64-x86_64-jq \
53103
base-devel \
54-
${{ contains(inputs.packages_repository, 'MINGW') && 'mingw-w64-cross-gcc mingw-w64-x86_64-ccache' || ' ccache' }} \
104+
${{ contains(inputs.packages_repository, 'MINGW')
105+
&& 'mingw-w64-cross-mingwarm64-gcc mingw-w64-cross-mingwarm64-windows-default-manifest mingw-w64-x86_64-gcc-libs'
106+
|| '' }} \
55107
${{ inputs.dependencies }}
56108
57109
- name: Download artifacts
@@ -69,25 +121,22 @@ jobs:
69121
run: |
70122
`cygpath "${{ github.workspace }}"`/.github/scripts/pthread-headers-hack-before.sh
71123
72-
- name: Checkout ${{ inputs.packages_repository }} repository
73-
uses: actions/checkout@v4
74-
with:
75-
repository: ${{ inputs.packages_repository }}
76-
ref: ${{ inputs.packages_branch }}
77-
sparse-checkout: ${{ inputs.package_name }}
78-
path: ${{ github.workspace }}/packages
124+
- name: Setup MINGWARM64 environment
125+
if: ${{ inputs.runner_arch == 'aarch64' }}
126+
run: |
127+
`cygpath "${{ github.workspace }}"`/.github/scripts/setup-mingwarm64.sh
79128
80129
- name: Enable Ccache
81130
id: enable-ccache
82131
run: |
83132
`cygpath "${{ github.workspace }}"`/.github/scripts/enable-ccache.sh
84133
85134
- name: Restore Ccache
86-
uses: actions/cache/restore@v4
135+
uses: actions/cache/restore@v4
87136
with:
88137
path: ${{ github.workspace }}/ccache
89-
key: main-ccache-${{ steps.enable-ccache.outputs.timestamp }}
90-
restore-keys: main-ccache-
138+
key: ${{ inputs.package_name }}-ccache-${{ steps.enable-ccache.outputs.timestamp }}
139+
restore-keys: ${{ inputs.package_name }}-
91140

92141
- name: Build ${{ inputs.package_name }}
93142
working-directory: ${{ github.workspace }}/packages/${{ inputs.package_name }}
@@ -98,10 +147,10 @@ jobs:
98147
99148
- name: Save Ccache
100149
if: always()
101-
uses: actions/cache/save@v4
150+
uses: actions/cache/save@v4
102151
with:
103152
path: ${{ github.workspace }}/ccache
104-
key: main-ccache-${{ steps.enable-ccache.outputs.timestamp }}
153+
key: ${{ inputs.package_name }}-ccache-${{ steps.enable-ccache.outputs.timestamp }}
105154

106155
- name: Upload ${{ inputs.package_name }}
107156
uses: actions/upload-artifact@v4

0 commit comments

Comments
 (0)