Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
AbnormalPoof opened this issue Jul 9, 2024 · 10 comments
Closed

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

AbnormalPoof opened this issue Jul 9, 2024 · 10 comments
Assignees
Labels
status: accepted Approved for contribution. If it's not already merged, it may be merged on a private branch. type: enhancement Provides an enhancement or new feature.

Comments

@AbnormalPoof
Copy link
Contributor

AbnormalPoof commented Jul 9, 2024

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.

  • ARM (959.05 Seconds):
    Screenshot 2024-07-10 at 4 26 21 PM

  • Intel (3817.11 Seconds):
    Screenshot 2024-07-10 at 4 02 06 PM

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"

  • ARM
ChartEditorSpam_APPLESILICON.mp4
  • Intel
ChartEditorSpam_INTEL.mp4
@AbnormalPoof AbnormalPoof changed the title Enhancement: Apple Silicon builds for macOS? Enhancement: Native Apple Silicon builds for macOS? Jul 10, 2024
@AbnormalPoof AbnormalPoof changed the title Enhancement: Native Apple Silicon builds for macOS? Question: Native Apple Silicon builds for macOS? Jul 10, 2024
@AbnormalPoof AbnormalPoof changed the title Question: Native Apple Silicon builds for macOS? Question/Enhancement: Native Apple Silicon builds for macOS? Jul 10, 2024
@ninjamuffin99
Copy link
Member

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
Copy link
Contributor Author

AbnormalPoof commented Jul 12, 2024

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.

Sept. 26 update: You no longer need to do the madness above, the FunkinCrew lime fork was updated for ARM64 support and already includes NDLLs for ARM64 and Intel, and Haxe 4.3.5+ is now Universal on macOS.
The script has been updated to reflect these changes.

#!/bin/bash

# This is a script that will build Friday Night Funkin' twice. One for Apple Silicon (ARM), and one for Intel (x86_64).
# The resulting builds are combined using `lipo` to output a Universal (ARM+Intel) build.

# 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: Move the ARM NDLL to the Intel folder (Mac64).
# We use the ARM lime library for compiling on Intel due to linking issues with ApplicationMain
if [ ! -f .haxelib/lime/git/ndll/Mac64/lime-intel.ndll ]; then
  mv ".haxelib/lime/git/ndll/Mac64/lime.ndll" ".haxelib/lime/git/ndll/Mac64/lime-intel.ndll"
fi
cp ".haxelib/lime/git/ndll/MacArm64/lime.ndll" ".haxelib/lime/git/ndll/Mac64/lime.ndll"

# 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 ""

# Make a copy of the ARM build, this will be the resulting Universal build.
cp -R export/release/macos/bin/Funkin-ARM.app export/release/macos/bin/Funkin.app

# Remove the ARM binaries inside the ARM copy.
rm export/release/macos/bin/Funkin.app/Contents/MacOS/Funkin
rm export/release/macos/bin/Funkin.app/Contents/MacOS/lime.ndll

# Move the ARM libraries inside Funkin-ARM to the Universal build.
# This will have the "-ARM" suffix.
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

# Move the Intel libraries inside Funkin-Intel to the Universal build.
# This will have the "-Intel" suffix.
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

# Use `lipo` to create Universal binaries.
# This is done by combining ARM and Intel versions of `lime.ndll` and `Funkin` respectively.
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

# Remove the leftover files.
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

# Remove the separate ARM and Intel builds.
rm -r export/release/macos/bin/Funkin-ARM.app
rm -r export/release/macos/bin/Funkin-Intel.app

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

# Post-build: Rename the Intel NDLL.
mv ".haxelib/lime/git/ndll/Mac64/lime-intel.ndll" ".haxelib/lime/git/ndll/Mac64/lime.ndll"

@JonnycatMeow
Copy link

hell yah

@JonnycatMeow
Copy link

JonnycatMeow commented Jul 20, 2024

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

@AbnormalPoof
Copy link
Contributor Author

AbnormalPoof commented Jul 20, 2024

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
Copy link

i know but i wanna do it for other mods

@ninjamuffin99
Copy link
Member

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
Copy link
Contributor Author

Sweet! Glad to see arm64 compilation went smoothly.

@EliteMasterEric EliteMasterEric added the status: accepted Approved for contribution. If it's not already merged, it may be merged on a private branch. label Jul 22, 2024
@EliteMasterEric EliteMasterEric added type: compilation help Involves some issue with compiling the game from source. type: enhancement Provides an enhancement or new feature. and removed type: compilation help Involves some issue with compiling the game from source. labels Jul 22, 2024
@AbnormalPoof
Copy link
Contributor Author

AbnormalPoof commented Sep 26, 2024

Just did a test build and ARM64 seems to compile smoothly now as of v0.5.0!
Screenshot 2024-09-26 at 10 57 58 AM
I'm not sure if I should close this issue now or wait until an official Apple Silicon/Universal build is out, though...

Side note: I updated the build script above to reflect recent changes to Haxe and FunkinCrew's lime fork!

@ninjamuffin99
Copy link
Member

yeah i actually develop and test FNF on my apple silicon laptop probably more than I do at my windows machine by now haha!

i actually completely forgot to update the apple silicon for the update though... lol.. i was getting trolled with lipo lol... I think i will close this issue however since its like 99% done and just needs to compile / publish a universal version and figure out that workflow!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepted Approved for contribution. If it's not already merged, it may be merged on a private branch. type: enhancement Provides an enhancement or new feature.
Projects
None yet
Development

No branches or pull requests

4 participants