openfl / lime

A foundational Haxe framework for cross-platform development
https://lime.openfl.org/
MIT License
753 stars 365 forks source link

Building lime.ndll on Apple Silicon Mac #1640

Closed tobil4sk closed 2 months ago

tobil4sk commented 1 year ago

Created this to keep track of the status of native Apple Silicon builds of the lime.ndll.

Todo:

After applying these patches, it is possible to build the ndll and build/run projects as expected.

player-03 commented 1 year ago

For any changes involving submodules, please start with the 8.2.0 branch and submit changes to that branch.

The branch includes a build guide that may help debug, but still feel free to ask if not.

tobil4sk commented 1 year ago

Created a new branch based on 8.2.0 as suggested. The linker error was due to a problem with the libpixman patch, which I have explained in more detail here: https://github.com/openfl/libpixman/pull/1.

I've created a new PR with the 8.2.0 based branch, which allows for a successful build of the lime.ndll on arm64 Mac with haxelib run lime rebuild mac -DHXCPP_ARM64: #1642. This also requires the most recent development version of hxcpp. I've pasted the installation instructions in case anyone is interested:

Expand for detailed installation instructions ```sh # install updated hxcpp with arm64 building support haxelib git hxcpp https://github.com/HaxeFoundation/hxcpp.git # clone forked version of lime from PR #1642 git clone https://github.com/soccertutor/lime.git --branch fix/m1-build-ndll --recursive # set lime library path haxelib dev lime ./lime # rebuild lime haxelib run lime rebuild mac -DHXCPP_ARM64 ```

Since the ndll is still loaded from the Mac64 path for now, we had to move the new arm64 binary:

cd $(haxelib libpath lime)
rm ndll/Mac64/lime.ndll
cp ndll/MacArm64/lime-64.ndll ndll/Mac64/lime.ndll

We also ran into this issue: #1750. ~~We managed to work around it by creating symlinks in /usr/local/bin and /usr/local/lib, see: https://brettterpstra.com/2022/09/28/homebrew-and-slash-usr-slash-local-slash-bin-on-m1-macs/~~.

UPDATE: It looks like /usr/local/lib may no longer be a default path for dyld anymore, see #1750.

Despite having to use these awkward workarounds, openfl test mac -DHXCPP_ARM64 now successfully runs our project. UPDATE: Seems to only build successfully with the -clean flag.

JonnycatMeow commented 1 year ago

how whould i build the macos arm64 dll on a x86_64 and i have xcode

ido-pluto commented 1 year ago

For some reason after installing the lime fork and doing all the steps, I got a segmentation fault

openfl test html5 -DHXCPP_ARM64
Could not link to neko.
Called from lime/_internal/backend/native/NativeCFFI.hx line 613
Called from lime/system/CFFI.hx line 171
Called from lime/system/CFFI.hx line 294
Uncaught exception - Segmentation fault 

If I put the MacArm64/lime-64.ndll into ndll/Mac/lime.ndll Is seems to work, but only for:

openfl test mac -DHXCPP_ARM64
tobil4sk commented 1 year ago

openfl test html5 -DHXCPP_ARM64

@ido-pluto The html5 target doesn't use hxcpp or lime.ndll so there is no need to build here with the -DHXCPP_ARM64 flag. However, it does seem odd that this causes a segmentation fault, there could be something wrong with the conditional compilation in my PR.

player-03 commented 1 year ago

Lime does use the ndll when building, which could explain the error.

If so, there's a second solution: the -eval flag skips lime.ndll when building. The flag was only recently merged into 8.2.0-Dev, so you'd need to pull that first.

bguiz commented 9 months ago

👋 Ran into this as well - any closer to this being resolved?

ido-pluto commented 9 months ago

Use the x86 version of haxe without brew (from the website). This works without any issue

bguiz commented 9 months ago

Ah will give this a go - thanks!

Use the x86 version of haxe without brew (from the website).

Related: Any chance we could get the x86 version on homebrew?

joshtynjala commented 9 months ago

Related: Any chance we could get the x86 version on homebrew?

I learned a while back that there are now two different versions of Homebrew. One for Intel and one for Apple Silicon, and you can actually install both on the same computer.

I needed the Intel version on my M1 Mac to locally build HashLink binaries a while back, and I mentioned what I did to install Intel Hombrew on the Haxe forums. Maybe it'll help you out.

https://community.haxe.org/t/compiling-hashlink-on-macos-apple-silicon/3150

tobil4sk commented 2 months ago

Now that the PRs have been merged, it is possible to build lime.ndll on apple silicon and build and run projects, with the following requirements:

Then run:

lime rebuild swf
lime rebuild mac

So I think it's time to close this issue!

tobil4sk commented 1 month ago

how whould i build the macos arm64 dll on a x86_64 and i have xcode

Also, in the develop branch you can now pass the -arm64 flag to do this:

lime rebuild mac -arm64

Same requirements as above (particularly for hxcpp).

Just-Feeshy commented 1 month ago

Love to see this completed