MinecraftMachina / ManyMC

📦 A familiar Minecraft Launcher with native support for macOS arm64 (M1)
GNU General Public License v3.0
500 stars 19 forks source link

JNA not built for aarch64 #85

Open jcrm1 opened 2 years ago

jcrm1 commented 2 years ago

!! Please fill in this template, DO NOT ignore or delete it. !!

I tried basic troubleshooting first

Describe the bug

ManyMC is not patching a version (3.4.0) of JNA that does not support arm64 by default, so Minecraft 1.8.9 is crashing when loading a mod (LabyMod 3) that requires it.

To reproduce

Steps to reproduce the behavior:

  1. Download LabyMod 3 from labymod.net 2.
  2. Run jar with java -jar LabyMod*.jar
  3. 1.8.9, Forge, Other (Extract)
  4. Add mod to 1.8.9 with Forge instance
  5. Launch, crash and see the below error

Expected behavior

Game should launch normally

Logs

Caused by: java.lang.UnsatisfiedLinkError: /private/var/folders/h9/3qh3y4ts7wz2f1qllz1yv7w80000gn/T/jna/jna2002535842885038387.tmp: dlopen(/private/var/folders/h9/3qh3y4ts7wz2f1qllz1yv7w80000gn/T/jna/jna2002535842885038387.tmp, 0x0001): tried: '/private/var/folders/h9/3qh3y4ts7wz2f1qllz1yv7w80000gn/T/jna/jna2002535842885038387.tmp' (fat file, but missing compatible architecture (have 'i386,x86_64,unknown', need 'arm64e'))

Screenshots

N/A

System configuration

Additional context

