diff --git a/.github/scripts/build-package.sh b/.github/scripts/build-package.sh index c550b41..993fd2f 100755 --- a/.github/scripts/build-package.sh +++ b/.github/scripts/build-package.sh @@ -15,7 +15,7 @@ ARGUMENTS="--syncdeps \ --force" if [[ "$PACKAGE_REPOSITORY" == *MINGW* ]]; then - MINGW_ARCH=mingw64 makepkg-mingw $ARGUMENTS --skippgpcheck + makepkg-mingw $ARGUMENTS else makepkg $ARGUMENTS fi diff --git a/.github/scripts/setup-cross-compilation.sh b/.github/scripts/setup-cross-compilation.sh new file mode 100644 index 0000000..9927661 --- /dev/null +++ b/.github/scripts/setup-cross-compilation.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e # exit on error +set -x # echo on +set -o pipefail # fail of any command in pipeline is an error + +while ! timeout -k 15s 10s pacman -U --noconfirm `cygpath "$GITHUB_WORKSPACE"`/patches/pacman/pacman-6.1.0-4-x86_64.pkg.tar.zst +do + echo "Command failed, retrying..." +done + +pushd / + pacman -S --noconfirm patch + patch -p1 -i `cygpath "$GITHUB_WORKSPACE"`/patches/makepkg/0001-cross-compilation.patch + cat /etc/pacman.conf + cat /etc/makepkg_mingw.conf + cat /etc/profile + cat /usr/share/makepkg/tidy/strip.sh +popd diff --git a/.github/scripts/setup-repository.sh b/.github/scripts/setup-repository.sh index 59506aa..f9049f3 100755 --- a/.github/scripts/setup-repository.sh +++ b/.github/scripts/setup-repository.sh @@ -4,7 +4,7 @@ set -e # exit on error set -x # echo on set -o pipefail # fail of any command in pipeline is an error -pacman -Syuu --noconfirm +#pacman -Syuu --noconfirm # Add WoArm64 custom repository. REPO='[woarm64] diff --git a/.github/workflows/build-package.yml b/.github/workflows/build-package.yml index aa5b8ab..b0df350 100644 --- a/.github/workflows/build-package.yml +++ b/.github/workflows/build-package.yml @@ -21,6 +21,10 @@ on: description: "MSYS2 packages branch to build from" type: string default: "woarm64" + runs_on_arm64: + description: "Whether Arm64 runner is required" + type: boolean + default: false defaults: run: @@ -31,17 +35,24 @@ env: jobs: build: - runs-on: windows-latest + runs-on: [Windows, ARM64, Blackhex] steps: - - uses: msys2/setup-msys2@v2 - with: - msystem: MSYS - update: true - - name: Checkout repository uses: actions/checkout@v4 + - name: Kill hanging processes + shell: powershell + run: | + taskkill /f /im pacman.exe -ErrorAction SilentlyContinue + taskkill /f /im make.exe -ErrorAction SilentlyContinue + taskkill /f /im sh.exe -ErrorAction SilentlyContinue + + - name: Setup cross-compilation environment + if: ${{ inputs.runs_on_arm64 }} + run: | + `cygpath "${{ github.workspace }}"`/.github/scripts/setup-cross-compilation.sh + - name: Setup packages repository run: | `cygpath "${{ github.workspace }}"`/.github/scripts/setup-repository.sh @@ -53,11 +64,9 @@ jobs: git \ mingw-w64-x86_64-github-cli \ mingw-w64-x86_64-jq \ + ${{ inputs.runs_on_arm64 && 'mingw-w64-cross-gcc' || '' }} \ ${{ inputs.dependencies }} - - name: Checkout repository - uses: actions/checkout@v4 - - name: Checkout ${{ inputs.packages_repository }} repository uses: actions/checkout@v4 with: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 420cbaf..e9a8783 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,7 +4,6 @@ on: push: branches: - main - pull_request: workflow_dispatch: inputs: msys2_packages_branch: diff --git a/.github/workflows/mingw-toolchain.yml b/.github/workflows/mingw-toolchain.yml new file mode 100644 index 0000000..df289aa --- /dev/null +++ b/.github/workflows/mingw-toolchain.yml @@ -0,0 +1,21 @@ +name: Build MinGW toolchain + +on: + pull_request: + workflow_dispatch: + inputs: + mingw_packages_branch: + description: "MINGW-packages branch to build" + type: string + required: false + default: "woarm64" + +jobs: + mingw-w64-binutils: + uses: ./.github/workflows/build-package.yml + with: + package_name: mingw-w64-binutils + packages_repository: Windows-on-ARM-Experiments/MINGW-packages + packages_branch: ${{ github.event.inputs.mingw_packages_branch || 'woarm64' }} + dependencies: mingw-w64-cross-gcc + runs_on_arm64: true diff --git a/build-native.sh b/build-native.sh new file mode 100644 index 0000000..d57c18d --- /dev/null +++ b/build-native.sh @@ -0,0 +1,82 @@ +#!/bin/bash + +set -e # exit on error +set -x # echo on + +CLEAN_BUILD=${CLEAN_BUILD:-0} + +MAKEPKG_OPTIONS="--syncdeps --rmdeps --noconfirm --noprogressbar --nocheck --skippgpcheck --force --install" +if [ "$CLEAN_BUILD" = 1 ] ; then + MAKEPKG_OPTIONS="$MAKEPKG_OPTIONS --cleanbuild" +fi + +pacman -S --noconfirm base-devel + +echo "::group::Build mingw-w64-headers-git" + pushd ../MINGW-packages/mingw-w64-headers-git + makepkg-mingw $MAKEPKG_OPTIONS + popd +echo "::endgroup::" + +echo "::group::Build mingw-w64-libiconv" + pushd ../MINGW-packages/mingw-w64-libiconv + makepkg-mingw $MAKEPKG_OPTIONS + popd +echo "::endgroup::" + +echo "::group::Build mingw-w64-gettext" + pushd ../MINGW-packages/mingw-w64-gettext + makepkg-mingw $MAKEPKG_OPTIONS + popd +echo "::endgroup::" + +echo "::group::Build mingw-w64-binutils" + pushd ../MINGW-packages/mingw-w64-binutils + makepkg-mingw $MAKEPKG_OPTIONS + popd +echo "::endgroup::" + +exit 1 + +echo "::group::Build mingw-w64-gcc-stage1" + pushd ../MINGW-packages/mingw-w64-gcc-stage1 + makepkg-mingw $MAKEPKG_OPTIONS + popd +echo "::endgroup::" + +echo "::group::Build mingw-w64-windows-default-manifest" + pushd ../MINGW-packages/mingw-w64-windows-default-manifest + makepkg-mingw $MAKEPKG_OPTIONS + popd +echo "::endgroup::" + +echo "::group::Build mingw-w64-crt" + pushd ../MINGW-packages/mingw-w64-crt + pacman -S --noconfirm mingw-w64-winpthreads + cp /opt/x86_64-w64-mingw32/include/pthread_signal.h /opt/aarch64-w64-mingw32/include/ + cp /opt/x86_64-w64-mingw32/include/pthread_unistd.h /opt/aarch64-w64-mingw32/include/ + cp /opt/x86_64-w64-mingw32/include/pthread_time.h /opt/aarch64-w64-mingw32/include/ + + makepkg-mingw $MAKEPKG_OPTIONS + popd +echo "::endgroup::" + +fi + +echo "::group::Build mingw-w64-winpthreads" + pushd ../MINGW-packages/mingw-w64-winpthreads + rm -f /opt/aarch64-w64-mingw32/include/pthread_signal.h + rm -f /opt/aarch64-w64-mingw32/include/pthread_unistd.h + rm -f /opt/aarch64-w64-mingw32/include/pthread_time.h + + makepkg-mingw $MAKEPKG_OPTIONS + popd +echo "::endgroup::" + +echo "::group::Build mingw-w64-gcc" + pushd ../MINGW-packages/mingw-w64-gcc + makepkg-mingw ${MAKEPKG_OPTIONS//--install/} + pacman -R --noconfirm mingw-w64-gcc-stage1 || true + pacman -U --noconfirm *.pkg.tar.zst + popd +echo "::endgroup::" diff --git a/build.sh b/build.sh index e6cc81a..b06f054 100644 --- a/build.sh +++ b/build.sh @@ -10,13 +10,13 @@ if [ "$CLEAN_BUILD" = 1 ] ; then MAKEPKG_OPTIONS="$MAKEPKG_OPTIONS --cleanbuild" fi -pacman -R mingw-w64-cross-gcc --noconfirm || true -pacman -R mingw-w64-cross-winpthreads --noconfirm || true -pacman -R mingw-w64-cross-crt --noconfirm || true -pacman -R mingw-w64-cross-windows-default-manifest --noconfirm || true -pacman -R mingw-w64-cross-gcc-stage1 --noconfirm || true -pacman -R mingw-w64-cross-binutils --noconfirm || true -pacman -R mingw-w64-cross-headers --noconfirm || true +pacman -R --noconfirm mingw-w64-cross-gcc || true +pacman -R --noconfirm mingw-w64-cross-winpthreads || true +pacman -R --noconfirm mingw-w64-cross-crt || true +pacman -R --noconfirm mingw-w64-cross-windows-default-manifest || true +pacman -R --noconfirm mingw-w64-cross-gcc-stage1 || true +pacman -R --noconfirm mingw-w64-cross-binutils || true +pacman -R --noconfirm mingw-w64-cross-headers || true pacman -S --noconfirm base-devel @@ -47,9 +47,7 @@ echo "::endgroup::" echo "::group::Build mingw-w64-cross-crt" pushd ../MSYS2-packages/mingw-w64-cross-crt pacman -S --noconfirm mingw-w64-cross-winpthreads - cp /opt/x86_64-w64-mingw32/include/pthread_signal.h /opt/aarch64-w64-mingw32/include/ - cp /opt/x86_64-w64-mingw32/include/pthread_unistd.h /opt/aarch64-w64-mingw32/include/ - cp /opt/x86_64-w64-mingw32/include/pthread_time.h /opt/aarch64-w64-mingw32/include/ + .github/scripts/pthread-header-fix.sh makepkg $MAKEPKG_OPTIONS popd @@ -57,6 +55,10 @@ echo "::endgroup::" echo "::group::Build mingw-w64-cross-winpthreads" pushd ../MSYS2-packages/mingw-w64-cross-winpthreads + rm -f /opt/aarch64-w64-mingw32/include/pthread_signal.h + rm -f /opt/aarch64-w64-mingw32/include/pthread_unistd.h + rm -f /opt/aarch64-w64-mingw32/include/pthread_time.h + makepkg $MAKEPKG_OPTIONS popd echo "::endgroup::" @@ -64,7 +66,7 @@ echo "::endgroup::" echo "::group::Build mingw-w64-cross-gcc" pushd ../MSYS2-packages/mingw-w64-cross-gcc makepkg ${MAKEPKG_OPTIONS//--install/} - pacman -R mingw-w64-cross-gcc-stage1 --noconfirm || true - pacman -U *.pkg.tar.zst --noconfirm + pacman -R --noconfirm mingw-w64-cross-gcc-stage1 || true + pacman -U --noconfirm *.pkg.tar.zst popd echo "::endgroup::" diff --git a/patches/makepkg/0001-cross-compilation.patch b/patches/makepkg/0001-cross-compilation.patch new file mode 100644 index 0000000..8f8ff7b --- /dev/null +++ b/patches/makepkg/0001-cross-compilation.patch @@ -0,0 +1,78 @@ +diff --git a/etc/makepkg_mingw.conf b/etc/makepkg_mingw.conf +--- a/etc/makepkg_mingw.conf ++++ b/etc/makepkg_mingw.conf +@@ -34,15 +34,17 @@ + # + + if [[ "$MSYSTEM" == "MINGW64" ]]; then +- CARCH="x86_64" ++ CARCH="aarch64" + CHOST="x86_64-w64-mingw32" + MINGW_CHOST="x86_64-w64-mingw32" + MINGW_PREFIX="/mingw64" + MINGW_PACKAGE_PREFIX="mingw-w64-x86_64" +- CC="gcc" +- CXX="g++" ++ CC="aarch64-w64-mingw32-gcc" ++ CXX="aarch64-w64-mingw32-g++" ++ STRIP="aarch64-w64-mingw32-strip" ++ OBJDUMP="aarch64-w64-mingw32-objdump" + CPPFLAGS="-D__USE_MINGW_ANSI_STDIO=1" +- CFLAGS="-march=nocona -msahf -mtune=generic -O2 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong" ++ CFLAGS="-O2 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong" + CXXFLAGS="$CFLAGS" + LDFLAGS="" + elif [[ "$MSYSTEM" == "MINGW32" ]]; then +--- /etc/pacman.conf ++++ /etc/pacman.conf +@@ -21,7 +21,7 @@ + Architecture = auto + + # Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup +-#IgnorePkg = ++IgnorePkg = pacman + #IgnoreGroup = + + #NoUpgrade = +diff --git a/etc/profile b/etc/profile +--- a/etc/profile ++++ b/etc/profile +@@ -49,7 +49,7 @@ + case "${MSYSTEM}" in + MINGW*|CLANG*|UCRT*) + MINGW_MOUNT_POINT="${MINGW_PREFIX}" +- PATH="${MINGW_MOUNT_POINT}/bin:${MSYS2_PATH}${ORIGINAL_PATH:+:${ORIGINAL_PATH}}" ++ PATH="/opt/bin:${MINGW_MOUNT_POINT}/bin:${MSYS2_PATH}${ORIGINAL_PATH:+:${ORIGINAL_PATH}}" + PKG_CONFIG_PATH="${MINGW_MOUNT_POINT}/lib/pkgconfig:${MINGW_MOUNT_POINT}/share/pkgconfig" + PKG_CONFIG_SYSTEM_INCLUDE_PATH="${MINGW_MOUNT_POINT}/include" + PKG_CONFIG_SYSTEM_LIBRARY_PATH="${MINGW_MOUNT_POINT}/lib" +diff --git a/usr/share/makepkg/tidy/strip.sh b/usr/share/makepkg/tidy/strip.sh +--- a/usr/share/makepkg/tidy/strip.sh ++++ b/usr/share/makepkg/tidy/strip.sh +@@ -85,7 +85,7 @@ + strip_file(){ + local binary=$1; shift + local tempfile=$(mktemp "$binary.XXXXXX") +- if strip "$@" "$binary" -o "$tempfile"; then ++ if $STRIP "$@" "$binary" -o "$tempfile"; then + cat "$tempfile" > "$binary" + fi + rm -f "$tempfile" +@@ -95,7 +95,7 @@ + local binary=$1; + + local tempfile=$(mktemp "$binary.XXXXXX") +- if strip -R .gnu.lto_* -R .gnu.debuglto_* -N __gnu_lto_v1 "$binary" -o "$tempfile"; then ++ if $STRIP -R .gnu.lto_* -R .gnu.debuglto_* -N __gnu_lto_v1 "$binary" -o "$tempfile"; then + cat "$tempfile" > "$binary" + fi + rm -f "$tempfile" +@@ -176,7 +176,7 @@ + case "${binary##*/}" in + *.dll|*.exe|*.sfx|*.so|*.so.[0-9]*|*.oct|*.cmxs) ;; + # make sure this isn't some oddly named DLL +- *) 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' ++ *) 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' + then + mv "${binary}" "${binary}.exe" + binary+=.exe diff --git a/patches/pacman/pacman-6.1.0-4-x86_64.pkg.tar.zst b/patches/pacman/pacman-6.1.0-4-x86_64.pkg.tar.zst new file mode 100644 index 0000000..2b47255 Binary files /dev/null and b/patches/pacman/pacman-6.1.0-4-x86_64.pkg.tar.zst differ