Skip to content

Commit 11c5a84

Browse files
author
ntwigg
committed
Add support for Apple silicon to the platform enums.
1 parent d46be2b commit 11c5a84

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

durian-swt.os/src/main/java/com/diffplug/common/swt/os/Arch.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
/** Enum for handling different processor architectures supported by SWT. */
1919
public enum Arch {
20-
x86, x64;
20+
x86, x64, arm64;
2121

2222
/** Returns the appropriate value depending on the arch. */
2323
public <T> T x86x64(T val86, T val64) {
@@ -31,6 +31,32 @@ public <T> T x86x64(T val86, T val64) {
3131
}
3232
}
3333

34+
/** Returns the appropriate value depending on the arch. */
35+
public <T> T x64arm64(T val64, T arm64) {
36+
switch (this) {
37+
case x64:
38+
return val64;
39+
case arm64:
40+
return arm64;
41+
default:
42+
throw unsupportedException(this);
43+
}
44+
}
45+
46+
/** Returns the appropriate value depending on the arch. */
47+
public <T> T x86x64arm64(T val86, T val64, T arm64) {
48+
switch (this) {
49+
case x86:
50+
return val86;
51+
case x64:
52+
return val64;
53+
case arm64:
54+
return arm64;
55+
default:
56+
throw unsupportedException(this);
57+
}
58+
}
59+
3460
/** Returns the Arch for the native platform: 32-bit JVM on 64-bit Windows returns Arch.x64. */
3561
public static Arch getNative() {
3662
return OS.getNative().getArch();

durian-swt.os/src/main/java/com/diffplug/common/swt/os/OS.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
/** Enum representing an OS and its underlying CPU architecture. */
2323
public enum OS {
24-
WIN_x64, WIN_x86, LINUX_x64, LINUX_x86, MAC_x64;
24+
WIN_x64, WIN_x86, LINUX_x64, LINUX_x86, MAC_x64, MAC_silicon;
2525

2626
public boolean isWindows() {
2727
return this == WIN_x64 || this == WIN_x86;
@@ -32,7 +32,7 @@ public boolean isLinux() {
3232
}
3333

3434
public boolean isMac() {
35-
return this == MAC_x64;
35+
return this == MAC_x64 || this == MAC_silicon;
3636
}
3737

3838
public boolean isMacOrLinux() {
@@ -62,6 +62,8 @@ public Arch getArch() {
6262
case WIN_x86:
6363
case LINUX_x86:
6464
return Arch.x86;
65+
case MAC_silicon:
66+
return Arch.arm64;
6567
default:
6668
throw unsupportedException(this);
6769
}
@@ -74,7 +76,7 @@ public String os() {
7476

7577
/** SWT-style x86/x86_64 */
7678
public String arch() {
77-
return getArch().x86x64("x86", "x86_64");
79+
return getArch().x86x64arm64("x86", "x86_64", "aarch64");
7880
}
7981

8082
/** os().arch() */
@@ -84,7 +86,7 @@ public String osDotArch() {
8486

8587
/** windowing.os.arch */
8688
public String toSwt() {
87-
return winMacLinux("win32", "cocoa", "gtk") + "." + winMacLinux("win32", "macosx", "linux") + "." + getArch().x86x64("x86", "x86_64");
89+
return winMacLinux("win32", "cocoa", "gtk") + "." + winMacLinux("win32", "macosx", "linux") + "." + getArch().x86x64arm64("x86", "x86_64", "aarch64");
8890
}
8991

9092
/** Returns the native OS: 32-bit JVM on 64-bit Windows returns OS.WIN_64. */
@@ -135,7 +137,7 @@ private static OS calculateRunning() {
135137
Arch runningArch = runningJvm();
136138
return NATIVE_OS.winMacLinux(
137139
runningArch.x86x64(OS.WIN_x86, OS.WIN_x64),
138-
OS.MAC_x64,
140+
runningArch.x64arm64(OS.MAC_x64, OS.MAC_silicon),
139141
runningArch.x86x64(OS.LINUX_x86, OS.LINUX_x64));
140142
}
141143

durian-swt.os/src/main/java/com/diffplug/common/swt/os/SwtPlatform.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public static SwtPlatform getRunning() {
129129
public static SwtPlatform fromOS(OS raw) {
130130
String ws = raw.winMacLinux("win32", "cocoa", "gtk");
131131
String os = raw.winMacLinux("win32", "macosx", "linux");
132-
String arch = raw.getArch().x86x64("x86", "x86_64");
132+
String arch = raw.getArch().x86x64arm64("x86", "x86_64", "aarch64");
133133
return new SwtPlatform(ws, os, arch);
134134
}
135135

0 commit comments

Comments
 (0)