Skip to content

Commit f3bdc5c

Browse files
committed
Build native MinGW toolchain packages
1 parent 3d2bf1e commit f3bdc5c

File tree

10 files changed

+234
-24
lines changed

10 files changed

+234
-24
lines changed

.github/scripts/build-package.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ARGUMENTS="--syncdeps \
1515
--force"
1616

1717
if [[ "$PACKAGE_REPOSITORY" == *MINGW* ]]; then
18-
MINGW_ARCH=mingw64 makepkg-mingw $ARGUMENTS --skippgpcheck
18+
makepkg-mingw $ARGUMENTS
1919
else
2020
makepkg $ARGUMENTS
2121
fi
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+
while ! timeout -k 15s 10s pacman -U --noconfirm `cygpath "$GITHUB_WORKSPACE"`/patches/pacman/pacman-6.1.0-4-x86_64.pkg.tar.zst
8+
do
9+
echo "Command failed, retrying..."
10+
done
11+
12+
pushd /
13+
pacman -S --noconfirm patch
14+
patch -p1 -i `cygpath "$GITHUB_WORKSPACE"`/patches/makepkg/0001-cross-compilation.patch
15+
cat /etc/pacman.conf
16+
cat /etc/makepkg_mingw.conf
17+
cat /etc/profile
18+
cat /usr/share/makepkg/tidy/strip.sh
19+
popd

.github/scripts/setup-repository.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -e # exit on error
44
set -x # echo on
55
set -o pipefail # fail of any command in pipeline is an error
66

7-
pacman -Syuu --noconfirm
7+
#pacman -Syuu --noconfirm
88

99
# Add WoArm64 custom repository.
1010
REPO='[woarm64]

.github/workflows/build-package.yml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ on:
2121
description: "MSYS2 packages branch to build from"
2222
type: string
2323
default: "woarm64"
24+
runs_on_arm64:
25+
description: "Whether Arm64 runner is required"
26+
type: boolean
27+
default: false
2428

2529
defaults:
2630
run:
@@ -31,17 +35,24 @@ env:
3135

3236
jobs:
3337
build:
34-
runs-on: windows-latest
38+
runs-on: [Windows, ARM64, Blackhex]
3539

3640
steps:
37-
- uses: msys2/setup-msys2@v2
38-
with:
39-
msystem: MSYS
40-
update: true
41-
4241
- name: Checkout repository
4342
uses: actions/checkout@v4
4443

44+
- name: Kill hanging processes
45+
shell: powershell
46+
run: |
47+
taskkill /t /f /im pacman.exe | Out-Null
48+
taskkill /t /f /im make.exe | Out-Null
49+
taskkill /t /f /im sh.exe | Out-Null
50+
51+
- name: Setup cross-compilation environment
52+
if: ${{ inputs.runs_on_arm64 }}
53+
run: |
54+
`cygpath "${{ github.workspace }}"`/.github/scripts/setup-cross-compilation.sh
55+
4556
- name: Setup packages repository
4657
run: |
4758
`cygpath "${{ github.workspace }}"`/.github/scripts/setup-repository.sh
@@ -53,11 +64,9 @@ jobs:
5364
git \
5465
mingw-w64-x86_64-github-cli \
5566
mingw-w64-x86_64-jq \
67+
${{ inputs.runs_on_arm64 && 'mingw-w64-cross-gcc' || '' }} \
5668
${{ inputs.dependencies }}
5769
58-
- name: Checkout repository
59-
uses: actions/checkout@v4
60-
6170
- name: Checkout ${{ inputs.packages_repository }} repository
6271
uses: actions/checkout@v4
6372
with:

.github/workflows/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
push:
55
branches:
66
- main
7-
pull_request:
87
workflow_dispatch:
98
inputs:
109
msys2_packages_branch:
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Build MinGW toolchain
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
inputs:
7+
mingw_packages_branch:
8+
description: "MINGW-packages branch to build"
9+
type: string
10+
required: false
11+
default: "woarm64"
12+
13+
jobs:
14+
mingw-w64-binutils:
15+
uses: ./.github/workflows/build-package.yml
16+
with:
17+
package_name: mingw-w64-binutils
18+
packages_repository: Windows-on-ARM-Experiments/MINGW-packages
19+
packages_branch: ${{ github.event.inputs.mingw_packages_branch || 'woarm64' }}
20+
dependencies: mingw-w64-cross-gcc
21+
runs_on_arm64: true

