FunkinCrew / Funkin

A rhythm game made with HaxeFlixel
https://www.newgrounds.com/portal/view/770371
Other
2.89k stars 2.26k forks source link

Question/Enhancement: Native Apple Silicon builds for macOS? #2985

Open AbnormalPoof opened 2 months ago

AbnormalPoof commented 2 months ago

Please check for duplicates or similar issues before creating this issue.

What is your suggestion, and why should it be implemented?

With the recent changes to lime (see the 8.2.0-Dev branch and #1640), building lime NDLL's and compiling projects on native ARM is now possible.

By porting over some changes from the FunkinCrew fork of lime, I managed to hack together a build for ARM! So I decided to compare the 2 (Native ARM vs Rosetta Intel), both of them are running off of the main branch.

Here are the compilation times, I am using a modified version of lime which is based of the 8.2.0-Dev branch, with changes ported from the FunkinCrew fork in order to make Funkin' compile properly.

Unfortunately, aside from compilation, there kind of(?) actually isn't much to talk about in terms of performance. Both of them seem to mostly run in the same FPS. With the small differences in FPS being confined to stuff like the Freeplay Menu.

One (significant?) performance boost I did encounter was with the chart editor... mainly from spamming notes in "Live Input Mode"

https://github.com/FunkinCrew/Funkin/assets/86753001/7f91147c-94b9-40a8-bede-1f025239a11a

https://github.com/FunkinCrew/Funkin/assets/86753001/a5e62bd5-a450-4b42-8d2f-622854d56509

ninjamuffin99 commented 1 month ago

Definitely something on the roadmap, as I use arm64 mac for a lot of my development! I've been keeping an eye on progress of the PRs being made, I just haven't tried out with installation too thoroughly since I didn't want to bug up my haxe installation on my mac bwah!

AbnormalPoof commented 1 month ago

Managed to create a universal build by using lipo to combine the Intel+ARM lime NDLL's and Funkin binaries together!

Screenshot 2024-07-12 at 8 28 50 AM

For anyone curious, I have created a script to automate the process. This requires installing the 8.2.0-Dev fork of lime using hmm (for ARM building support) and the changes from lime#1802 in order for Funkin' to build properly. Furthermore, the ARM version of Haxe/Neko is needed I'm pretty sure, installable through brew.

#!/bin/bash

# Pre-build: Cleanup build files
if [ -d export/release/macos/bin/Funkin.app ]; then
  rm -r export/release/macos/bin/Funkin.app
fi
if [ -d export/release/macos/bin/Funkin-ARM.app ]; then
  rm -r export/release/macos/bin/Funkin-ARM.app
fi
if [ -d export/release/macos/bin/Funkin-Intel.app ]; then
  rm -r export/release/macos/bin/Funkin-Intel.app
fi

# Step 1: Compile lime for both ARM and Intel architectures
# This can be skipped by passing '--skip-lime'
if [[ ! " $@ " =~ " --skip-lime " ]]; then
  echo -e ""
  echo -e "\033[1;33m\033[1m/***************************************\\"
  echo -e "       ***** COMPILING LIME *****"
  echo -e "\\***************************************/\033[0m"
  echo -e ""
  lime rebuild mac -clean -release
  if [ ! -f .haxelib/lime/git/ndll/MacArm64/lime.ndll ]; then
    echo -e "\033[1;31m\033[1mThe ARM lime build has failed! Exiting...\033[0m"
    exit 1
  fi
  arch -x86_64 lime rebuild mac -DHXCPP_X64 -clean -release
  if [ ! -f .haxelib/lime/git/ndll/Mac64/lime.ndll ]; then
    echo -e "\033[1;31m\033[1mThe Intel lime build has failed! Exiting...\033[0m"
    exit 1
  fi
  # We use the ARM lime library for compiling on Intel due to linking issues with ApplicationMain
  mv ".haxelib/lime/git/ndll/Mac64/lime.ndll" ".haxelib/lime/git/ndll/Mac64/lime-intel.ndll"
  cp ".haxelib/lime/git/ndll/MacArm64/lime.ndll" ".haxelib/lime/git/ndll/Mac64/lime.ndll"
else
  echo -e "\033[38;5;214m\033[1mLime compilation has been skipped since '--skip-lime' was specified!"
fi

# Step 2: Build the ARM version
echo -e ""
echo -e "\033[1;33m\033[1m/***************************************\\"
echo -e "  ***** COMPILING THE ARM BUILD *****"
echo -e "\\***************************************/\033[0m"
echo -e ""
lime build mac
if [ ! -f export/release/macos/bin/Funkin.app/Contents/MacOS/Funkin ]; then
  echo -e "\033[1;31m\033[1mThe ARM build has failed! Exiting...\033[0m"
  exit 1
else
  mv export/release/macos/bin/Funkin.app export/release/macos/bin/Funkin-ARM.app
fi

# Step 3: Build the Intel Version
echo -e ""
echo -e "\033[1;33m\033[1m/***************************************\\"
echo -e "  ***** COMPILING THE INTEL BUILD *****"
echo -e "\\***************************************/\033[0m"
echo -e ""
arch -x86_64 lime build mac -DHXCPP_X64
if [ ! -f export/release/macos/bin/Funkin.app/Contents/MacOS/Funkin ]; then
  echo -e "\033[1;31m\033[1mThe Intel build has failed! Exiting...\033[0m"
  exit 1
else
  mv export/release/macos/bin/Funkin.app export/release/macos/bin/Funkin-Intel.app
fi

# Step 4: COMBINE!
# This is a mess, I know.
echo -e ""
echo -e "\033[1;33m\033[1m/***************************************\\"
echo -e "***** MAKING A UNIVERSAL BINARY *****"
echo -e "\\***************************************/\033[0m"
echo -e ""

cp -R export/release/macos/bin/Funkin-ARM.app export/release/macos/bin/Funkin.app

rm export/release/macos/bin/Funkin.app/Contents/MacOS/Funkin
rm export/release/macos/bin/Funkin.app/Contents/MacOS/lime.ndll

cp export/release/macos/bin/Funkin-ARM.app/Contents/MacOS/Funkin export/release/macos/bin/Funkin.app/Contents/MacOS/Funkin-ARM
cp export/release/macos/bin/Funkin-ARM.app/Contents/MacOS/lime.ndll export/release/macos/bin/Funkin.app/Contents/MacOS/lime.ndll-ARM
cp export/release/macos/bin/Funkin-Intel.app/Contents/MacOS/Funkin export/release/macos/bin/Funkin.app/Contents/MacOS/Funkin-Intel
cp .haxelib/lime/git/ndll/Mac64/lime-intel.ndll export/release/macos/bin/Funkin.app/Contents/MacOS/lime.ndll-Intel

lipo -create -output export/release/macos/bin/Funkin.app/Contents/MacOS/Funkin export/release/macos/bin/Funkin.app/Contents/MacOS/Funkin-Intel export/release/macos/bin/Funkin.app/Contents/MacOS/Funkin-ARM
lipo -create -output export/release/macos/bin/Funkin.app/Contents/MacOS/lime.ndll export/release/macos/bin/Funkin.app/Contents/MacOS/lime.ndll-Intel export/release/macos/bin/Funkin.app/Contents/MacOS/lime.ndll-ARM

rm export/release/macos/bin/Funkin.app/Contents/MacOS/Funkin-ARM
rm export/release/macos/bin/Funkin.app/Contents/MacOS/lime.ndll-ARM
rm export/release/macos/bin/Funkin.app/Contents/MacOS/Funkin-Intel
rm export/release/macos/bin/Funkin.app/Contents/MacOS/lime.ndll-Intel
rm -r export/release/macos/bin/Funkin-ARM.app
rm -r export/release/macos/bin/Funkin-Intel.app

echo -e "\033[1;32mSuccess! You should see a Universal version of Funkin.app in export/release/macos/bin\033[0m"
JonnycatMeow commented 1 month ago

hell yah

JonnycatMeow commented 1 month ago

but how do i build it for arm64 on a intel computer? because i want to make a universal build as well

AbnormalPoof commented 1 month ago

I only made this script with ARM64 Macs in mind. Lime allows you to cross-compile to arm64 using the -arm64 flag (At least in the 8.2.0-Dev branch). So you can probably start there. There's pretty much no point in doing this though since the Mac build is already in Intel.

JonnycatMeow commented 1 month ago

i know but i wanna do it for other mods

ninjamuffin99 commented 1 month ago

I've been able to compile for arm64 now :) I have a branch on our internal repo that I've been getting fixed up and all that. I'll have to look into all that lipo stuff to make a universal binary, but hopefully next FNF update should be able to run natively on arm64 :)

AbnormalPoof commented 1 month ago

Sweet! Glad to see arm64 compilation went smoothly.