shannah / Java-Objective-C-Bridge

A thin bridge that allows for two-way communication from Java to Objective-C.
123 stars 25 forks source link

Mac M1 Support #41

Closed andriy-gerasika closed 2 years ago

andriy-gerasika commented 3 years ago

Hi, is it possible to upgrade the library to include Mac M1 support:

shannah commented 3 years ago

I just gave a feeble effort to build it on my arm mac in the hope that it would just work. But no such luck. I'm getting some build errors related to JavaNativeFoundation not being available. I fished around a bit but don't have time right now.

I'll give it another try later (no ETA) when I have more time to work on it.

andriy-gerasika commented 3 years ago

create a sample PR solving the problem w/ JavaNativeFoundation

I have one more question: why it is said on the front page the project requires Java 11 or higher on MacOS? I am using current version w/ Java 8 on MacOS and plan to use the upcoming version on Mac M1 using Azul/Zulu Java 8 -- is it possible not to make Java 11 a requirement in the future version and compile the JAR w/ Java 8 compatibility option on?

Thanks

shannah commented 3 years ago

Up until recently it supported Java 8. Some PRs came in that moved it to Java11. I didn't see any reason why not to bump to Java11. Probably wouldn't be hard to backport. I think it just uses a few convenience features of Java11. Nothing fundamental. If you want to try building for Java 8, I'm sure you could flush out the build errors relatively quickly.

shannah commented 3 years ago

Thank for the PR. Build works. Tests fail on ARM (meaning build didn't really work). https://gist.github.com/shannah/836d8e8944559cb733c12334387ff404

Don't have time to dig into details of it right now. If you have time to dig into this, I can give you SSH access to the Arm box so you can play with it.

andriy-gerasika commented 3 years ago

sorry, I did not ran test on my Mac M1 -- there is indeed a problem w/ Mac M1 (not Intel though). I receive the following Java crash logs on "mvn clean install": http://www.gerixsoft.com/tmp/hs_err_pid8603.log http://www.gerixsoft.com/tmp/hs_err_pid8450.log -- looks like there is a bug in JNA v5.7 on ARM or there is some problem with binding to Objective C runtime lib

andriy-gerasika commented 3 years ago

Hi, I was able to find a problem -- for some reason methodSignatureForSelector on Mac M1 returns null: http://www.gerixsoft.com/tmp/methodSignatureForSelector.png but I am not sure why...

shannah commented 3 years ago

At the break point in the screenshot, what is context of that methodSignatureForSelector: call? I.e. What is the receiver/object and what is the selector?

andriy-gerasika commented 3 years ago

receiver is "NSObject", selector is "alloc" http://www.gerixsoft.com/tmp/methodSignatureForSelector2.png

shannah commented 3 years ago

Thanks for that. Odd. I'm not sure why this should be the case. NSObject certainly supports the "alloc" selector. I'll need to dig into it. Perhaps there is a change to how Objective-C classes work (since in this case, the receiver is a Class, and not an NSObject instance).

ghost commented 3 years ago

Has anyone had the chance to check into this a little more?

Perhaps this would be helpful?

https://developer.apple.com/documentation/apple-silicon/addressing-architectural-differences-in-your-macos-code#Enable-Strict-Type-Enforcement-for-Dynamic-Method-Dispatching

I am not sure if it is relevant or not as this is beyond my scope of knowledge but I am willing to test any changes or help in any other way possible if necessary.

shannah commented 3 years ago

I just picked up an M1 mac over the weekend but haven't had a chance to set it up yet. Well look into this further once it is set up.

dkocher commented 2 years ago

You might be interested in this PR tackling the same issues for Rococoa.

rednoah commented 2 years ago

@shannah I'd be happy to hire you as a freelancer to work on M1 support for objc bridge.

shannah commented 2 years ago

Thanks @rednoah. Much appreciated. Send me an email at steve@weblite.ca and let's talk.

ViRb3 commented 2 years ago

@rednoah @shannah Thank you so much for the sponsorship and effort respectively, thanks to you Minecraft is one step closer to fully functioning on M1 - https://github.com/MinecraftMachina/ManyMC.