Skip to content

Support ARM64 on macOS and Linux #16

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

Merged
merged 11 commits into from
Oct 8, 2022
Merged

Support ARM64 on macOS and Linux #16

merged 11 commits into from
Oct 8, 2022

Conversation

Scrumplex
Copy link
Contributor

@Scrumplex Scrumplex commented Jun 26, 2022

CC @ViRb3 @r58Playz

This PR adds a new mechanism called LibraryPatch. It should be very flexible and can be used for a lot of things. Eventually we could patch Mojang's LWJGL 3.2.2 to include the missing tinyfd. I have rewritten the whole patching logic from scratch, I did take the library patches from #15 as a base though.

I have dropped the unrelated changes from #15 and #14 as they are not really important right now.

TODO

  • Test all changed Minecraft versions (1.12 onwards) on arm64 Linux
  • Test all changed Minecraft versions (1.12 onwards) on arm64 macOS
  • Test all LWJGL versions on arm64 Linux
  • Test all LWJGL versions on arm64 macOS
  • Update Multi-arch rules PolyMC#680 accordingly

Scrumplex and others added 7 commits June 26, 2022 12:14
In preparation for the library override system
Co-authored-by: r58Playz <toshit307@gmail.com>
Co-authored-by: Victor <virb3e@gmail.com>
When we have this cool patching mechanism, we could just use it to patch our existing LWJGL, instead of providing a static one
This was referenced Jul 1, 2022
@r58Playz
Copy link
Contributor

r58Playz commented Aug 6, 2022

You still need to apply this patch which fixes the DL links for mmachina natives and fixes the official LWJGL arm libs

diff --git a/generateMojang.py b/generateMojang.py
index e458ca1..eea83f2 100755
--- a/generateMojang.py
+++ b/generateMojang.py
@@ -191,6 +191,9 @@ def patch_library(lib: Library, patches: LibraryPatches) -> List[Library]:
             if patch.applies(target):
                 if patch.override:
                     target.merge(patch.override)
+                    
+                if patch.overwriteInLibrary:
+                    target.overwrite(patch.overwriteInLibrary)
 
                 if patch.additionalLibraries:
                     additional_copy = copy.deepcopy(patch.additionalLibraries)
diff --git a/meta/model/__init__.py b/meta/model/__init__.py
index caa0e6d..d143cd5 100644
--- a/meta/model/__init__.py
+++ b/meta/model/__init__.py
@@ -150,6 +150,28 @@ class MetaBase(pydantic.BaseModel):
                 ours.merge(theirs)
             else:
                 setattr(self, key, theirs)
+    
+    def overwrite(self, other):
+        """
+        Overwrite other object with self.
+        - Overwrites lists
+        - Overwrites sets
+        - Overwrites dictionaries
+        - Overwrites for all fields that are also MetaBase classes
+        - Overwrites for any other field type (int, string, ...)
+        """
+        print(self)
+        print(other)
+        assert type(other) is type(self)
+        for key, field in self.__fields__.items():
+            ours = getattr(self, key)
+            theirs = getattr(other, key)
+            if theirs is None:
+                continue
+            if ours is None:
+                setattr(self, key, theirs)
+                continue
+            setattr(self, key, theirs)
 
     def __hash__(self):
         return hash(self.json())
diff --git a/meta/model/mojang.py b/meta/model/mojang.py
index 6581417..fbfda7b 100644
--- a/meta/model/mojang.py
+++ b/meta/model/mojang.py
@@ -113,6 +113,7 @@ class LegacyOverrideIndex(MetaBase):
 class LibraryPatch(MetaBase):
     match: List[GradleSpecifier]
     override: Optional[Library]
+    overwriteInLibrary: Optional[Library]
     additionalLibraries: Optional[List[Library]]
     patchAdditionalLibraries: bool = Field(False)
 
diff --git a/static/mojang/library-patches.json b/static/mojang/library-patches.json
index 83a6660..7729ae2 100644
--- a/static/mojang/library-patches.json
+++ b/static/mojang/library-patches.json
@@ -408,7 +408,7 @@
             "natives-osx-arm64": {
               "sha1": "71d793d0a5a42e3dfe78eb882abc2523a2c6b496",
               "size": 129076,
-              "url": "https://github.com/MinecraftMachina/lwjgl3/releases/download/3.3.1-mmachina.1/lwjgl-glfw-natives-osx-arm64.jar"
+              "url": "https://github.com/MinecraftMachina/lwjgl3/releases/download/3.3.1-mmachina.1/lwjgl-glfw-natives-macos-arm64.jar"
             }
           }
         },
