Skip to content

Commit

Permalink
Build and test aarch64-w64-mingw32 toolchain using MSYS2 MinGW cros…
Browse files Browse the repository at this point in the history
…s-compilation toolchain
  • Loading branch information
Blackhex committed Jul 1, 2024
1 parent ad8113a commit faf7952
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 36 deletions.
6 changes: 4 additions & 2 deletions .github/scripts/binutils/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ if [ "$RUN_CONFIG" = 1 ] || [ ! -f "$BINUTILS_BUILD_PATH/Makefile" ] ; then
lt_cv_deplibs_check_method=pass_all"
;;
*mingw*)
# CHANGED: --enable-lto to --disable-lto
TARGET_OPTIONS="$TARGET_OPTIONS \
--enable-lto \
--enable-64-bit-bfd \
--disable-lto \
--disable-werror \
--with-libiconv-prefix=$TOOLCHAIN_PATH \
--with-system-zlib"
Expand All @@ -48,7 +49,8 @@ if [ "$RUN_CONFIG" = 1 ] || [ ! -f "$BINUTILS_BUILD_PATH/Makefile" ] ; then
--host=$HOST \
--target=$TARGET \
$HOST_OPTIONS \
$TARGET_OPTIONS
$TARGET_OPTIONS \
LDFLAGS="$LDFLAGS"
echo "::endgroup::"
fi

Expand Down
20 changes: 5 additions & 15 deletions .github/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,7 @@

source `dirname ${BASH_SOURCE[0]}`/config.sh

if [ "$CCACHE" = 1 ] ; then
mkdir -p $TOOLCHAIN_PATH/lib/ccache
pushd $TOOLCHAIN_PATH/lib/ccache
if ! [ -f $TARGET-gcc ]; then
ln -s /usr/bin/ccache $TARGET-gcc
fi
if ! [ -f $TARGET-g++ ]; then
ln -s /usr/bin/ccache $TARGET-g++
fi
popd

ccache -z
fi

if [ "$RUN_BOOTSTRAP" = 1 ]; then
if [[ "$RUN_BOOTSTRAP" = 1 && -z $MSYSTEM ]]; then
.github/scripts/install-dependencies.sh
fi

Expand All @@ -33,6 +19,10 @@ if [ "$RUN_BOOTSTRAP" = 1 ]; then
.github/scripts/install-libraries.sh
fi

if [ "$CCACHE" = 1 ] ; then
ccache -s
fi

.github/scripts/binutils/build.sh

if [[ "$PLATFORM" =~ linux ]]; then
Expand Down
18 changes: 8 additions & 10 deletions .github/scripts/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ OPENSSL_VERSION=${OPENSSL_VERSION:-openssl-master}
LIBJPEG_TURBO_VERSION=${LIBJPEG_TURBO_VERSION:-libjpeg-turbo-main}
FFMPEG_VERSION=${FFMPEG_VERSION:-ffmpeg-master}

ARCH=${ARCH:-aarch64}
ARCH=${ARCH:-x86_64}
PLATFORM=${PLATFORM:-w64-mingw32}
if [[ "$PLATFORM" =~ (mingw|cygwin) ]]; then
CRT=${CRT:-msvcrt}
else
CRT=${CRT:-libc}
fi
BUILD=x86_64-pc-linux-gnu
HOST=x86_64-pc-linux-gnu
BUILD=${BUILD:-x86_64-w64-mingw32}
HOST=${HOST:-$ARCH-$PLATFORM}
TARGET=$ARCH-$PLATFORM
TOOLCHAIN_NAME=${TOOLCHAIN_NAME:-$ARCH-$PLATFORM-$CRT}

Expand Down Expand Up @@ -63,15 +63,13 @@ FFMPEG_PATH=${FFMPEG_PATH:-~/ffmpeg}
FFMPEG_TESTS_PATH=${FFMPEG_TESTS_PATH:-~/ffmpeg-tests}

DEBUG=${DEBUG:-0} # Enable debug build.
CCACHE=${CCACHE:-0} # Enable usage of ccache.
RUN_BOOTSTRAP=${RUN_BOOTSTRAP:-0} # Bootstrap dependencies during the build.
CCACHE=${CCACHE:-1} # Enable usage of ccache.
RUN_BOOTSTRAP=${RUN_BOOTSTRAP:-1} # Bootstrap dependencies during the build.
UPDATE_SOURCES=${UPDATE_SOURCES:-0} # Update source code repositories.
RESET_SOURCES=${RESET_SOURCES:-0} # Reset source code repositories before update.
RUN_CONFIG=${RUN_CONFIG:-1} # Run configuration step.
RUN_INSTALL=${RUN_INSTALL:-1} # Run installation step.

PATH=$PATH:$TOOLCHAIN_PATH/bin

if [ "$CCACHE" = 1 ]; then
PATH=/usr/lib/ccache:$TOOLCHAIN_PATH/lib/ccache:$PATH
fi
MSYS=winsymlinks
PATH="/usr/lib/ccache/bin:$TOOLCHAIN_PATH/bin:/opt/$BUILD/bin:/opt/$TARGET/bin:/opt/bin:$PATH"
LDFLAGS="-L/opt/lib/gcc/$TARGET/lib/ $LDFLAGS"
23 changes: 23 additions & 0 deletions .github/scripts/enable-ccache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

source `dirname ${BASH_SOURCE[0]}`/config.sh

if ! [ -z "$GITHUB_WORKSPACE" ]; then
echo "CCACHE_DIR=`cygpath "$GITHUB_WORKSPACE"`/ccache" >> "$GITHUB_ENV"
echo "timestamp=$(date -u --iso-8601=seconds)" >> "$GITHUB_OUTPUT"
fi

if [ -d /usr/lib/ccache/bin ]; then
echo "::group::Add aarch64 toolchain to ccache"
pushd /usr/lib/ccache/bin/
ln -sf /usr/bin/ccache aarch64-w64-mingw32-gcc
ln -sf /usr/bin/ccache aarch64-w64-mingw32-g++
ln -sf /usr/bin/ccache aarch64-w64-mingw32-c++
popd

ln -sf /opt/bin/$BUILD-gcc /opt/$BUILD/bin/gcc
ln -sf /opt/bin/$BUILD-gcc-ar /opt/$BUILD/bin/gcc-ar
ln -sf /opt/bin/$BUILD-g++ /opt/$BUILD/bin/g++
ln -sf /usr/bin/true /opt/$BUILD/bin/makeinfo
echo "::endgroup::"
fi
12 changes: 10 additions & 2 deletions .github/scripts/install-libraries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ echo "::group::Install libraries"

