From ecdbaaf84e3b04526406c5cd33b5d7d1dee14d5d Mon Sep 17 00:00:00 2001 From: Rachel Date: Tue, 16 Jul 2024 16:05:16 -0700 Subject: [PATCH] Integrate metroskrew as the default compiler --- .github/workflows/build.yml | 6 +- .gitignore | 7 +++ build.sh | 16 ++++- config.sh | 121 ++++++++++++++++++++++++------------ meson/cross.ini | 14 ----- meson/cross_unix.ini | 14 ----- tools/meson.build | 1 - 7 files changed, 105 insertions(+), 74 deletions(-) delete mode 100644 meson/cross.ini delete mode 100644 meson/cross_unix.ini diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b868477cba..233cedd7f2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,17 +23,17 @@ jobs: sudo wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/$(lsb_release -cs)/winehq-$(lsb_release -cs).sources sudo dpkg --add-architecture i386 sudo apt-get update -y - sudo apt-get install -y --install-recommends python3-pip ninja-build winehq-stable binutils-arm-none-eabi gcc-arm-none-eabi + sudo apt-get install -y --install-recommends python3-pip ninja-build winehq-stable binutils-arm-none-eabi gcc-arm-none-eabi gcc-multilib pip install --user meson pyelftools - name: Checkout Repo uses: actions/checkout@v2 - name: Configure Repo - run: ./config.sh /var/tmp/pokeplatinum + run: ./config.sh skrew /var/tmp/pokeplatinum - name: Build Repo - run: meson test -C /var/tmp/pokeplatinum + run: ./build.sh test /var/tmp/pokeplatinum - name: Webhook if: ${{ github.event_name == 'push' }} diff --git a/.gitignore b/.gitignore index ccfa5a58c7..084a581a2f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,13 @@ /tools/cw/mwrap /tools/cw/mwrap.exe +# Metroskrew Installation +/metroskrew/ + +# Generated cross-compilation files +/meson/cross.ini +/meson/cross_unix.ini + # Wrapped subprojects folders /subprojects/libvct-*/ /subprojects/NitroDWC-*/ diff --git a/build.sh b/build.sh index f73cc08b9e..9833c493b0 100755 --- a/build.sh +++ b/build.sh @@ -7,6 +7,12 @@ if [ "$#" -ge 1 ]; then shift fi +build="build" +if [ "$#" -ge 1 ]; then + build="$1" + shift +fi + # Set up env variable to show % of completion during ninja build export NINJA_STATUS="[%p %f/%t] " @@ -17,11 +23,15 @@ export NINJA_STATUS="[%p %f/%t] " # TODO: https://github.com/mesonbuild/meson/issues/13414 export MESON_RSP_THRESHOLD=16387 +# Set up environment variables pointing to MSL libc +export MWCIncludes="$PWD/tools/cw/include/MSL_C;$PWD/tools/cw/include/MSL_Extras" +export MWLibraries="$PWD/tools/cw/lib" + # Build the project if [ "$target" = test ]; then - "${MESON:-meson}" test -C build "$@" + "${MESON:-meson}" test -C "$build" "$@" elif [ "$target" = rom ]; then - "${MESON:-meson}" compile -C build "pokeplatinum.us.nds" + "${MESON:-meson}" compile -C "$build" "pokeplatinum.us.nds" else - "${MESON:-meson}" compile -C build "$target" "$@" + "${MESON:-meson}" compile -C "$build" "$target" "$@" fi diff --git a/config.sh b/config.sh index ab5d8d362b..3f3e8b4345 100755 --- a/config.sh +++ b/config.sh @@ -1,21 +1,16 @@ #!/bin/sh set -e -build="build" +compiler="skrew" if [ "$#" -ge 1 ]; then - build="$1" + compiler="$1" shift fi -wrap=tools/cw - -# Build the wrapper -if ! "$wrap/mwrap" -test 2> /dev/null; then - rm -rf "$wrap/mwrap" "$wrap/build" - "${MESON:-meson}" setup "$wrap/build" "$wrap" - "${MESON:-meson}" compile -C "$wrap/build" - install -m755 "$wrap/build/mwrap" "$wrap/mwrap" - rm -rf "$wrap/build" +build="build" +if [ "$#" -ge 1 ]; then + build="$1" + shift fi is_wsl_accessing_windows() { @@ -28,18 +23,17 @@ is_wsl_accessing_windows() { fi } +# Bootstrap machine file pointing to the repo mkdir -p -- "$build" - root="$PWD" -if [ -n "$MSYSTEM" -a "$MSYSTEM" != MSYS ]; then +if [ -n "$MSYSTEM" ] && [ "$MSYSTEM" != MSYS ]; then root="$(cygpath -w "$root")" fi -# Bootstrap machine file pointing to the repo echo "[constants]" > "$build/root.ini" echo "root = '$root'" >> "$build/root.ini" -# Select toolchain +# Select toolchain configuration files if [ "$(uname -s)" = "Linux" ]; then if is_wsl_accessing_windows; then native_file="native.ini" @@ -56,32 +50,81 @@ else cross_file="cross.ini" fi -touch "$build/.mwconfig" -export MWCONFIG="$(realpath -- "$build/.mwconfig")" - -if [ "$native_file" = "native_unix.ini" ] || [ "$native_file" = "native_macos.ini" ]; then - wrap_wine="$(command -v "${WINELOADER:-wine}")" - wrap_path_unx="$PWD" - wrap_path_win="$("$wrap_wine" winepath -w "$wrap_path_unx")" - wrap_path_build_unx="$build" - wrap_path_build_win="$("$wrap_wine" winepath -w "$wrap_path_build_unx")" - "$wrap/mwrap" -conf -wine "$wrap_wine" \ - -path_unx "$wrap_path_unx" \ - -path_win "$wrap_path_win" \ - -path_build_unx "$wrap_path_build_unx" \ - -path_build_win "$wrap_path_build_win" -elif is_wsl_accessing_windows; then - wrap_path_unx="$PWD" - wrap_path_win="$(wslpath -w "$wrap_path_unx")" - wrap_path_build_unx="$build" - wrap_path_build_win="$(wslpath -w "$wrap_path_build_unx")" - "$wrap/mwrap" -conf -wine "$wrap_wine" \ - -path_unx "$wrap_path_unx" \ - -path_win "$wrap_path_win" \ - -path_build_unx "$wrap_path_build_unx" \ - -path_build_win "$wrap_path_build_win" +# Setup the chosen compiler +if [ "$compiler" = "skrew" ]; then + git clone --depth=1 https://github.com/mid-kid/metroskrew + sed -e '/tool_ver = args.wrap_ver/s/tool_ver/tool_sdk/' -i metroskrew/wrap/wrap.c + sed -e '/^default_mwccarm/cdefault_mwccarm = '\''3.0-137'\''' -i metroskrew/wrap/meson.build + + export MWCIncludes="$PWD/tools/cw/include/MSL_C;$PWD/tools/cw/include/MSL_Extras" + export MWLibraries="$PWD/tools/cw/lib" + + metroskrew_build="$build/metroskrew.build" + meson setup "$metroskrew_build" metroskrew --prefix "$PWD/$build/metroskrew" --buildtype release --cross-file="$root/metroskrew/meson/cc-m32.ini" + meson install -C "$metroskrew_build" + + compiler_exe="$build/metroskrew/bin/skrewrap" +elif [ "$compiler" = "mwrap" ]; then + wrap=tools/cw + + if ! "$wrap/mwrap" -test 2> /dev/null; then + rm -rf "$wrap/mwrap" "$wrap/build" + "${MESON:-meson}" setup "$wrap/build" "$wrap" + "${MESON:-meson}" compile -C "$wrap/build" + install -m755 "$wrap/build/mwrap" "$wrap/mwrap" + rm -rf "$wrap/build" + fi + + touch "$build/.mwconfig" + export MWCONFIG="$(realpath -- "$build/.mwconfig")" + + if [ "$native_file" = "native_unix.ini" ] || [ "$native_file" = "native_macos.ini" ]; then + wrap_wine="$(command -v "${WINELOADER:-wine}")" + wrap_path_unx="$PWD" + wrap_path_win="$("$wrap_wine" winepath -w "$wrap_path_unx")" + wrap_path_build_unx="$build" + wrap_path_build_win="$("$wrap_wine" winepath -w "$wrap_path_build_unx")" + "$wrap/mwrap" -conf -wine "$wrap_wine" \ + -path_unx "$wrap_path_unx" \ + -path_win "$wrap_path_win" \ + -path_build_unx "$wrap_path_build_unx" \ + -path_build_win "$wrap_path_build_win" + elif is_wsl_accessing_windows; then + wrap_path_unx="$PWD" + wrap_path_win="$(wslpath -w "$wrap_path_unx")" + wrap_path_build_unx="$build" + wrap_path_build_win="$(wslpath -w "$wrap_path_build_unx")" + "$wrap/mwrap" -conf -wine "$wrap_wine" \ + -path_unx "$wrap_path_unx" \ + -path_win "$wrap_path_win" \ + -path_build_unx "$wrap_path_build_unx" \ + -path_build_win "$wrap_path_build_win" + fi + + compiler_exe="$wrap/mwrap" +else + echo "Unknown compiler $compiler; terminating" + exit 1 fi +# Set up cross-compilation configuration files +cat < "meson/$cross_file" +[binaries] +c = [root + '/$compiler_exe', 'mwccarm'] +c_ld = [root + '/$compiler_exe', 'mwldarm'] +cpp = [root + '/$compiler_exe', 'mwccarm'] +cpp_ld = [root + '/$compiler_exe', 'mwldarm'] +nasm = [root + '/$compiler_exe', 'mwasmarm'] +ar = [root + '/$compiler_exe', 'mwldarm'] +strip = ['false'] + +[host_machine] +system = 'bare metal' +cpu_family = 'arm' +cpu = 'arm' +endian = 'little' +EOF + # Explicitly set the Response File threshold to half of Wine's limit # Ref: https://github.com/mesonbuild/meson/blob/8e89a38737281f7618a1284fe9e68eb6bb1fe99d/mesonbuild/backend/ninjabackend.py#L108 # Ref: https://github.com/wine-mirror/wine/blob/34b1606019982b71818780bc84b76460f650af31/dlls/ntdll/unix/env.c#L1579 diff --git a/meson/cross.ini b/meson/cross.ini deleted file mode 100644 index 11b2954ecc..0000000000 --- a/meson/cross.ini +++ /dev/null @@ -1,14 +0,0 @@ -[binaries] -c = [root + '/tools/cw/mwrap.exe', 'mwccarm'] -c_ld = [root + '/tools/cw/mwrap.exe', 'mwldarm'] -cpp = [root + '/tools/cw/mwrap.exe', 'mwccarm'] -cpp_ld = [root + '/tools/cw/mwrap.exe', 'mwldarm'] -nasm = [root + '/tools/cw/mwrap.exe', 'mwasmarm'] -ar = [root + '/tools/cw/mwrap.exe', 'mwldarm'] -strip = ['false'] - -[host_machine] -system = 'bare metal' -cpu_family = 'arm' -cpu = 'arm' -endian = 'little' diff --git a/meson/cross_unix.ini b/meson/cross_unix.ini deleted file mode 100644 index f4aa5f5557..0000000000 --- a/meson/cross_unix.ini +++ /dev/null @@ -1,14 +0,0 @@ -[binaries] -c = [root + '/tools/cw/mwrap', 'mwccarm'] -c_ld = [root + '/tools/cw/mwrap', 'mwldarm'] -cpp = [root + '/tools/cw/mwrap', 'mwccarm'] -cpp_ld = [root + '/tools/cw/mwrap', 'mwldarm'] -nasm = [root + '/tools/cw/mwrap', 'mwasmarm'] -ar = [root + '/tools/cw/mwrap', 'mwldarm'] -strip = ['false'] - -[host_machine] -system = 'bare metal' -cpu_family = 'arm' -cpu = 'arm' -endian = 'little' diff --git a/tools/meson.build b/tools/meson.build index 91540a2ca9..66aa322f07 100644 --- a/tools/meson.build +++ b/tools/meson.build @@ -7,7 +7,6 @@ subdir('postconf') subdir('scripts') # Prebuilt tools -mwrap_exe = find_program('cw/mwrap', native: true) makebanner_exe = find_program('makebanner', native: true) makelcf_exe = find_program('makelcf', native: true) makerom_exe = find_program('makerom', native: true)