Skip to content

Commit

Permalink
Integrate metroskrew as the default compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
lhearachel committed Jul 17, 2024
1 parent c86dc1e commit ecdbaaf
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 74 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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-*/
Expand Down
16 changes: 13 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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] "

Expand All @@ -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
121 changes: 82 additions & 39 deletions config.sh
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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"
Expand All @@ -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 <<EOF > "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
Expand Down
14 changes: 0 additions & 14 deletions meson/cross.ini

This file was deleted.

14 changes: 0 additions & 14 deletions meson/cross_unix.ini

This file was deleted.

1 change: 0 additions & 1 deletion tools/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ecdbaaf

Please sign in to comment.