# Symbolic links for binutils dependencies
cd $SOURCE_PATH/$BINUTILS_VERSION
ln -sf $SOURCE_PATH/$GCC_VERSION/gmp gmp
ln -sf $SOURCE_PATH/$GCC_VERSION/mpfr mpfr
if [ -z "$MSYSTEM" ]; then
ln -sf $SOURCE_PATH/$GCC_VERSION/gmp gmp
ln -sf $SOURCE_PATH/$GCC_VERSION/mpfr mpfr
ln -sf $SOURCE_PATH/$GCC_VERSION/isl isl
else
mkdir -p gmp mpfr isl
cp -rf $SOURCE_PATH/$GCC_VERSION/gmp/* gmp
cp -rf $SOURCE_PATH/$GCC_VERSION/mpfr/* mpfr
cp -rf $SOURCE_PATH/$GCC_VERSION/isl/* isl
fi

echo "::endgroup::"

Expand Down
9 changes: 7 additions & 2 deletions .github/scripts/toolchain/build-gcc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ if [ "$RUN_CONFIG" = 1 ] || [ ! -f "$GCC_BUILD_PATH/Makefile" ] ; then
--without-libintl-prefix"
;;
*mingw*)
# REMOVED: --with-gmp=$TOOLCHAIN_PATH
# REMOVED: --with-mpfr=$TOOLCHAIN_PATH
# REMOVED: --with-mpc=$TOOLCHAIN_PATH
# REMOVED: --with-isl=$TOOLCHAIN_PATH
# CHANGED: --enable-lto to --disable-lto
TARGET_OPTIONS="$TARGET_OPTIONS \
--libexecdir=$TOOLCHAIN_PATH/lib \
--enable-threads=win32 \
Expand All @@ -68,7 +73,6 @@ if [ "$RUN_CONFIG" = 1 ] || [ ! -f "$GCC_BUILD_PATH/Makefile" ] ; then
--enable-libstdcxx-time \
--enable-cloog-backend=isl \
--enable-version-specific-runtime-libs \
--enable-lto \
--enable-libgomp \
--enable-checking=release \
--disable-libstdcxx-pch \
Expand Down Expand Up @@ -96,14 +100,15 @@ if [ "$RUN_CONFIG" = 1 ] || [ ! -f "$GCC_BUILD_PATH/Makefile" ] ; then
;;
esac

# REMOVED --enable-languages=lto
$SOURCE_PATH/$GCC_VERSION/configure \
--prefix=$TOOLCHAIN_PATH \
--build=$BUILD \
--host=$HOST \
--target=$TARGET \
--enable-static \
--enable-shared \
--enable-languages=c,c++,lto,fortran \
--enable-languages=c,c++,fortran \
--disable-bootstrap \
--disable-multilib \
--with-gnu-as \
Expand Down
7 changes: 6 additions & 1 deletion .github/scripts/toolchain/build-mingw-headers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ if [ "$RUN_INSTALL" = 1 ] ; then
make install

# Symlink for gcc
ln -sf $TOOLCHAIN_PATH/$TARGET $TOOLCHAIN_PATH/mingw
if [ -z "$MSYSTEM" ]; then
ln -sf $TOOLCHAIN_PATH/$TARGET $TOOLCHAIN_PATH/mingw
else
mkdir -p $TOOLCHAIN_PATH/mingw
cp -rf $TOOLCHAIN_PATH/$TARGET/* $TOOLCHAIN_PATH/mingw
fi
echo "::endgroup::"
fi

Expand Down
2 changes: 0 additions & 2 deletions .github/scripts/toolchain/execute-gcc-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ echo "::group::Execute GCC tests"

cd $GCC_BUILD_PATH
make $BUILD_MAKE_OPTIONS -k check \
RUNTESTFLAGS="--target_board wsl-sim" \
DEJAGNU="$DEJAGNU_FILE" \
CHECK_TEST_FRAMEWORK=1 \
|| echo "Error"

Expand Down
1 change: 0 additions & 1 deletion .github/workflows/advanced.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- main
pull_request:
workflow_dispatch:
inputs:
binutils_branch:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- main
pull_request:
workflow_dispatch:
inputs:
binutils_branch:
Expand Down
115 changes: 115 additions & 0 deletions .github/workflows/test-toolchain-msys2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: Build and test GCC

on:
pull_request:
workflow_dispatch:
inputs:
binutils_branch:
description: 'Binutils branch to build'
required: false
default: 'woarm64'
gcc_branch:
description: 'GCC branch to build'
required: false
default: 'woarm64'
mingw_branch:
description: 'Mingw branch to build'
required: false
default: 'woarm64'

env:
BINUTILS_REPO: Windows-on-ARM-Experiments/binutils-woarm64
BINUTILS_BRANCH: ${{ inputs.binutils_branch }}
BINUTILS_VERSION: binutils

GCC_REPO: Windows-on-ARM-Experiments/gcc-woarm64
GCC_BRANCH: ${{ inputs.gcc_branch }}
GCC_VERSION: gcc

MINGW_REPO: Windows-on-ARM-Experiments/mingw-woarm64
MINGW_BRANCH: ${{ inputs.mingw_branch }}
MINGW_VERSION: mingw-w64-master

jobs:
build-and-test:
runs-on: windows-latest

defaults:
run:
shell: msys2 {0}

env:
BUILD: x86_64-w64-mingw32
ARCH: x86_64
PLATFORM: w64-mingw32
CRT: msvcrt

steps:
- uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
install: git mingw-w64-cross-gcc mingw-w64-cross-zlib make flex bison ccache zlib-devel dejagnu

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

- name: Checkout binutils
uses: actions/checkout@v4
with:
repository: ${{ env.BINUTILS_REPO }}
ref: ${{ env.BINUTILS_BRANCH }}
path: ${{ github.workspace }}/code/${{ env.BINUTILS_VERSION }}

- name: Checkout GCC
uses: actions/checkout@v4
with:
repository: ${{ env.GCC_REPO }}
ref: ${{ env.GCC_BRANCH }}
path: ${{ github.workspace }}/code/${{ env.GCC_VERSION }}

- name: Checkout MinGW
uses: actions/checkout@v4
with:
repository: ${{ env.MINGW_REPO }}
ref: ${{ env.MINGW_BRANCH }}
path: ${{ github.workspace }}/code/${{ env.MINGW_VERSION }}

- name: Enable Ccache
id: enable-ccache
run: |
.github/scripts/enable-ccache.sh
- name: Restore Ccache
uses: actions/cache/restore@v4
with:
path: ${{ github.workspace }}/ccache
key: test-gcc-ccache-${{ steps.enable-ccache.outputs.timestamp }}
restore-keys: test-gcc-ccache-

- name: Build toolchain
run: |
.github/scripts/build.sh
- name: Execute GCC tests
run: |
.github/scripts/toolchain/execute-gcc-tests.sh
- name: Save Ccache
if: always()
uses: actions/cache/save@v4
with:
path: ${{ github.workspace }}/ccache
key: test-gcc-ccache-${{ steps.enable-ccache.outputs.timestamp }}

- name: Compress build folder
if: failure()
run: |
tar -czf build.tar.gz build-*/*
- name: Upload build folder
if: failure()
uses: actions/upload-artifact@v4
with:
name: build
retention-days: 1
path: build.tar.gz

0 comments on commit faf7952

Please sign in to comment.