@@ -417,6 +417,9 @@
           "osx-arm64": "natives-osx-arm64"
         },
         "rules": [
+          {
+            "action": "disallow"
+          },
           {
             "action": "allow",
             "os": {
@@ -511,6 +514,9 @@
         },
         "name": "org.lwjgl:lwjgl-jemalloc:3.2.2",
         "rules": [
+          {
+            "action": "disallow"
+          },
           {
             "action": "allow",
             "os": {
@@ -530,7 +536,7 @@
             "natives-osx-arm64": {
               "sha1": "b0be721188d2e7195798780b1c5fe7eafe8091c1",
               "size": 103478,
-              "url": "https://github.com/MinecraftMachina/lwjgl3/releases/download/3.3.1-mmachina.1/lwjgl-jemalloc-natives-osx-arm64.jar"
+              "url": "https://github.com/MinecraftMachina/lwjgl3/releases/download/3.3.1-mmachina.1/lwjgl-jemalloc-natives-macos-arm64.jar"
             }
           }
         },
@@ -539,6 +545,9 @@
           "osx-arm64": "natives-osx-arm64"
         },
         "rules": [
+          {
+            "action": "disallow"
+          },
           {
             "action": "allow",
             "os": {
@@ -633,6 +642,9 @@
         },
         "name": "org.lwjgl:lwjgl-openal:3.2.2",
         "rules": [
+          {
+            "action": "disallow"
+          },
           {
             "action": "allow",
             "os": {
@@ -652,7 +664,7 @@
             "natives-osx-arm64": {
               "sha1": "6b80fc0b982a0723b141e88859c42d6f71bd723f",
               "size": 346131,
-              "url": "https://github.com/MinecraftMachina/lwjgl3/releases/download/3.3.1-mmachina.1/lwjgl-openal-natives-osx-arm64.jar"
+              "url": "https://github.com/MinecraftMachina/lwjgl3/releases/download/3.3.1-mmachina.1/lwjgl-openal-natives-macos-arm64.jar"
             }
           }
         },
@@ -661,6 +673,9 @@
           "osx-arm64": "natives-osx-arm64"
         },
         "rules": [
+          {
+            "action": "disallow"
+          },
           {
             "action": "allow",
             "os": {
@@ -774,7 +789,7 @@
             "natives-osx-arm64": {
               "sha1": "bb575058e0372f515587b5d2d04ff7db185f3ffe",
               "size": 41667,
-              "url": "https://github.com/MinecraftMachina/lwjgl3/releases/download/3.3.1-mmachina.1/lwjgl-opengl-natives-osx-arm64.jar"
+              "url": "https://github.com/MinecraftMachina/lwjgl3/releases/download/3.3.1-mmachina.1/lwjgl-opengl-natives-macos-arm64.jar"
             }
           }
         },
@@ -896,7 +911,7 @@
             "natives-osx-arm64": {
               "sha1": "98f0ad956c754723ef354d50057cc30417ef376a",
               "size": 178409,
-              "url": "https://github.com/MinecraftMachina/lwjgl3/releases/download/3.3.1-mmachina.1/lwjgl-stb-natives-osx-arm64.jar"
+              "url": "https://github.com/MinecraftMachina/lwjgl3/releases/download/3.3.1-mmachina.1/lwjgl-stb-natives-macos-arm64.jar"
             }
           }
         },
@@ -1018,7 +1033,7 @@
             "natives-osx-arm64": {
               "sha1": "015b931a2daba8f0c317d84c9d14e8e98ae56e0c",
               "size": 41384,
-              "url": "https://github.com/MinecraftMachina/lwjgl3/releases/download/3.3.1-mmachina.1/lwjgl-tinyfd-natives-osx-arm64.jar"
+              "url": "https://github.com/MinecraftMachina/lwjgl3/releases/download/3.3.1-mmachina.1/lwjgl-tinyfd-natives-macos-arm64.jar"
             }
           }
         },
@@ -1140,7 +1155,7 @@
             "natives-osx-arm64": {
               "sha1": "984df31fadaab86838877b112e5b4e4f68a00ccf",
               "size": 42693,
-              "url": "https://github.com/MinecraftMachina/lwjgl3/releases/download/3.3.1-mmachina.1/lwjgl-natives-osx-arm64.jar"
+              "url": "https://github.com/MinecraftMachina/lwjgl3/releases/download/3.3.1-mmachina.1/lwjgl-natives-macos-arm64.jar"
             }
           }
         },
@@ -1159,6 +1174,31 @@
       }
     ]
   },
+  {
+    "_comment": "Fix macos-arm64 natives for LWJGL 3.3.1 being tagged for macos",
+    "match": [
+      "org.lwjgl:lwjgl-glfw-natives-macos-arm64:3.3.1",
+      "org.lwjgl:lwjgl-jemalloc-natives-macos-arm64:3.3.1",
+      "org.lwjgl:lwjgl-openal-natives-macos-arm64:3.3.1",
+      "org.lwjgl:lwjgl-opengl-natives-macos-arm64:3.3.1",
+      "org.lwjgl:lwjgl-stb-natives-macos-arm64:3.3.1",
+      "org.lwjgl:lwjgl-tinyfd-natives-macos-arm64:3.3.1",
+      "org.lwjgl:lwjgl-natives-macos-arm64:3.3.1"
+    ],
+    "overwriteInLibrary": {
+      "rules": [
+        {
+          "action": "disallow"
+        },
+        {
+          "action": "allow",
+          "os": {
+            "name": "osx-arm64"
+          }
+        }
+      ]
+    }
+  },
   {
     "_comment": "Add linux-arm64 support for LWJGL 3.3.1",
     "match": [

@Scrumplex
Copy link
Contributor Author

Scrumplex commented Aug 6, 2022

Why do you add the disallow actions? The launcher already implies disallow as the first entry while evaluating rules.

See: https://github.com/PolyMC/PolyMC/blob/75f92de8f8517142289dc76d071cfb4fa724598c/launcher/minecraft/Library.cpp#L203-L226

@r58Playz
Copy link
Contributor

r58Playz commented Aug 6, 2022

Why do you add the disallow actions? The launcher already implies disallow as the first entry while evaluating rules.

See: https://github.com/PolyMC/PolyMC/blob/75f92de8f8517142289dc76d071cfb4fa724598c/launcher/minecraft/Library.cpp#L203-L226

must have added those in during the 10 or so test runs that didn't work
Screen Shot 2022-08-06 at 2 34 40 PM

@Scrumplex Scrumplex mentioned this pull request Aug 8, 2022
3 tasks
@Scrumplex Scrumplex merged commit 4903123 into PolyMC:master Oct 8, 2022
@Scrumplex Scrumplex deleted the arm64-new branch October 8, 2022 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants