From e174ff15caa3caa749fda382c5b7a48ce2a7f2ca Mon Sep 17 00:00:00 2001 From: weisj <31143295+weisJ@users.noreply.github.com> Date: Mon, 5 Jul 2021 16:29:26 +0200 Subject: [PATCH] Actions+Native: Upload arm64 library on macOS. Upload the arm64 library on macos so it can be consumed by the build on other platforms. We also print the file information to check that the produced library really targets the correct arch. --- .github/workflows/libs.yml | 15 ++++++++--- .../darklaf/platform/macos/MacOSLibrary.java | 26 +++++++++++++++++-- .../platform/windows/WindowsLibrary.java | 2 +- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/.github/workflows/libs.yml b/.github/workflows/libs.yml index 13c520fb..c653b501 100644 --- a/.github/workflows/libs.yml +++ b/.github/workflows/libs.yml @@ -68,10 +68,17 @@ jobs: configuration-cache-enabled: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Upload artifact + - name: Upload x86-64 artifact uses: actions/upload-artifact@v1 with: name: macos-x86-64 - path: macos/build/libs/main/libdarklaf-macos.dylib - - name: Print library information - run: otool -l macos/build/libs/main/libdarklaf-macos.dylib + path: macos/build/libs/main/x86-64/libdarklaf-macos.dylib + - name: Upload arm64 artifact + uses: actions/upload-artifact@v1 + with: + name: macos-arm64 + path: macos/build/libs/main/arm64/libdarklaf-macos.dylib + - name: Print x86-64 library information + run: otool -l macos/build/libs/main/x86-64/libdarklaf-macos.dylib && file macos/build/libs/main/x86-64/libdarklaf-macos.dylib + - name: Print arm64 library information + run: otool -l macos/build/libs/main/arm64/libdarklaf-macos.dylib && file macos/build/libs/main/arm64/libdarklaf-macos.dylib diff --git a/macos/src/main/java/com/github/weisj/darklaf/platform/macos/MacOSLibrary.java b/macos/src/main/java/com/github/weisj/darklaf/platform/macos/MacOSLibrary.java index 2e5127bb..58181018 100644 --- a/macos/src/main/java/com/github/weisj/darklaf/platform/macos/MacOSLibrary.java +++ b/macos/src/main/java/com/github/weisj/darklaf/platform/macos/MacOSLibrary.java @@ -27,7 +27,9 @@ import com.github.weisj.darklaf.util.SystemInfo; public class MacOSLibrary extends AbstractLibrary { - private static final String PATH = "/com/github/weisj/darklaf/platform/darklaf-macos/macos-x86-64/"; + private static final String PATH = "/com/github/weisj/darklaf/platform/darklaf-macos/"; + private static final String x86_64_PATH = "macos-x86-64/"; + private static final String arm64_PATH = "macos-arm64/"; private static final String DLL_NAME = "libdarklaf-macos.dylib"; private static final MacOSLibrary instance = new MacOSLibrary(); @@ -39,8 +41,28 @@ public class MacOSLibrary extends AbstractLibrary { super(PATH, DLL_NAME, LogUtil.getLogger(MacOSLibrary.class)); } + private String getArm64Path() { + return super.getPath() + arm64_PATH; + } + + private String getX64Path() { + return super.getPath() + x86_64_PATH; + } + + + @Override + protected String getPath() { + if (SystemInfo.isX86Compatible && SystemInfo.isX64) { + return getX64Path(); + } else if (SystemInfo.isM1) { + return getArm64Path(); + } else { + throw new IllegalStateException("Unsupported arch"); + } + } + @Override protected boolean canLoad() { - return (SystemInfo.isX86Compatible && SystemInfo.isX64) && SystemInfo.isMacOSYosemite; + return ((SystemInfo.isX86Compatible && SystemInfo.isX64) || SystemInfo.isM1) && SystemInfo.isMacOSYosemite; } } diff --git a/windows/src/main/java/com/github/weisj/darklaf/platform/windows/WindowsLibrary.java b/windows/src/main/java/com/github/weisj/darklaf/platform/windows/WindowsLibrary.java index 12353fe4..25185c1a 100644 --- a/windows/src/main/java/com/github/weisj/darklaf/platform/windows/WindowsLibrary.java +++ b/windows/src/main/java/com/github/weisj/darklaf/platform/windows/WindowsLibrary.java @@ -56,7 +56,7 @@ public class WindowsLibrary extends AbstractLibrary { } else if (SystemInfo.isX64) { return getX64Path(); } else { - return super.getPath(); + throw new IllegalStateException("Unsupported arch"); } }