build-native.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
3+
set -e # exit on error
4+
set -x # echo on
5+
6+
CLEAN_BUILD=${CLEAN_BUILD:-0}
7+
8+
MAKEPKG_OPTIONS="--syncdeps --rmdeps --noconfirm --noprogressbar --nocheck --skippgpcheck --force --install"
9+
if [ "$CLEAN_BUILD" = 1 ] ; then
10+
MAKEPKG_OPTIONS="$MAKEPKG_OPTIONS --cleanbuild"
11+
fi
12+
13+
pacman -S --noconfirm base-devel
14+
15+
echo "::group::Build mingw-w64-headers-git"
16+
pushd ../MINGW-packages/mingw-w64-headers-git
17+
makepkg-mingw $MAKEPKG_OPTIONS
18+
popd
19+
echo "::endgroup::"
20+
21+
echo "::group::Build mingw-w64-libiconv"
22+
pushd ../MINGW-packages/mingw-w64-libiconv
23+
makepkg-mingw $MAKEPKG_OPTIONS
24+
popd
25+
echo "::endgroup::"
26+
27+
echo "::group::Build mingw-w64-gettext"
28+
pushd ../MINGW-packages/mingw-w64-gettext
29+
makepkg-mingw $MAKEPKG_OPTIONS
30+
popd
31+
echo "::endgroup::"
32+
33+
echo "::group::Build mingw-w64-binutils"
34+
pushd ../MINGW-packages/mingw-w64-binutils
35+
makepkg-mingw $MAKEPKG_OPTIONS
36+
popd
37+
echo "::endgroup::"
38+
39+
exit 1
40+
41+
echo "::group::Build mingw-w64-gcc-stage1"
42+
pushd ../MINGW-packages/mingw-w64-gcc-stage1
43+
makepkg-mingw $MAKEPKG_OPTIONS
44+
popd
45+
echo "::endgroup::"
46+
47+
echo "::group::Build mingw-w64-windows-default-manifest"
48+
pushd ../MINGW-packages/mingw-w64-windows-default-manifest
49+
makepkg-mingw $MAKEPKG_OPTIONS
50+
popd
51+
echo "::endgroup::"
52+
53+
echo "::group::Build mingw-w64-crt"
54+
pushd ../MINGW-packages/mingw-w64-crt
55+
pacman -S --noconfirm mingw-w64-winpthreads
56+
cp /opt/x86_64-w64-mingw32/include/pthread_signal.h /opt/aarch64-w64-mingw32/include/
57+
cp /opt/x86_64-w64-mingw32/include/pthread_unistd.h /opt/aarch64-w64-mingw32/include/
58+
cp /opt/x86_64-w64-mingw32/include/pthread_time.h /opt/aarch64-w64-mingw32/include/
59+
60+
makepkg-mingw $MAKEPKG_OPTIONS
61+
popd
62+
echo "::endgroup::"
63+
64+
fi
65+
66+
echo "::group::Build mingw-w64-winpthreads"
67+
pushd ../MINGW-packages/mingw-w64-winpthreads
68+
rm -f /opt/aarch64-w64-mingw32/include/pthread_signal.h
69+
rm -f /opt/aarch64-w64-mingw32/include/pthread_unistd.h
70+
rm -f /opt/aarch64-w64-mingw32/include/pthread_time.h
71+
72+
makepkg-mingw $MAKEPKG_OPTIONS
73+
popd
74+
echo "::endgroup::"
75+
76+
echo "::group::Build mingw-w64-gcc"
77+
pushd ../MINGW-packages/mingw-w64-gcc
78+
makepkg-mingw ${MAKEPKG_OPTIONS//--install/}
79+
pacman -R --noconfirm mingw-w64-gcc-stage1 || true
80+
pacman -U --noconfirm *.pkg.tar.zst
81+
popd
82+
echo "::endgroup::"

build.sh

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ if [ "$CLEAN_BUILD" = 1 ] ; then
1010
MAKEPKG_OPTIONS="$MAKEPKG_OPTIONS --cleanbuild"
1111
fi
1212

13-
pacman -R mingw-w64-cross-gcc --noconfirm || true
14-
pacman -R mingw-w64-cross-winpthreads --noconfirm || true
15-
pacman -R mingw-w64-cross-crt --noconfirm || true
16-
pacman -R mingw-w64-cross-windows-default-manifest --noconfirm || true
17-
pacman -R mingw-w64-cross-gcc-stage1 --noconfirm || true
18-
pacman -R mingw-w64-cross-binutils --noconfirm || true
19-
pacman -R mingw-w64-cross-headers --noconfirm || true
13+
pacman -R --noconfirm mingw-w64-cross-gcc || true
14+
pacman -R --noconfirm mingw-w64-cross-winpthreads || true
15+
pacman -R --noconfirm mingw-w64-cross-crt || true
16+
pacman -R --noconfirm mingw-w64-cross-windows-default-manifest || true
17+
pacman -R --noconfirm mingw-w64-cross-gcc-stage1 || true
18+
pacman -R --noconfirm mingw-w64-cross-binutils || true
19+
pacman -R --noconfirm mingw-w64-cross-headers || true
2020

2121
pacman -S --noconfirm base-devel
2222

@@ -47,24 +47,26 @@ echo "::endgroup::"
4747
echo "::group::Build mingw-w64-cross-crt"
4848
pushd ../MSYS2-packages/mingw-w64-cross-crt
4949
pacman -S --noconfirm mingw-w64-cross-winpthreads
50-
cp /opt/x86_64-w64-mingw32/include/pthread_signal.h /opt/aarch64-w64-mingw32/include/
51-
cp /opt/x86_64-w64-mingw32/include/pthread_unistd.h /opt/aarch64-w64-mingw32/include/
52-
cp /opt/x86_64-w64-mingw32/include/pthread_time.h /opt/aarch64-w64-mingw32/include/
50+
.github/scripts/pthread-header-fix.sh
5351

5452
makepkg $MAKEPKG_OPTIONS
5553
popd
5654
echo "::endgroup::"
5755

5856
echo "::group::Build mingw-w64-cross-winpthreads"
5957
pushd ../MSYS2-packages/mingw-w64-cross-winpthreads
58+
rm -f /opt/aarch64-w64-mingw32/include/pthread_signal.h
59+
rm -f /opt/aarch64-w64-mingw32/include/pthread_unistd.h
60+
rm -f /opt/aarch64-w64-mingw32/include/pthread_time.h
61+
6062
makepkg $MAKEPKG_OPTIONS
6163
popd
6264
echo "::endgroup::"
6365

6466
echo "::group::Build mingw-w64-cross-gcc"
6567
pushd ../MSYS2-packages/mingw-w64-cross-gcc
6668
makepkg ${MAKEPKG_OPTIONS//--install/}
67-
pacman -R mingw-w64-cross-gcc-stage1 --noconfirm || true
68-
pacman -U *.pkg.tar.zst --noconfirm
69+
pacman -R --noconfirm mingw-w64-cross-gcc-stage1 || true
70+
pacman -U --noconfirm *.pkg.tar.zst
6971
popd
7072
echo "::endgroup::"
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
diff --git a/etc/makepkg_mingw.conf b/etc/makepkg_mingw.conf
2+
--- a/etc/makepkg_mingw.conf
3+
+++ b/etc/makepkg_mingw.conf
4+
@@ -34,15 +34,17 @@
5+
#
6+
7+
if [[ "$MSYSTEM" == "MINGW64" ]]; then
8+
- CARCH="x86_64"
9+
+ CARCH="aarch64"
10+
CHOST="x86_64-w64-mingw32"
11+
MINGW_CHOST="x86_64-w64-mingw32"
12+
MINGW_PREFIX="/mingw64"
13+
MINGW_PACKAGE_PREFIX="mingw-w64-x86_64"
14+
- CC="gcc"
15+
- CXX="g++"
16+
+ CC="aarch64-w64-mingw32-gcc"
17+
+ CXX="aarch64-w64-mingw32-g++"
18+
+ STRIP="aarch64-w64-mingw32-strip"
19+
+ OBJDUMP="aarch64-w64-mingw32-objdump"
20+
CPPFLAGS="-D__USE_MINGW_ANSI_STDIO=1"
21+
- CFLAGS="-march=nocona -msahf -mtune=generic -O2 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong"
22+
+ CFLAGS="-O2 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong"
23+
CXXFLAGS="$CFLAGS"
24+
LDFLAGS=""
25+
elif [[ "$MSYSTEM" == "MINGW32" ]]; then
26+
--- /etc/pacman.conf
27+
+++ /etc/pacman.conf
28+
@@ -21,7 +21,7 @@
29+
Architecture = auto
30+
31+
# Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup
32+
-#IgnorePkg =
33+
+IgnorePkg = pacman
34+
#IgnoreGroup =
35+
36+
#NoUpgrade =
37+
diff --git a/etc/profile b/etc/profile
38+
--- a/etc/profile
39+
+++ b/etc/profile
40+
@@ -49,7 +49,7 @@
41+
case "${MSYSTEM}" in
42+
MINGW*|CLANG*|UCRT*)
43+
MINGW_MOUNT_POINT="${MINGW_PREFIX}"
44+
- PATH="${MINGW_MOUNT_POINT}/bin:${MSYS2_PATH}${ORIGINAL_PATH:+:${ORIGINAL_PATH}}"
45+
+ PATH="/opt/bin:${MINGW_MOUNT_POINT}/bin:${MSYS2_PATH}${ORIGINAL_PATH:+:${ORIGINAL_PATH}}"
46+
PKG_CONFIG_PATH="${MINGW_MOUNT_POINT}/lib/pkgconfig:${MINGW_MOUNT_POINT}/share/pkgconfig"
47+
PKG_CONFIG_SYSTEM_INCLUDE_PATH="${MINGW_MOUNT_POINT}/include"
48+
PKG_CONFIG_SYSTEM_LIBRARY_PATH="${MINGW_MOUNT_POINT}/lib"
49+
diff --git a/usr/share/makepkg/tidy/strip.sh b/usr/share/makepkg/tidy/strip.sh
50+
--- a/usr/share/makepkg/tidy/strip.sh
51+
+++ b/usr/share/makepkg/tidy/strip.sh
52+
@@ -85,7 +85,7 @@
53+
strip_file(){
54+
local binary=$1; shift
55+
local tempfile=$(mktemp "$binary.XXXXXX")
56+
- if strip "$@" "$binary" -o "$tempfile"; then
57+
+ if $STRIP "$@" "$binary" -o "$tempfile"; then
58+
cat "$tempfile" > "$binary"
59+
fi
60+
rm -f "$tempfile"
61+
@@ -95,7 +95,7 @@
62+
local binary=$1;
63+
64+
local tempfile=$(mktemp "$binary.XXXXXX")
65+
- if strip -R .gnu.lto_* -R .gnu.debuglto_* -N __gnu_lto_v1 "$binary" -o "$tempfile"; then
66+
+ if $STRIP -R .gnu.lto_* -R .gnu.debuglto_* -N __gnu_lto_v1 "$binary" -o "$tempfile"; then
67+
cat "$tempfile" > "$binary"
68+
fi
69+
rm -f "$tempfile"
70+
@@ -176,7 +176,7 @@
71+
case "${binary##*/}" in
72+
*.dll|*.exe|*.sfx|*.so|*.so.[0-9]*|*.oct|*.cmxs) ;;
73+
# make sure this isn't some oddly named DLL
74+
- *) if LANG=en_US.UTF-8 LC_ALL=C objdump -f "${binary}" | grep -Eq '^start address 0x(0000000[01])?00401[0-9a-e][0-9a-e]0'
75+
+ *) if LANG=en_US.UTF-8 LC_ALL=C $OBJDUMP -f "${binary}" | grep -Eq '^start address 0x(0000000[01])?00401[0-9a-e][0-9a-e]0'
76+
then
77+
mv "${binary}" "${binary}.exe"
78+
binary+=.exe
6.42 MB
Binary file not shown.

0 commit comments

Comments
 (0)