~/Library/Application Support/ManyMC/libraries/net/java/dev/jna/jna/3.4.0/jna-3.4.0.jar contains a file in com/sun/jna/darwin/*.jnilib that is identical to the file (jna2002535842885038387.tmp) referenced in the error above. file jna2002535842885038387.tmp returns Mach-O universal binary with 3 architectures: [i386:Mach-O dynamically linked shared library i386Mach-O dynamically linked shared library i386] [x86_64:Mach-O 64-bit dynamically linked shared library x86_64Mach-O 64-bit dynamically linked shared library x86_64] [ppc_7400:Mach-O dynamically linked shared library ppc_7400Mach-O dynamically linked shared library ppc_7400] jna6932855343444723145.tmp (for architecture i386): Mach-O dynamically linked shared library i386 jna6932855343444723145.tmp (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64 jna6932855343444723145.tmp (for architecture ppc7400): Mach-O dynamically linked shared library ppc_7400
This shows that the library lacks support for arm64/aarch64 in its current state.

jna6932855343444723145.tmp.zip

The solution could be to rebuild JNA 3.4.0 for aarch64- however, I am not experienced with ant, and I was unable to get this working. I can, however, provide the commit in which aarch64 support was added to JNA.

ViRb3 commented 2 years ago

@r58Playz did we have a solution for this?

r58Playz commented 2 years ago

https://github.com/r58Playz/jna-4.4.0-m1 has jna 4.4.0, i guess you could use the patches from there

jcrm1 commented 2 years ago

Applied the changes from that repo to https://github.com/jcrm1/jna-3.4.0-m1, but still getting the same error I got when trying to build it without modifications.

     native:
     [exec] Configuring libffi (aarch64)
     [exec] checking build system type... arm-apple-darwin21.6.0configure: WARNING: if you wanted to set the --build type, don't use --host.
     [exec]
     [exec]     If a cross compiler is detected then cross compile mode will be used
     [exec] Invalid configuration `aarch64-apple-darwin': machine `aarch64-apple' not recognized
     [exec] configure: error: /bin/sh ~/Downloads/jna-3.4.0-m1/native/libffi/config.sub aarch64-apple-darwin failed
     [exec] make: *** [~/Downloads/jna-3.4.0-m1/build-d64/native/libffi/.libs/libffi.a] Error 1
     [exec] checking host system type...
r58Playz commented 2 years ago

Applied the changes from that repo to https://github.com/jcrm1/jna-3.4.0-m1, but still getting the same error I got when trying to build it without modifications. native: [exec] Configuring libffi (aarch64) [exec] checking build system type... arm-apple-darwin21.6.0configure: WARNING: if you wanted to set the --build type, don't use --host. [exec] [exec] If a cross compiler is detected then cross compile mode will be used [exec] Invalid configuration `aarch64-apple-darwin': machine `aarch64-apple' not recognized [exec] configure: error: /bin/sh ~/Downloads/jna-3.4.0-m1/native/libffi/config.sub aarch64-apple-darwin failed [exec] make: *** [~/Downloads/jna-3.4.0-m1/build-d64/native/libffi/.libs/libffi.a] Error 1 [exec] checking host system type...

echo 'echo arm-apple-darwin' > native/libffi/config.sub

(replace the contents of config.sub in libffi source with echo arm-apple-darwin)

PS: use three ticks (```) for better code blocks

jcrm1 commented 2 years ago

Well, I had a long comment written up detailing what I've tried, but then I got a kernel panic. Instead, I'll just leave the key error message here (from config.log):

configure:4633: checking whether the C compiler works
configure:4655: gcc -arch aarch64  -O2 -fno-omit-frame-pointer -fno-strict-alia>
clang: error: invalid arch name '-arch aarch64'
configure:4659: $? = 1
configure:4699: result: no

My guess is that somewhere in the configure process, the target architecture is getting set to aarch64 instead of arm64, which neither apple-clang nor GNU gcc recognize as a valid architecture. PS: Thanks for the formatting info!

r58Playz commented 2 years ago

Well, I had a long comment written up detailing what I've tried, but then I got a kernel panic. Instead, I'll just leave the key error message here (from config.log):

configure:4633: checking whether the C compiler works
configure:4655: gcc -arch aarch64  -O2 -fno-omit-frame-pointer -fno-strict-alia>
clang: error: invalid arch name '-arch aarch64'
configure:4659: $? = 1
configure:4699: result: no

My guess is that somewhere in the configure process, the target architecture is getting set to aarch64 instead of arm64, which neither apple-clang nor GNU gcc recognize as a valid architecture. PS: Thanks for the formatting info!

Here you have to change the libffi makefile a bit since thats probably where it's setting the arch. probably try getting some patches from either your commit or my 4.4.0 repo

jcrm1 commented 2 years ago

I tried a lot of stuff, but I couldn't get it to build. Regardless, it turns out that the game works fine if you swap 3.4.0 for 5.10.0. I did this by changing

{
            "downloads": {
                "artifact": {
                    "sha1": "803ff252fedbd395baffd43b37341dc4a150a554",
                    "size": 1008730,
                    "url": "https://libraries.minecraft.net/net/java/dev/jna/jna/3.4.0/jna-3.4.0.jar"
                }
            },
            "name": "net.java.dev.jna:jna:3.4.0"
        }

to as follows:

{
            "downloads": {
                "artifact": {
                    "sha1": "7cf4c87dd802db50721db66947aa237d7ad09418",
                    "size": 1756400,
                    "url": "https://libraries.minecraft.net/net/java/dev/jna/jna/5.10.0/jna-5.10.0.jar"
                }
            },
            "name": "net.java.dev.jna:jna:3.4.0"
        }

in net.minecraft.json for 1.8.9. You can find this file through Edit Instance -> Version -> Customize -> Edit. The feature involving JNA (Discord Rich Presence) in the mod I'm using is not working in-game, but the game stops pushing errors if you turn off the Discord integration, and that's good enough for me.

Closing the issue because my original issue is solved, and I believe that hosting modified libraries (not natives) could be out-of-scope for ManyMC since I can't find any that are currently hosted.

ViRb3 commented 2 years ago

Glad you found a solution! Apologies I haven't been able to help, been very busy lately.

This is definitely in scope for ManyMC as we maintain and host various modified libraries specifically to work on M1. Eventually I will look into this, when I get some free time.

jcrm1 commented 2 years ago

Good to know, and good luck!