diff --git a/.github/scripts/build-package.sh b/.github/scripts/build-package.sh index 2e49e9e..73101d3 100755 --- a/.github/scripts/build-package.sh +++ b/.github/scripts/build-package.sh @@ -21,12 +21,18 @@ ARGUMENTS="--syncdeps \ $([ "$CLEAN_BUILD" = 1 ] && echo "--cleanbuild" || echo "") \ $([ "$INSTALL_PACKAGE" = 1 ] && echo "--install" || echo "")" -ccache -svv || true +echo "::group::Ccache statistics before build" + ccache -svv || 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 statistics after build" + ccache -svv || true +echo "::endgroup::" diff --git a/.github/scripts/download-artifacts.sh b/.github/scripts/download-artifacts.sh index ee8c01c..89837b7 100755 --- a/.github/scripts/download-artifacts.sh +++ b/.github/scripts/download-artifacts.sh @@ -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 diff --git a/.github/scripts/enable-ccache.sh b/.github/scripts/enable-ccache.sh index 8a8f300..ea1444a 100755 --- a/.github/scripts/enable-ccache.sh +++ b/.github/scripts/enable-ccache.sh @@ -6,11 +6,14 @@ set -o pipefail # fail of any command in pipeline is an error DIR="`dirname ${BASH_SOURCE[0]}`/../.." DIR=`realpath $DIR` +CCACHE_DIR=$DIR/ccache 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" @@ -22,3 +25,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 + ln -sf /usr/bin/true makeinfo + echo "::endgroup::" +popd diff --git a/.github/scripts/pacman-workaround.sh b/.github/scripts/pacman-workaround.sh new file mode 100644 index 0000000..96e8d90 --- /dev/null +++ b/.github/scripts/pacman-workaround.sh @@ -0,0 +1,32 @@ +#!/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-packages.patch" + echo "::endgroup::" + + echo "::group::/etc/pacman.conf" + cat /etc/pacman.conf + echo "::endgroup::" +popd diff --git a/.github/scripts/setup-mingwarm64.sh b/.github/scripts/setup-mingwarm64.sh new file mode 100644 index 0000000..a994954 --- /dev/null +++ b/.github/scripts/setup-mingwarm64.sh @@ -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-mingwarm64.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 diff --git a/.github/workflows/build-package.yml b/.github/workflows/build-package.yml index 815a75f..34b1717 100644 --- a/.github/workflows/build-package.yml +++ b/.github/workflows/build-package.yml @@ -6,13 +6,6 @@ on: package_name: description: "Package name to build" type: string - needs: - description: "Parent workflow job dependencies" - type: string - dependencies: - description: "Install additional dependencies" - type: string - default: "" packages_repository: description: "MSYS2 packages repository to build from" type: string @@ -21,6 +14,17 @@ on: description: "MSYS2 packages branch to build from" type: string default: "woarm64" + runner_arch: + description: "Architecture to build on" + type: string + default: "x86_64" + needs: + description: "Parent workflow job dependencies" + type: string + dependencies: + description: "Install additional dependencies" + type: string + default: "" defaults: run: @@ -28,22 +32,85 @@ defaults: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CLEAN_BUILD: 1 jobs: build: name: Build ${{ inputs.package_name }} - runs-on: windows-latest + runs-on: >- + ${{ fromJson(inputs.runner_arch == 'aarch64' + && '["Windows", "ARM64", "Blackhex"]' + || '["windows-latest"]') }} steps: - - uses: msys2/setup-msys2@v2 + - name: Kill hanging processes + if: ${{ inputs.runner_arch == 'aarch64' }} + shell: powershell + run: | + tasklist + taskkill /F /FI 'MODULES eq msys-2.0.dll' + tasklist + Set-Location "${{ github.workspace }}" + Remove-Item -Recurse -Force -ErrorAction SilentlyContinue -Path packages + exit 0 + + - name: Fix Git long paths + if: ${{ inputs.runner_arch == 'aarch64' }} + shell: powershell + run: | + git config --global core.longpaths true + + - name: Fix $PATH + if: ${{ inputs.runner_arch == 'aarch64' }} + 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: Windows-on-ARM-Experiments/setup-msys2@main + timeout-minutes: 10 with: - msystem: ${{ contains(inputs.packages_repository, 'MINGW') && 'MINGW64' || 'MSYS' }} - update: true - cache: true + msystem: >- + ${{ contains(inputs.packages_repository, 'MINGW') + && ((inputs.runner_arch == 'aarch64') && 'MINGWARM64' || 'MINGW64') + || 'MSYS' }} + update: ${{ inputs.runner_arch == 'x86_64' }} + cache: ${{ inputs.runner_arch == 'x86_64' }} - name: Checkout repository uses: actions/checkout@v4 + - name: Checkout ${{ inputs.packages_repository }} repository + uses: actions/checkout@v4 + with: + repository: ${{ inputs.packages_repository }} + ref: ${{ inputs.packages_branch }} + sparse-checkout: ${{ inputs.package_name }} + path: ${{ github.workspace }}/packages + + - name: Pacman hang workaround + if: ${{ inputs.runner_arch == 'aarch64' }} + run: | + `cygpath "${{ github.workspace }}"`/.github/scripts/pacman-workaround.sh + + - name: First MSYS2 update + if: ${{ inputs.runner_arch == 'aarch64' }} + shell: powershell + run: | + msys2 -c 'pacman -Syuu --noconfirm' + exit 0 + + - name: Second MSYS2 update + if: ${{ inputs.runner_arch == 'aarch64' }} + shell: powershell + run: | + msys2 -c 'pacman -Syuu --noconfirm' + + - name: Setup packages repository + if: ${{ inputs.runner_arch == 'aarch64' }} + run: | + `cygpath "${{ github.workspace }}"`/.github/scripts/setup-repository.sh + - name: Install dependencies run: | pacman -S --noconfirm \ @@ -51,7 +118,7 @@ jobs: 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-mingwarm64-gcc mingw-w64-cross-mingwarm64-windows-default-manifest mingw-w64-x86_64-gcc-libs' || '' }} \ ${{ inputs.dependencies }} - name: Download artifacts @@ -69,13 +136,10 @@ jobs: run: | `cygpath "${{ github.workspace }}"`/.github/scripts/pthread-headers-hack-before.sh - - name: Checkout ${{ inputs.packages_repository }} repository - uses: actions/checkout@v4 - with: - repository: ${{ inputs.packages_repository }} - ref: ${{ inputs.packages_branch }} - sparse-checkout: ${{ inputs.package_name }} - path: ${{ github.workspace }}/packages + - name: Setup MINGWARM64 environment + if: ${{ inputs.runner_arch == 'aarch64' }} + run: | + `cygpath "${{ github.workspace }}"`/.github/scripts/setup-mingwarm64.sh - name: Enable Ccache id: enable-ccache @@ -83,7 +147,7 @@ jobs: `cygpath "${{ github.workspace }}"`/.github/scripts/enable-ccache.sh - name: Restore Ccache - uses: actions/cache/restore@v4 + uses: actions/cache/restore@v4 with: path: ${{ github.workspace }}/ccache key: main-ccache-${{ steps.enable-ccache.outputs.timestamp }} @@ -92,13 +156,11 @@ jobs: - 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 }} diff --git a/.github/workflows/check-repository.yml b/.github/workflows/check-repository.yml index 4b02ed7..0ed375e 100644 --- a/.github/workflows/check-repository.yml +++ b/.github/workflows/check-repository.yml @@ -13,7 +13,7 @@ jobs: shell: msys2 {0} steps: - - uses: msys2/setup-msys2@v2 + - uses: Windows-on-ARM-Experiments/setup-msys2@main with: msystem: MSYS update: true diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f288c1b..1e3f917 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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: @@ -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: @@ -33,7 +47,7 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: msys2/setup-msys2@v2 + - uses: Windows-on-ARM-Experiments/setup-msys2@main with: msystem: MSYS update: true @@ -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: | diff --git a/.github/workflows/mingw-native-toolchain.yml b/.github/workflows/mingw-native-toolchain.yml new file mode 100644 index 0000000..91a133b --- /dev/null +++ b/.github/workflows/mingw-native-toolchain.yml @@ -0,0 +1,242 @@ +name: Build MinGW native toolchain + +on: + workflow_dispatch: + inputs: + mingw_packages_branch: + description: "MINGW-packages branch to build" + type: string + required: false + default: "woarm64" + workflow_call: + inputs: + mingw_packages_branch: + description: "MINGW-packages branch to build" + type: string + default: "woarm64" + outputs: + artifacts: + value: ${{ toJson(jobs) }} + +jobs: + mingw-w64-libiconv: + uses: ./.github/workflows/build-package.yml + with: + package_name: mingw-w64-libiconv + packages_repository: Windows-on-ARM-Experiments/MINGW-packages + packages_branch: ${{ github.event.inputs.mingw_packages_branch || 'woarm64' }} + runner_arch: aarch64 + + mingw-w64-libtre-git: + uses: ./.github/workflows/build-package.yml + with: + package_name: mingw-w64-libtre-git + packages_repository: Windows-on-ARM-Experiments/MINGW-packages + packages_branch: ${{ github.event.inputs.mingw_packages_branch || 'woarm64' }} + runner_arch: aarch64 + + mingw-w64-libsystre: + needs: [ + mingw-w64-libtre-git + ] + uses: ./.github/workflows/build-package.yml + with: + package_name: mingw-w64-libsystre + packages_repository: Windows-on-ARM-Experiments/MINGW-packages + packages_branch: ${{ github.event.inputs.mingw_packages_branch || 'woarm64' }} + runner_arch: aarch64 + needs: ${{ toJson(needs) }} + + mingw-w64-ncurses: + needs: [ + mingw-w64-libtre-git, + mingw-w64-libsystre + ] + uses: ./.github/workflows/build-package.yml + with: + package_name: mingw-w64-ncurses + packages_repository: Windows-on-ARM-Experiments/MINGW-packages + packages_branch: ${{ github.event.inputs.mingw_packages_branch || 'woarm64' }} + runner_arch: aarch64 + needs: ${{ toJson(needs) }} + + mingw-w64-gettext: + needs: [ + mingw-w64-libiconv, + mingw-w64-libtre-git, + mingw-w64-libsystre, + mingw-w64-ncurses + ] + uses: ./.github/workflows/build-package.yml + with: + package_name: mingw-w64-gettext + packages_repository: Windows-on-ARM-Experiments/MINGW-packages + packages_branch: ${{ github.event.inputs.mingw_packages_branch || 'woarm64' }} + runner_arch: aarch64 + needs: ${{ toJson(needs) }} + + mingw-w64-headers-git: + uses: ./.github/workflows/build-package.yml + with: + package_name: mingw-w64-headers-git + packages_repository: Windows-on-ARM-Experiments/MINGW-packages + packages_branch: ${{ github.event.inputs.mingw_packages_branch || 'woarm64' }} + runner_arch: aarch64 + + mingw-w64-crt-git: + needs: [ + mingw-w64-headers-git + ] + uses: ./.github/workflows/build-package.yml + with: + package_name: mingw-w64-crt-git + packages_repository: Windows-on-ARM-Experiments/MINGW-packages + packages_branch: ${{ github.event.inputs.mingw_packages_branch || 'woarm64' }} + runner_arch: aarch64 + needs: ${{ toJson(needs) }} + + mingw-w64-winpthreads-git: + needs: [ + mingw-w64-headers-git, + mingw-w64-crt-git + ] + uses: ./.github/workflows/build-package.yml + with: + package_name: mingw-w64-winpthreads-git + packages_repository: Windows-on-ARM-Experiments/MINGW-packages + packages_branch: ${{ github.event.inputs.mingw_packages_branch || 'woarm64' }} + runner_arch: aarch64 + needs: ${{ toJson(needs) }} + + mingw-w64-bzip2: + uses: ./.github/workflows/build-package.yml + with: + package_name: mingw-w64-bzip2 + packages_repository: Windows-on-ARM-Experiments/MINGW-packages + packages_branch: ${{ github.event.inputs.mingw_packages_branch || 'woarm64' }} + runner_arch: aarch64 + + mingw-w64-zlib: + needs: [ + mingw-w64-bzip2 + ] + uses: ./.github/workflows/build-package.yml + with: + package_name: mingw-w64-zlib + packages_repository: Windows-on-ARM-Experiments/MINGW-packages + packages_branch: ${{ github.event.inputs.mingw_packages_branch || 'woarm64' }} + runner_arch: aarch64 + needs: ${{ toJson(needs) }} + + mingw-w64-zstd: + uses: ./.github/workflows/build-package.yml + with: + package_name: mingw-w64-zstd + packages_repository: Windows-on-ARM-Experiments/MINGW-packages + packages_branch: ${{ github.event.inputs.mingw_packages_branch || 'woarm64' }} + runner_arch: aarch64 + + mingw-w64-gmp: + uses: ./.github/workflows/build-package.yml + with: + package_name: mingw-w64-gmp + packages_repository: Windows-on-ARM-Experiments/MINGW-packages + packages_branch: ${{ github.event.inputs.mingw_packages_branch || 'woarm64' }} + runner_arch: aarch64 + + mingw-w64-mpfr: + uses: ./.github/workflows/build-package.yml + needs: [ + mingw-w64-gmp + ] + with: + package_name: mingw-w64-mpfr + packages_repository: Windows-on-ARM-Experiments/MINGW-packages + packages_branch: ${{ github.event.inputs.mingw_packages_branch || 'woarm64' }} + runner_arch: aarch64 + needs: ${{ toJson(needs) }} + + mingw-w64-isl: + uses: ./.github/workflows/build-package.yml + needs: [ + mingw-w64-gmp + ] + with: + package_name: mingw-w64-isl + packages_repository: Windows-on-ARM-Experiments/MINGW-packages + packages_branch: ${{ github.event.inputs.mingw_packages_branch || 'woarm64' }} + runner_arch: aarch64 + needs: ${{ toJson(needs) }} + + mingw-w64-binutils: + needs: [ + mingw-w64-libiconv, + mingw-w64-libtre-git, + mingw-w64-libsystre, + mingw-w64-ncurses, + mingw-w64-gettext, + mingw-w64-headers-git, + mingw-w64-winpthreads-git, + mingw-w64-bzip2, + mingw-w64-zlib, + mingw-w64-zstd, + mingw-w64-gmp, + mingw-w64-mpfr, + mingw-w64-isl + ] + 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' }} + runner_arch: aarch64 + needs: ${{ toJson(needs) }} + + mingw-w64-mpc: + needs: [ + mingw-w64-gmp, + mingw-w64-mpfr + ] + uses: ./.github/workflows/build-package.yml + with: + package_name: mingw-w64-mpc + packages_repository: Windows-on-ARM-Experiments/MINGW-packages + packages_branch: ${{ github.event.inputs.mingw_packages_branch || 'woarm64' }} + runner_arch: aarch64 + needs: ${{ toJson(needs) }} + + mingw-w64-windows-default-manifest: + uses: ./.github/workflows/build-package.yml + with: + package_name: mingw-w64-windows-default-manifest + packages_repository: Windows-on-ARM-Experiments/MINGW-packages + packages_branch: ${{ github.event.inputs.mingw_packages_branch || 'woarm64' }} + runner_arch: aarch64 + + mingw-w64-gcc: + needs: [ + mingw-w64-libiconv, + mingw-w64-libtre-git, + mingw-w64-libsystre, + mingw-w64-ncurses, + mingw-w64-gettext, + mingw-w64-headers-git, + mingw-w64-winpthreads-git, + mingw-w64-bzip2, + mingw-w64-zlib, + mingw-w64-zstd, + mingw-w64-gmp, + mingw-w64-mpfr, + mingw-w64-isl, + mingw-w64-binutils, + mingw-w64-mpc, + mingw-w64-crt-git, + mingw-w64-windows-default-manifest + ] + uses: ./.github/workflows/build-package.yml + with: + package_name: mingw-w64-gcc + packages_repository: Windows-on-ARM-Experiments/MINGW-packages + packages_branch: ${{ github.event.inputs.mingw_packages_branch || 'woarm64' }} + runner_arch: aarch64 + needs: ${{ toJson(needs) }} diff --git a/build-native.sh b/build-native.sh new file mode 100644 index 0000000..a218d91 --- /dev/null +++ b/build-native.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +set -e # exit on error +set -x # echo on + +if [[ "$MSYSTEM" != "MINGWARM64" ]]; then + echo "This script must be run in the MSYS2 MINGWARM64 shell" + exit 1 +fi + +ROOT_DIR=`dirname ${BASH_SOURCE[0]}` +ROOT_DIR=`realpath $ROOT_DIR` +CLEAN_BUILD=${CLEAN_BUILD:-0} + +function build_package () { + PACKAGE=$1 + echo "::group::Build $PACKAGE" + pushd ../MINGW-packages/$PACKAGE + rm -rf *.pkg.tar.zst + rm -rf src/ + INSTALL_PACKAGE=1 \ + $ROOT_DIR/.github/scripts/build-package.sh MINGW + popd + echo "::endgroup::" +} + +pacman -R --noconfirm mingw-w64-gcc || true +pacman -R --noconfirm mingw-w64-windows-default-manifest || true +pacman -R --noconfirm mingw-w64-binutils || true +pacman -R --noconfirm mingw-w64-winpthreads-git || true +pacman -R --noconfirm mingw-w64-crt-git || true +pacman -R --noconfirm mingw-w64-headers-git || true +pacman -R --noconfirm mingw-w64-mpc || true +pacman -R --noconfirm mingw-w64-isl || true +pacman -R --noconfirm mingw-w64-mpfr || true +pacman -R --noconfirm mingw-w64-gmp || true +pacman -R --noconfirm mingw-w64-zstd || true +pacman -R --noconfirm mingw-w64-zlib || true +pacman -R --noconfirm mingw-w64-bzip2 || true +pacman -R --noconfirm mingw-w64-gettext || true +pacman -R --noconfirm mingw-w64-ncurses || true +pacman -R --noconfirm mingw-w64-libsystre || true +pacman -R --noconfirm mingw-w64-libtre-git || true +pacman -R --noconfirm mingw-w64-libiconv || true + +pacman -S --noconfirm \ + base-devel \ + mingw-w64-cross-mingwarm64-gcc \ + mingw-w64-cross-mingwarm64-windows-default-manifest \ + mingw-w64-x86_64-gcc-libs + +build_package mingw-w64-libiconv +build_package mingw-w64-libtre-git +build_package mingw-w64-libsystre +build_package mingw-w64-ncurses +build_package mingw-w64-gettext +build_package mingw-w64-bzip2 +build_package mingw-w64-zlib +build_package mingw-w64-zstd +build_package mingw-w64-gmp +build_package mingw-w64-mpfr +build_package mingw-w64-isl +build_package mingw-w64-mpc + +build_package mingw-w64-headers-git +build_package mingw-w64-crt-git +build_package mingw-w64-winpthreads-git +build_package mingw-w64-binutils +build_package mingw-w64-windows-default-manifest +build_package mingw-w64-gcc diff --git a/build.sh b/build.sh index e53524e..0566dd5 100644 --- a/build.sh +++ b/build.sh @@ -3,72 +3,63 @@ set -e # exit on error set -x # echo on +if [[ "$MSYSTEM" != "MSYS" ]]; then + echo "This script must be run in the MSYS2 MSYS shell" + exit 1 +fi + +ROOT_DIR=`dirname ${BASH_SOURCE[0]}` +ROOT_DIR=`realpath $ROOT_DIR` CLEAN_BUILD=${CLEAN_BUILD:-0} -MAKEPKG_OPTIONS="--syncdeps --rmdeps --noconfirm --noprogressbar --nocheck --force --install" -if [ "$CLEAN_BUILD" = 1 ] ; then - MAKEPKG_OPTIONS="$MAKEPKG_OPTIONS --cleanbuild" -fi +function build_package () { + PACKAGE=$1 + echo "::group::Build $PACKAGE" + pushd ../MSYS2-packages/$PACKAGE + rm -rf *.pkg.tar.zst + rm -rf src/ + if [[ "$PACKAGE" == mingw-w64-cross-mingwarm64-crt ]]; then + $ROOT_DIR/.github/scripts/pthread-headers-hack-before.sh + fi + if [[ "$PACKAGE" == mingw-w64-cross-mingwarm64-gcc ]]; then + $ROOT_DIR/.github/scripts/build-package.sh MSYS2 + pacman -R --noconfirm mingw-w64-cross-mingwarm64-gcc-stage1 || true + pacman -U --noconfirm *.pkg.tar.zst + else + INSTALL_PACKAGE=1 \ + $ROOT_DIR/.github/scripts/build-package.sh MSYS2 + fi + if [[ "$PACKAGE" == mingw-w64-cross-mingwarm64-crt ]]; then + $ROOT_DIR/.github/scripts/pthread-headers-hack-after.sh + fi + popd + echo "::endgroup::" +} pacman -R --noconfirm mingw-w64-cross-mingwarm64-zlib || true pacman -R --noconfirm mingw-w64-cross-mingwarm64-gcc || true +pacman -R --noconfirm mingw-w64-cross-gcc || true pacman -R --noconfirm mingw-w64-cross-mingwarm64-winpthreads || true +pacman -R --noconfirm mingw-w64-cross-winpthreads || true pacman -R --noconfirm mingw-w64-cross-mingwarm64-crt || true +pacman -R --noconfirm mingw-w64-cross-cross-crt || true pacman -R --noconfirm mingw-w64-cross-mingwarm64-windows-default-manifest || true +pacman -R --noconfirm mingw-w64-cross-windows-default-manifest || true pacman -R --noconfirm mingw-w64-cross-mingwarm64-gcc-stage1 || true pacman -R --noconfirm mingw-w64-cross-mingwarm64-binutils || true +pacman -R --noconfirm mingw-w64-cross-binutils || true +pacman -R --noconfirm mingw-w64-cross-mingwarm64-headers || true +pacman -R --noconfirm mingw-w64-cross-headers || true pacman -R --noconfirm mingw-w64-cross-mingwarm64-headers || true -pacman -S --noconfirm base-devel - -echo "::group::Build mingw-w64-cross-mingwarm64-headers" - pushd ../MSYS2-packages/mingw-w64-cross-mingwarm64-headers - makepkg $MAKEPKG_OPTIONS - popd -echo "::endgroup::" - -echo "::group::Build mingw-w64-cross-mingwarm64-binutils" - pushd ../MSYS2-packages/mingw-w64-cross-mingwarm64-binutils - makepkg $MAKEPKG_OPTIONS - popd -echo "::endgroup::" - -echo "::group::Build mingw-w64-cross-mingwarm64-gcc-stage1" - pushd ../MSYS2-packages/mingw-w64-cross-mingwarm64-gcc-stage1 - makepkg $MAKEPKG_OPTIONS - popd -echo "::endgroup::" - -echo "::group::Build mingw-w64-cross-mingwarm64-windows-default-manifest" - pushd ../MSYS2-packages/mingw-w64-cross-mingwarm64-windows-default-manifest - makepkg $MAKEPKG_OPTIONS - popd -echo "::endgroup::" - -echo "::group::Build mingw-w64-cross-mingwarm64-crt" - .github/scripts/pthread-headers-hack-before.sh - pushd ../MSYS2-packages/mingw-w64-cross-mingwarm64-crt - makepkg $MAKEPKG_OPTIONS - popd - .github/scripts/pthread-headers-hack-after.sh -echo "::endgroup::" - -echo "::group::Build mingw-w64-cross-mingwarm64-winpthreads" - pushd ../MSYS2-packages/mingw-w64-cross-mingwarm64-winpthreads - makepkg $MAKEPKG_OPTIONS - popd -echo "::endgroup::" - -echo "::group::Build mingw-w64-cross-mingwarm64-gcc" - pushd ../MSYS2-packages/mingw-w64-cross-mingwarm64-gcc - makepkg ${MAKEPKG_OPTIONS//--install/} - pacman -R --noconfirm mingw-w64-cross-mingwarm64-gcc-stage1 || true - pacman -U --noconfirm *.pkg.tar.zst - popd -echo "::endgroup::" +pacman -S --noconfirm \ + base-devel -echo "::group::Build mingw-w64-cross-mingwarm64-zlib" - pushd ../MSYS2-packages/mingw-w64-cross-mingwarm64-zlib - makepkg $MAKEPKG_OPTIONS --skippgpcheck - popd -echo "::endgroup::" +build_package mingw-w64-cross-mingwarm64-headers +build_package mingw-w64-cross-mingwarm64-binutils +build_package mingw-w64-cross-mingwarm64-gcc-stage1 +build_package mingw-w64-cross-mingwarm64-windows-default-manifest +build_package mingw-w64-cross-mingwarm64-crt +build_package mingw-w64-cross-mingwarm64-winpthreads +build_package mingw-w64-cross-mingwarm64-gcc +build_package mingw-w64-cross-mingwarm64-zlib diff --git a/patches/ccache/0002-makepkg-mingw.patch b/patches/ccache/0002-makepkg-mingw.patch index 2bef28b..406cbab 100644 --- a/patches/ccache/0002-makepkg-mingw.patch +++ b/patches/ccache/0002-makepkg-mingw.patch @@ -9,16 +9,3 @@ # #-- If using DistCC, your MAKEFLAGS will also need modification. In addition, #-- specify a space-delimited list of hosts running in the DistCC cluster. ---- a/usr/share/makepkg/buildenv/compiler.sh -+++ b/usr/share/makepkg/buildenv/compiler.sh -@@ -34,8 +34,8 @@ - - buildenv_ccache() { - if check_buildoption "ccache" "y"; then -- if [ -d /usr/lib/ccache/bin ]; then -- export PATH="/usr/lib/ccache/bin:$PATH" -+ if [ -d ${MINGW_PREFIX:-/usr}/lib/ccache/bin ]; then -+ export PATH="${MINGW_PREFIX:-/usr}/lib/ccache/bin:$PATH" - using_ccache=1 - fi - fi diff --git a/patches/makepkg/0001-mingwarm64.patch b/patches/makepkg/0001-mingwarm64.patch new file mode 100644 index 0000000..b5217ac --- /dev/null +++ b/patches/makepkg/0001-mingwarm64.patch @@ -0,0 +1,118 @@ +--- a/etc/makepkg_mingw.conf ++++ b/etc/makepkg_mingw.conf +@@ -32,8 +32,24 @@ + # ARCHITECTURE, COMPILE FLAGS + ######################################################################### + # +- +-if [[ "$MSYSTEM" == "MINGW64" ]]; then ++if [[ "$MSYSTEM" == "MINGWARM64" ]]; then ++ CARCH="aarch64" ++ CHOST="aarch64-w64-mingw32" ++ MINGW_CHOST="aarch64-w64-mingw32" ++ MINGW_PREFIX="/mingwarm64" ++ MINGW_PACKAGE_PREFIX="mingw-w64-aarch64" ++ CC="aarch64-w64-mingw32-gcc" ++ CXX="aarch64-w64-mingw32-g++" ++ RC="aarch64-w64-mingw32-windres" ++ WINDRES="aarch64-w64-mingw32-windres" ++ STRIP="aarch64-w64-mingw32-strip" ++ OBJDUMP="aarch64-w64-mingw32-objdump" ++ OBJCOPY="aarch64-w64-mingw32-objcopy" ++ CPPFLAGS="-D__USE_MINGW_ANSI_STDIO=1" ++ CFLAGS="-march=armv8-a -mtune=generic -g -O0 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong" ++ CXXFLAGS="$CFLAGS" ++ LDFLAGS="" ++elif [[ "$MSYSTEM" == "MINGW64" ]]; then + CARCH="x86_64" + CHOST="x86_64-w64-mingw32" + MINGW_CHOST="x86_64-w64-mingw32" +--- a/etc/msystem ++++ b/etc/msystem +@@ -39,6 +39,15 @@ + MINGW_PACKAGE_PREFIX="mingw-w64-${MSYSTEM_CARCH}" + export MSYSTEM_PREFIX MSYSTEM_CARCH MSYSTEM_CHOST MINGW_CHOST MINGW_PREFIX MINGW_PACKAGE_PREFIX + ;; ++ MINGWARM64) ++ MSYSTEM_PREFIX='/mingwarm64' ++ MSYSTEM_CARCH='aarch64' ++ MSYSTEM_CHOST='aarch64-w64-mingw32' ++ MINGW_CHOST="${MSYSTEM_CHOST}" ++ MINGW_PREFIX="${MSYSTEM_PREFIX}" ++ MINGW_PACKAGE_PREFIX="mingw-w64-${MSYSTEM_CARCH}" ++ export MSYSTEM_PREFIX MSYSTEM_CARCH MSYSTEM_CHOST MINGW_CHOST MINGW_PREFIX MINGW_PACKAGE_PREFIX ++ ;; + CLANG32) + MSYSTEM_PREFIX='/clang32' + MSYSTEM_CARCH='i686' +--- 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="${MINGW_MOUNT_POINT}/bin:${MINGW_MOUNT_POINT}/${MSYSTEM_CHOST}/bin:/opt/bin:/opt/${MSYSTEM_CHOST}/bin:/opt/lib/gcc/${MSYSTEM_CHOST}/15.0.0:/opt/lib/bfd-plugins:/mingw64/bin:/mingw64/${MSYSTEM_CHOST}/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" +--- a/usr/bin/makepkg-mingw ++++ b/usr/bin/makepkg-mingw +@@ -84,7 +84,7 @@ + fi + + # Validate or set MINGW_ARCH +-MINGW_ARCH_ALLOWED=('mingw32' 'mingw64' 'clang32' 'clang64' 'clangarm64' 'ucrt64') ++MINGW_ARCH_ALLOWED=('mingw32' 'mingw64' 'mingwarm64' 'clang32' 'clang64' 'clangarm64' 'ucrt64') + MINGW_ARCH="${MINGW_ARCH,,}" + if [[ -z "$MINGW_ARCH" ]]; then + # In case MINGW_ARCH isn't set we default to MSYSTEM, or error out +--- a/usr/share/makepkg/executable/strip.sh ++++ b/usr/share/makepkg/executable/strip.sh +@@ -30,7 +30,7 @@ + + executable_strip() { + if check_option "strip" "y"; then +- if ! type -p strip >/dev/null; then ++ if ! type -p $STRIP >/dev/null; then + error "$(gettext "Cannot find the %s binary required for object file stripping.")" "strip" + return 1 + fi +--- a/usr/share/makepkg/buildenv.sh ++++ b/usr/share/makepkg/buildenv.sh +@@ -42,5 +42,5 @@ + done + + # ensure all necessary build variables are exported +- export ${buildenv_vars[@]} CC CXX CHOST MAKEFLAGS ++ export ${buildenv_vars[@]} CC CXX RC WINDRES SRIP OBJDUMP OBJCOPY CHOST MAKEFLAGS + } +--- 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/makepkg/0002-enable-debug.patch b/patches/makepkg/0002-enable-debug.patch new file mode 100644 index 0000000..4ead6a3 --- /dev/null +++ b/patches/makepkg/0002-enable-debug.patch @@ -0,0 +1,20 @@ +--- a/etc/makepkg_mingw.conf ++++ b/etc/makepkg_mingw.conf +@@ -47,7 +47,7 @@ + OBJDUMP="aarch64-w64-mingw32-objdump" + OBJCOPY="aarch64-w64-mingw32-objcopy" + CPPFLAGS="-D__USE_MINGW_ANSI_STDIO=1 -I/mingwarm64/include" +- CFLAGS="-O2 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong" ++ CFLAGS="-g -O0 -pipe -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong" + CXXFLAGS="$CFLAGS" + LDFLAGS="-L/mingwarm64/lib" + elif [[ "$MSYSTEM" == "MINGW32" ]]; then +@@ -169,7 +169,7 @@ + #-- lto: Add compile flags for building with link time optimization + #-- autodeps: Automatically add depends/provides + # +-OPTIONS=(strip docs !libtool staticlibs emptydirs zipman purge !debug !lto !autodeps) ++OPTIONS=(!strip docs !libtool staticlibs emptydirs zipman purge !debug !lto !autodeps) + + #-- File integrity checks to use. Valid: ck, md5, sha1, sha224, sha256, sha384, sha512, b2 + INTEGRITY_CHECK=(sha256) diff --git a/patches/pacman/0001-pin-packages.patch b/patches/pacman/0001-pin-packages.patch new file mode 100644 index 0000000..304ae59 --- /dev/null +++ b/patches/pacman/0001-pin-packages.patch @@ -0,0 +1,11 @@ +--- a/etc/pacman.conf ++++ b/etc/pacman.conf +@@ -21,7 +21,7 @@ + Architecture = auto + + # Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup +-#IgnorePkg = ++IgnorePkg = pacman pacman-mirrors gawk + #IgnoreGroup = + + #NoUpgrade = diff --git a/patches/pacman/0002-add-woarm64-repository.patch b/patches/pacman/0002-add-woarm64-repository.patch new file mode 100644 index 0000000..5931616 --- /dev/null +++ b/patches/pacman/0002-add-woarm64-repository.patch @@ -0,0 +1,13 @@ +--- a/etc/pacman.conf ++++ b/etc/pacman.conf +@@ -70,6 +70,10 @@ + # Server = https://repo.msys2.org/staging/ + # SigLevel = Never + ++[woarm64] ++Server = https://windows-on-arm-experiments.github.io/msys2-woarm64-build/x86_64 ++SigLevel = Optional ++ + [clangarm64] + Include = /etc/pacman.d/mirrorlist.mingw + 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