Skip to content
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

Support of macOS arm64 #11

Merged
merged 2 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ inThisBuild(
if (isSnapshot.value) Some("snapshots" at nexus + "content/repositories/snapshots")
else Some("releases" at nexus + "service/local/staging/deploy/maven2")
},
nativeArch := "x86_64",
nativeArch := {
System.getProperty("os.arch") match {
case "amd64" =>
"x86_64"
case arch =>
arch
}
},
nativeCompiler := "gcc",
nativeCompileOptions := "-shared" :: "-O2" :: "-Wall" :: "-Wextra" :: Nil,
nativePlatform := (System.getProperty("os.name").head.toLower match {
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/org/scalasbt/ipcsocket/NativeLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ class NativeLoader {
private static final boolean isMac;
private static final boolean isLinux;
private static final boolean isWindows;
private static final String arch;

static {
final String os = System.getProperty("os.name", "").toLowerCase();
isMac = os.startsWith("mac");
isLinux = os.startsWith("linux");
isWindows = os.startsWith("windows");
String maybeArch = System.getProperty("os.arch", "");
if ("amd64".equals(maybeArch)) {
maybeArch = "x86_64";
}
arch = maybeArch;
}

private static final String pid =
Expand All @@ -40,18 +46,14 @@ private static String tmpDirLocation() {

static void load() throws UnsatisfiedLinkError {
if (!loaded.get()) {
final String os = System.getProperty("os.name", "").toLowerCase();
final boolean isMac = os.startsWith("mac");
final boolean isLinux = os.startsWith("linux");
final boolean isWindows = os.startsWith("windows");
final boolean is64bit = System.getProperty("sun.arch.data.model", "64").equals("64");
String tmpDir = tmpDirLocation();
if (is64bit && (isMac || isLinux || isWindows)) {
final String extension = "." + (isMac ? "dylib" : isWindows ? "dll" : "so");
final String libName = (isWindows ? "" : "lib") + "sbtipcsocket" + extension;
final String prefix = isMac ? "darwin" : isLinux ? "linux" : "win32";

final String resource = prefix + "/x86_64/" + libName;
final String resource = prefix + "/" + arch + "/" + libName;
final URL url = NativeLoader.class.getClassLoader().getResource(resource);
if (url == null) throw new UnsatisfiedLinkError(resource + " not found on classpath");
try {
Expand Down
Binary file not shown.